Skip to content

Commit

Permalink
调整单元测试代码,使用新的MessaageHandler构造函数
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreySu committed Oct 21, 2018
1 parent bebe6c7 commit 28dd9fc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ and limitations under the License.
using Senparc.NeuChar.Context;
using Senparc.NeuChar.Entities;
using Senparc.Weixin.MP.Entities;
using Senparc.Weixin.MP.Entities.Request;
using Senparc.Weixin.MP.MessageHandlers;

namespace Senparc.Weixin.MP.Test.MessageHandlers
{
public class CancelMessageHandlers : MessageHandler<MessageContext<IRequestMessageBase,IResponseMessageBase>>
public class CancelMessageHandlers : MessageHandler<MessageContext<IRequestMessageBase, IResponseMessageBase>>
{
public string RunStep { get; set; }

public CancelMessageHandlers(XDocument requestDoc)
: base(requestDoc)
public CancelMessageHandlers(XDocument requestDoc, PostModel postModel)
: base(requestDoc, postModel)
{
}

Expand Down Expand Up @@ -88,9 +89,10 @@ public class MessageHandlers_CancelTest
[TestMethod]
public void CancelTest()
{
var postModel = new PostModel() { AppId = "appId" };
{
//一开始就取消
var messageHandler = new CancelMessageHandlers(XDocument.Parse(xmlText));
var messageHandler = new CancelMessageHandlers(XDocument.Parse(xmlText), postModel);
messageHandler.CancelExcute = true;
messageHandler.Execute();

Expand All @@ -99,7 +101,7 @@ public void CancelTest()

{
//OnExecuting中途取消
var messageHandler = new CancelMessageHandlers(XDocument.Parse(xmlText));
var messageHandler = new CancelMessageHandlers(XDocument.Parse(xmlText), postModel);
messageHandler.Execute();

Assert.AreEqual("OnExecuting", messageHandler.RunStep);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and limitations under the License.
using Senparc.NeuChar.Context;
using Senparc.NeuChar.Entities;
using Senparc.Weixin.MP.Entities;
using Senparc.Weixin.MP.Entities.Request;
using Senparc.Weixin.MP.MessageHandlers;

namespace Senparc.Weixin.MP.Test.MessageHandlers
Expand All @@ -32,8 +33,9 @@ public class OmitRepeatMessageMessageHandlers : MessageHandler<MessageContext<IR
{
public string RunStep { get; set; }

public OmitRepeatMessageMessageHandlers(XDocument requestDoc)
: base(requestDoc)

public OmitRepeatMessageMessageHandlers(XDocument requestDoc,PostModel postModel)
: base(requestDoc, postModel)
{
}

Expand Down Expand Up @@ -76,17 +78,20 @@ public class MessageHandlers_OmitRepeatMessage
</xml>
";

private PostModel _postModel = new PostModel() { AppId = "appId" };


[TestMethod]
public void OmitMessageTest_DifferentMsgId()
{
//发送两条不同MsgId的消息
var messageHandler = new OmitRepeatMessageMessageHandlers(XDocument.Parse(string.Format(xmlText, "11", "Jeffrey")));
var messageHandler = new OmitRepeatMessageMessageHandlers(XDocument.Parse(string.Format(xmlText, "11", "Jeffrey")), _postModel);
messageHandler.OmitRepeatedMessage = true;
messageHandler.Execute();
Assert.IsNotNull(messageHandler.ResponseMessage);
Assert.AreEqual("Jeffrey", (messageHandler.ResponseMessage as ResponseMessageText).Content);

messageHandler = new OmitRepeatMessageMessageHandlers(XDocument.Parse(string.Format(xmlText, "12", "Su")));
messageHandler = new OmitRepeatMessageMessageHandlers(XDocument.Parse(string.Format(xmlText, "12", "Su")), _postModel);
messageHandler.OmitRepeatedMessage = true;
messageHandler.Execute();
Assert.IsNotNull(messageHandler.ResponseMessage);
Expand All @@ -97,13 +102,13 @@ public void OmitMessageTest_DifferentMsgId()
public void OmitMessageTest_SameMsgId()
{
//发送两条相同MsgId的消息
var messageHandler = new OmitRepeatMessageMessageHandlers(XDocument.Parse(string.Format(xmlText, "21", "Jeffrey")));
var messageHandler = new OmitRepeatMessageMessageHandlers(XDocument.Parse(string.Format(xmlText, "21", "Jeffrey")), _postModel);
messageHandler.OmitRepeatedMessage = true;
messageHandler.Execute();
Assert.IsNotNull(messageHandler.ResponseMessage);
Assert.AreEqual("Jeffrey", (messageHandler.ResponseMessage as ResponseMessageText).Content);

messageHandler = new OmitRepeatMessageMessageHandlers(XDocument.Parse(string.Format(xmlText, "21", "Su")));
messageHandler = new OmitRepeatMessageMessageHandlers(XDocument.Parse(string.Format(xmlText, "21", "Su")), _postModel);
messageHandler.OmitRepeatedMessage = true;
messageHandler.Execute();
Assert.IsNull(messageHandler.ResponseMessage);
Expand All @@ -115,13 +120,13 @@ public void OmitMessageTest_SameMsgId()
public void OmitMessageTest_NotOmit()
{
//发送两条相同MsgId的消息,但是不启用忽略
var messageHandler = new OmitRepeatMessageMessageHandlers(XDocument.Parse(string.Format(xmlText, "31", "Jeffrey")));
var messageHandler = new OmitRepeatMessageMessageHandlers(XDocument.Parse(string.Format(xmlText, "31", "Jeffrey")), _postModel);
messageHandler.OmitRepeatedMessage = false;
messageHandler.Execute();
Assert.IsNotNull(messageHandler.ResponseMessage);
Assert.AreEqual("Jeffrey", (messageHandler.ResponseMessage as ResponseMessageText).Content);

messageHandler = new OmitRepeatMessageMessageHandlers(XDocument.Parse(string.Format(xmlText, "31", "Su")));
messageHandler = new OmitRepeatMessageMessageHandlers(XDocument.Parse(string.Format(xmlText, "31", "Su")), _postModel);
messageHandler.OmitRepeatedMessage = false;
messageHandler.Execute();
Assert.IsNotNull(messageHandler.ResponseMessage);
Expand Down

0 comments on commit 28dd9fc

Please sign in to comment.