Skip to content

Commit

Permalink
更新单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreySu committed Oct 2, 2024
1 parent 05e5fa7 commit 4855e62
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@ and limitations under the License.
----------------------------------------------------------------*/
#endregion Apache License Version 2.0

using System;
using System.Text;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Senparc.Weixin.Exceptions;
using Senparc.Weixin.Work.AdvancedAPIs;
using Senparc.Weixin.Work.AdvancedAPIs.App;
using Senparc.Weixin.Work.AdvancedAPIs.MailList;
using Senparc.Weixin.Work.CommonAPIs;
using Senparc.Weixin.Work.Containers;
using Senparc.Weixin.Work.Test.CommonApis;
using System;
using System.Threading.Tasks;

namespace Senparc.Weixin.Work.Test.AdvancedAPIs
{
Expand All @@ -39,77 +34,59 @@ namespace Senparc.Weixin.Work.Test.AdvancedAPIs
[TestClass]
public partial class AppTest : CommonApiTest
{
const int AGENT_ID = 1000009;

[TestMethod]
public void GetAppInfoTest()
{
{
//使用AppKey测试
//常规AccessToken测试
var appKey = AccessTokenContainer.BuildingKey(_corpId, base._corpSecret);
var result = AppApi.GetAppInfo(appKey, 2);
var result = AppApi.GetAppInfo(appKey, AGENT_ID);

Assert.IsNotNull(result.agentid);
Assert.AreEqual(result.agentid, "2");
Assert.AreEqual(result.agentid, AGENT_ID.ToString());
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(result));
}

{
//常规AccessToken测试
var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret);
var result = AppApi.GetAppInfo(accessToken, 2);
var result = AppApi.GetAppInfo(accessToken, AGENT_ID);

Assert.IsNotNull(result.agentid);
Assert.AreEqual(result.agentid, "2");
Assert.AreEqual(result.agentid, AGENT_ID.ToString());
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(result));
}
}

[TestMethod]
public void GetAppInfoAsyncTest()
public async Task GetAppInfoAsyncTest()
{
var finishedCount = 0;

{
Task.Factory.StartNew(async () =>
{
//使用AppKey测试
//常规AccessToken测试
var appKey = AccessTokenContainer.BuildingKey(_corpId, base._corpSecret);
var result = await AppApi.GetAppInfoAsync(appKey, 2);

Assert.IsNotNull(result.agentid);
Assert.AreEqual(result.agentid, "2");

Console.WriteLine("1.Ticket:" + SystemTime.Now.Ticks);
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(result));
finishedCount++;
});
//使用AppKey测试
//常规AccessToken测试
var appKey = AccessTokenContainer.BuildingKey(_corpId, base._corpSecret);
var result = await AppApi.GetAppInfoAsync(appKey, AGENT_ID);

while (finishedCount < 1)
{
Assert.IsNotNull(result.agentid);
Assert.AreEqual(result.agentid, AGENT_ID.ToString());

}
Console.WriteLine("1.Ticket:" + SystemTime.Now.Ticks);
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(result));
}

{
Task.Factory.StartNew(async () =>
{
//常规AccessToken测试
var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret);
var result = await AppApi.GetAppInfoAsync(accessToken, 2);

Assert.IsNotNull(result.agentid);
Assert.AreEqual(result.agentid, "2");

Console.WriteLine("2.Ticket:" + SystemTime.Now.Ticks);
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(result));
finishedCount++;
});
//常规AccessToken测试
var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret);
var result = await AppApi.GetAppInfoAsync(accessToken, AGENT_ID);

while (finishedCount < 2)
{
Assert.IsNotNull(result.agentid);
Assert.AreEqual(result.agentid, AGENT_ID.ToString());

}
Console.WriteLine("2.Ticket:" + SystemTime.Now.Ticks);
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(result));
}
}

Expand All @@ -120,15 +97,15 @@ public void SetAppTest()

SetAppPostData date = new SetAppPostData()
{
agentid = "2",//"100" + SystemTime.Now.ToString("yyMMddHHMM"),
agentid = AGENT_ID.ToString(),//"100" + SystemTime.Now.ToString("yyMMddHHMM"),
report_location_flag = "1",
//logo_mediaid = "1muvdK7W8cjLfNqj0hWP89-CEhZNOVsktCE1JHSTSNpzTf7cGOXyDin_ozluwNZqi",
name = "单元测试添加" + SystemTime.Now.ToString("yyMMddHHMM"),
description = "test",
redirect_domain = "https://sdk.weixin.senparc.com",
name = "微信 SDK 单元测试添加" + SystemTime.Now.ToString("yyyyMMdd HH:mm"),
description = "微信 SDK 单元测试",
redirect_domain = "sdk.weixin.senparc.com",
//isreportenter = 0,
isreportuser = 1,
home_url = "weixin.senparc.com"
home_url = "https://weixin.senparc.com",
};

var result = AppApi.SetApp(accessToken, date);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Threading.Tasks;
using Senparc.Weixin.Work.Test.CommonApis;
using Senparc.Weixin.Work.Containers;

namespace Senparc.Weixin.Work.AdvancedAPIs.Tests
{
Expand All @@ -15,8 +16,8 @@ public class MailListApiTests : CommonApiTest
[TestMethod()]
public void GetDepartmentMemberInfoTest()
{
var appKeyOrAccessToken = "";
var result = MailListApi.GetDepartmentMemberInfo(appKeyOrAccessToken, 1, 1/*, Int32.MaxValue*/);
var appKey = AccessTokenContainer.BuildingKey(_corpId, _corpSecret);
var result = MailListApi.GetDepartmentMemberInfo(appKey, 1, 1/*, Int32.MaxValue*/);
Assert.IsNotNull(result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ and limitations under the License.
using Senparc.WeixinTests;
using Microsoft.AspNetCore.Hosting;
using Senparc.CO2NET.Cache.CsRedis;
using Senparc.CO2NET.Extensions;


namespace Senparc.Weixin.Work.Test.CommonApis
Expand Down Expand Up @@ -143,6 +144,7 @@ public void GetCallBackIpTest()
var result = CommonApi.GetCallBackIp(accessToken);
Assert.IsNotNull(result);
Assert.IsTrue(result.errcode == ReturnCode_Work.请求成功);
Console.WriteLine(result.ToJson(true));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ public partial class WorkMessageHandlersTest : CommonApiTest
private string testXml2 = @"<xml><ToUserName><![CDATA[tj99bf85a7c6525277]]></ToUserName><Encrypt><![CDATA[mOYGyroKLkpIDLNn6DAPjdZbRsQlkUggk+LnYY2S/7O/nRxxu3hDsJLiod29NVMYpwVNHMqTnZALXmycI6c7+wWxway/T/91okclPXn+EB/u4vss5FKntesFMxtGPRxt1aChMN9yNJNRhom05UD4c3B3lSicS10LE3MwWenb9t3CzbovlwM7T9jq1PFOA/0HyGZtwIoNdPjc0xaPe09oMvRtn69vu7whudjq2oI27jmEvXAfrWxN29oYTb+dPmBgXx/y4Hs2nWctuiCS7l9jN/dgzKTfPP056k7AKp49XIe2PHJZsmq/jhKLh+7aVRjGcWQepgshtbRwNtolPsT3AoblAa/be7d3igl/EbfguPTK/mAANEb73grwQxfNVH/MJr4sQrTKn/DHjbP9GyoKrr6qFxpDiziZB7LD/kvUqSw=]]></Encrypt><AgentID><![CDATA[]]></AgentID></xml>";

[TestMethod]
public void TextTest()
public async Task TextTest()
{
var postModel = new PostModel()
{
Msg_Signature = "Fill Your Setting",
Timestamp = "Fill Your Setting",
Nonce = "Fill Your Setting",
Msg_Signature = "118b034be74c917464f833cd32fc3f74958b2c93",
Timestamp = "1505643268",
Nonce = "1504921331",

Token = "Fill Your Setting",
EncodingAESKey = "Fill Your Setting",
CorpId = "Fill Your Setting"
Token = "3J5JTpb4j8Yfk",
EncodingAESKey = "XtJUgDlFYncPP3z4V7W6Jv4ietcIFveUn6LP1KzOBNf",
CorpId = base._corpId
};
var messageHandler = new CustomMessageHandlers(XDocument.Parse(testXml), postModel, 10);
Assert.IsNotNull(messageHandler.RequestDocument);
Assert.IsNotNull(messageHandler.RequestMessage);
Assert.IsNotNull(messageHandler.EncryptPostData);
Assert.IsTrue(messageHandler.AgentId == 2);

messageHandler.Execute();
await messageHandler.ExecuteAsync(new CancellationToken());

Assert.IsNotNull(messageHandler.ResponseDocument);
Assert.IsNotNull(messageHandler.ResponseMessage);
Expand Down

0 comments on commit 4855e62

Please sign in to comment.