using System;
using System.IO;
using System.Xml.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Senparc.Weixin.Open.Entities.Request;
using Senparc.Weixin.Open.MessageHandlers;
namespace Senparc.Weixin.Open.Test.ThirdPartyMessageHandlers
{
public class CustomMessageHandler : ThirdPartyMessageHandler
{
public CustomMessageHandler(XDocument ecryptRequestDocument, PostModel postModel = null)
: base(ecryptRequestDocument, postModel)
{
}
}
[TestClass]
public class ThirdPartyMessageHandlerTest
{
//TODO:以下XML不正确
private string requestXML = @"
";
string sToken = "senparc";
string sAppID = "wxbbd3f07e2945cf2a";
string sEncodingAESKey = "0123456789012345678901234567890123456789012";
string sReqMsgSig = "346f1ed0ed84e80342072f2b88e2f4f018b8c79d";
string sReqTimeStamp = "1436876197";
string sReqNonce = "1879066412";
private string sReqSig = "6cd59ed9ca88d3993475bd4960052c5e5204391e";
[TestMethod]
public void UnAuthMessageHandlerTest()
{
var postModel = new PostModel()
{
AppId = sAppID,
Msg_Signature = sReqMsgSig,
Signature = sReqSig,
Timestamp = sReqTimeStamp,
Nonce = sReqNonce,
Token = sToken,
EncodingAESKey = sEncodingAESKey
};
var messageHandler = new CustomMessageHandler(XDocument.Parse(requestXML), postModel);
messageHandler.Execute();
//TestMessageHandlers中没有处理坐标信息的重写方法,将返回默认消息
Assert.IsInstanceOfType(messageHandler.ResponseMessageText, typeof(String));
Assert.IsInstanceOfType(messageHandler.RequestMessage, typeof(RequestMessageUnauthorized));
Assert.AreEqual("success", messageHandler.ResponseMessageText);
Console.WriteLine(messageHandler.RequestDocument.ToString());
}
[TestMethod]
public void TicketMessageHandlerTest()
{
string xml = @"
";
var postModel = new PostModel()
{
AppId = sAppID,
Msg_Signature = "066523677e42a15c64a725ba0058cd7651174624",
Signature = "60d1ddec039f51cc8c7ee4ea9ae9a479dd7c7d01",
Timestamp = "1436881222",
Nonce = "296318614",
Token = sToken,
EncodingAESKey = sEncodingAESKey
};
var messageHandler = new CustomMessageHandler(XDocument.Parse(xml), postModel);
messageHandler.Execute();
//TestMessageHandlers中没有处理坐标信息的重写方法,将返回默认消息
Assert.IsInstanceOfType(messageHandler.ResponseMessageText, typeof(String));
Assert.AreEqual("success", messageHandler.ResponseMessageText);
Console.WriteLine(messageHandler.RequestDocument.ToString());
Assert.IsInstanceOfType(messageHandler.RequestMessage, typeof(RequestMessageComponentVerifyTicket));
}
}
}