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_Change_Contact_User_Create()
{
//官方提供
var xml = @"
1403610513
create_user
1
13800000000
1
1
-
0
-
1
";
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_Change_Contact_User_Create));
var requestMessage = messageHandler.RequestMessage as RequestMessageEvent_Change_Contact_User_Create;
Console.WriteLine(requestMessage.ToJson(true));
Assert.AreEqual(Event.change_contact, requestMessage.Event);
Assert.AreEqual(ContactChangeType.create_user, requestMessage.ChangeType);
Assert.AreEqual("张三", requestMessage.Name);
Assert.AreEqual("1,2,3", requestMessage.Department);
Assert.AreEqual(3, requestMessage.DepartmentIdList.Count());
Assert.AreEqual(1, requestMessage.DepartmentIdList[0]);
Assert.AreEqual(2, requestMessage.DepartmentIdList[1]);
Assert.AreEqual(3, requestMessage.DepartmentIdList[2]);
Assert.AreEqual(1, requestMessage.MainDepartment);
Assert.AreEqual("1,0,0", requestMessage.IsLeaderInDept);
Assert.AreEqual(3, requestMessage.IsLeaderInDeptList.Count());
Assert.AreEqual(1, requestMessage.IsLeaderInDeptList[0]);
Assert.AreEqual(0, requestMessage.IsLeaderInDeptList[1]);
Assert.AreEqual(0, requestMessage.IsLeaderInDeptList[2]);
Assert.AreEqual("lisi,wangwu", requestMessage.DirectLeader);
Assert.AreEqual(2, requestMessage.DirectLeaderList.Count());
Assert.AreEqual("lisi", requestMessage.DirectLeaderList[0]);
Assert.AreEqual("wangwu", requestMessage.DirectLeaderList[1]);
Assert.AreEqual("产品经理", requestMessage.Position);
Assert.AreEqual("13800000000", requestMessage.Mobile);
Assert.AreEqual(1, requestMessage.Gender);
Assert.AreEqual("zhangsan@gzdev.com", requestMessage.Email);
Assert.AreEqual("zhangsan@qyycs2.wecom.work", requestMessage.BizMail);
Assert.AreEqual(1, requestMessage.Status);
Assert.AreEqual("http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0", requestMessage.Avatar);
Assert.AreEqual("zhangsan", requestMessage.Alias);
Assert.AreEqual("020-123456", requestMessage.Telephone);
Assert.AreEqual("广州市", requestMessage.Address);
Assert.AreEqual(2, requestMessage.ExtAttr.Count());
Assert.AreEqual("爱好", requestMessage.ExtAttr[0].Name);
Assert.AreEqual(0, requestMessage.ExtAttr[0].Type);
Assert.AreEqual("旅游", requestMessage.ExtAttr[0].Text.Value);
Assert.AreEqual("卡号", requestMessage.ExtAttr[1].Name);
Assert.AreEqual(1, requestMessage.ExtAttr[1].Type);
Assert.AreEqual("企业微信", requestMessage.ExtAttr[1].Web.Title);
Assert.AreEqual("https://work.weixin.qq.com", requestMessage.ExtAttr[1].Web.Url);
}
}
}