You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
4.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#region Apache License Version 2.0
/*----------------------------------------------------------------
Copyright 2023 Jeffrey Su & Suzhou Senparc Network Technology Co.,Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the specific language governing permissions
and limitations under the License.
Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md
----------------------------------------------------------------*/
#endregion Apache License Version 2.0
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Senparc.Weixin;
using Senparc.Weixin.Entities;
using Senparc.Weixin.Exceptions;
using Senparc.Weixin.HttpUtility;
namespace Senparc.Weixin.HttpUtility.Tests
{
[TestClass]
public class PostTests
{
[TestMethod]
public void PostGetJsonTest()
{
return;//已经通过,但需要连接远程测试,太耗时,常规测试时暂时忽略。 //TODO迁移到 CO2NET 中测试
var url = Config.ApiMpHost + "/cgi-bin/media/upload?access_token=TOKEN&type=image";
try
{
//这里因为参数错误,系统会返回错误信息
WxJsonResult resultFail = CO2NET.HttpUtility.Post.PostGetJson<WxJsonResult>(CommonDI.CommonSP, url, cookieContainer: null, formData: null, encoding: null);
Assert.Fail();//上一步就应该已经抛出异常
}
catch (ErrorJsonResultException ex)
{
//实际返回的信息(错误信息)
Assert.AreEqual(ex.JsonResult.errcode, ReturnCode.access_tokenAppSecretaccess_token);
}
}
[TestMethod()]
public async Task PostGetJsonAsyncTest()
{
//return;//已经通过,但需要连接远程测试,太耗时,常规测试时暂时忽略。
var url = Config.ApiMpHost + "/cgi-bin/media/upload?access_token=TOKEN&type=image";
try
{
WxJsonResult resultFail =
await CO2NET.HttpUtility.Post.PostGetJsonAsync<WxJsonResult>(CommonDI.CommonSP, url, cookieContainer: null, formData: null,
encoding: null);
//这里因为参数错误,系统会返回错误信息
Assert.Fail(); //上一步就应该已经抛出异常
}
catch (ErrorJsonResultException ex)
{
//实际返回的信息(错误信息)
Assert.AreEqual(ex.JsonResult.errcode, ReturnCode.access_tokenAppSecretaccess_token);
Console.WriteLine("Success");
}
}
[TestMethod]
public void PostGetJsonByFormDataTest()
{
return;//已经通过,但需要连接远程测试,太耗时,常规测试时暂时忽略。
var url = "http://localhost:12222/P2P/GetPassport";
try
{
//这里因为参数错误,系统会返回错误信息
var formData = new Dictionary<string, string>();
formData["appKey"] = "test";
formData["secret"] = "test2";
var resultFail = CO2NET.HttpUtility.Post.PostGetJson<object>(CommonDI.CommonSP, url, formData: formData);
}
catch (ErrorJsonResultException ex)
{
Assert.Fail();
}
}
[TestMethod]
public void DownLoadTest()
{
}
}
}