using Microsoft.VisualStudio.TestTools.UnitTesting;
using Senparc.CO2NET.Extensions;
using Senparc.NeuChar;
using Senparc.Weixin.Work.Entities;
using Senparc.Weixin.Work.Test.net6.MessageHandlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace Senparc.Weixin.Work.Test.MessageHandlers
{
///
/// 审批相关测试
///
public partial class WorkMessageHandlersTest
{
///
/// 系统审批
///
[TestMethod]
public void RequestMessageEvent_SysApprovalChangeTest()
{
//官方提供
var xml = @"
1571732272
3010040
201910220003
1
1571728713
1
2
1
0
1
0
1
1
1
0
1571732272
15717322723
MediaId
10
";
var postModel = new PostModel()
{
Msg_Signature = "22cb38c34ae9ba4bdec938405b931ad3ece7e19e",
Timestamp = "1644320363",
Nonce = "1645172247",
Token = "",
EncodingAESKey = "",
CorpId = ""
};
var messageHandler = new CustomMessageHandlers(XDocument.Parse(xml), postModel, 10);
messageHandler.Execute();
var responseMessage = messageHandler.ResponseDocument;
Assert.IsNotNull(messageHandler.RequestMessage);
Assert.AreEqual(RequestMsgType.Event, messageHandler.RequestMessage.MsgType);
Assert.IsInstanceOfType(messageHandler.RequestMessage, typeof(RequestMessageEvent_SysApprovalChange));
var requestMessage = messageHandler.RequestMessage as RequestMessageEvent_SysApprovalChange;
Console.WriteLine(requestMessage.ToJson(true));
Assert.AreEqual(Event.SYS_APPROVAL_CHANGE, requestMessage.Event);
Assert.IsNotNull(requestMessage.ApprovalInfo);
Assert.AreEqual((ulong)201910220003, requestMessage.ApprovalInfo.SpNo);
Assert.AreEqual("示例模板", requestMessage.ApprovalInfo.SpName);
Assert.AreEqual((byte)1, requestMessage.ApprovalInfo.SpStatus);
Assert.IsNotNull(requestMessage.ApprovalInfo.SpRecords);
Assert.AreEqual(2, requestMessage.ApprovalInfo.SpRecords.Length);
Assert.AreEqual(2, requestMessage.ApprovalInfo.SpRecords[0].ApproverAttr);
Assert.AreEqual(2, requestMessage.ApprovalInfo.SpRecords[0].Details.Length);
Assert.AreEqual(1, requestMessage.ApprovalInfo.SpRecords[0].Details[0].SpStatus);
Assert.AreEqual(2, requestMessage.ApprovalInfo.Notifyers.Length);
Assert.AreEqual("ChengLiang2", requestMessage.ApprovalInfo.Notifyers[1].UserId);
Assert.AreEqual(2, requestMessage.ApprovalInfo.Comments.Length);
Assert.AreEqual("LiuZhi2", requestMessage.ApprovalInfo.Comments[1].CommentUserInfo.UserId);
Assert.AreEqual("这又是一个备注", requestMessage.ApprovalInfo.Comments[1].CommentContent);
Assert.AreEqual("6750538708562308221", requestMessage.ApprovalInfo.Comments[1].CommentId);
Assert.AreEqual("MediaId", requestMessage.ApprovalInfo.Comments[1].Attach);
/* 实际收到的:
1645070366
1000002
202202170001
1
1645070220
1
2
1
0
1
0
1645070277
1645070366
10
*/
}
///
/// 自定义审批
///
[TestMethod]
public void RequestMessageEvent_OpenApprovalChangeTest()
{
var xml = @"
wwd08c8e7c775abaaa
sys
1527838022
event
open_approval_change
1
thirdNoxxx
付款
1234567111
1
1527837645
jackiejjwu
WuJunJie
产品部
http://www.qq.com/xxx.png
1
1
1
-
chauvetxiao
XiaoWen
产品部
http://www.qq.com/xxx.png
1
0
-
chauvetxiao
XiaoWen
产品部
http://www.qq.com/xxx.png
1
0
1
1
1
-
chauvetxiao
XiaoWen
产品部
http://www.qq.com/xxx.png
1
0
-
chauvetxiao2
XiaoWen2
产品部2
http://www.qq.com/xxx2.png
1
0
jinhuiguo
GuoJinHui
行政部
http://www.qq.com/xxx.png
jinhuiguo
GuoJinHui
行政部
http://www.qq.com/xxx.png
10
";
var postModel = new PostModel()
{
Msg_Signature = "22cb38c34ae9ba4bdec938405b931ad3ece7e19e",
Timestamp = "1644320363",
Nonce = "1645172247",
Token = "",
EncodingAESKey = "",
CorpId = ""
};
var messageHandler = new CustomMessageHandlers(XDocument.Parse(xml), postModel, 10);
messageHandler.Execute();
var responseMessage = messageHandler.ResponseDocument;
Assert.IsNotNull(messageHandler.RequestMessage);
Assert.AreEqual(RequestMsgType.Event, messageHandler.RequestMessage.MsgType);
Assert.IsInstanceOfType(messageHandler.RequestMessage, typeof(RequestMessageEvent_OpenApprovalChange));
var requestMessage = messageHandler.RequestMessage as RequestMessageEvent_OpenApprovalChange;
Console.WriteLine(requestMessage.ToJson(true));
Assert.AreEqual(Event.OPEN_APPROVAL_CHANGE, requestMessage.Event);
Assert.IsNotNull(requestMessage.ApprovalInfo);
Assert.AreEqual("thirdNoxxx", requestMessage.ApprovalInfo.ThirdNo);
Assert.AreEqual((uint)1234567111, requestMessage.ApprovalInfo.OpenTemplateId);
Assert.AreEqual("产品部", requestMessage.ApprovalInfo.ApplyUserParty);
Assert.IsNotNull(requestMessage.ApprovalInfo.ApprovalNodes);
Assert.IsTrue(requestMessage.ApprovalInfo.ApprovalNodes.Length == 2);
var firstApprovalNode = requestMessage.ApprovalInfo.ApprovalNodes.First();
Assert.IsNotNull(firstApprovalNode.Items);
Assert.IsTrue(firstApprovalNode.Items.Length == 2);
var firstItem = firstApprovalNode.Items.First();
Assert.AreEqual("chauvetxiao", firstItem.ItemName);
Assert.AreEqual("http://www.qq.com/xxx.png", firstItem.ItemImage);
var secondApprovalNode = requestMessage.ApprovalInfo.ApprovalNodes[1];
Assert.IsNotNull(secondApprovalNode.Items);
Assert.IsTrue(secondApprovalNode.Items.Length == 2);
var secondItem = secondApprovalNode.Items[1];
Assert.AreEqual("chauvetxiao2", secondItem.ItemName);
Assert.AreEqual("产品部2", secondItem.ItemParty);
Assert.AreEqual("http://www.qq.com/xxx2.png", secondItem.ItemImage);
Assert.IsNotNull(requestMessage.ApprovalInfo.NotifyNodes);
Assert.IsTrue(requestMessage.ApprovalInfo.NotifyNodes.Length > 0);
var firstNotifyNode = requestMessage.ApprovalInfo.NotifyNodes.First();
Assert.AreEqual("jinhuiguo", firstNotifyNode.ItemName);
Assert.AreEqual(10, requestMessage.ApprovalInfo.ApproverStep);
}
}
}