#region Apache License Version 2.0 /*---------------------------------------------------------------- Copyright 2022 Jeffrey Su & Suzhou Senparc Network Technology Co.,Ltd. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md ----------------------------------------------------------------*/ #endregion Apache License Version 2.0 using System; using System.Collections.Generic; using System.Xml.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using Senparc.CO2NET.Helpers; using Senparc.NeuChar.Entities; using Senparc.Weixin.Helpers; using Senparc.Weixin.MP.Entities; using Senparc.Weixin.MP.Helpers; namespace Senparc.Weixin.MP.Test { [TestClass] public class ResponseMessageFactoryTest { string xmlText = @" 63497820384 text 0 "; string xmlNews = @" 63497821905 news 2 <![CDATA[您刚才发送了图片信息]]> <![CDATA[第二条]]> 0 "; string xmlMusic = @" 63497823450 music <![CDATA[标题]]> 0 "; [TestMethod] public void GetResponseEntityTest() { { //Text ResponseMessageText exceptResult = new ResponseMessageText() { ToUserName = "olPjZjsXuQPJoV0HlruZkNzKc91E", FromUserName = "gh_a96a4a619366", CreateTime = DateTimeHelper.GetDateTimeFromXml(63497820384), //MsgType = ResponseMsgType.Text, Content = "文字信息", //FuncFlag = false }; var result = ResponseMessageFactory.GetResponseEntity(xmlText) as ResponseMessageText; Assert.AreEqual(exceptResult.ToUserName, result.ToUserName); Assert.AreEqual(exceptResult.CreateTime, result.CreateTime); Assert.AreEqual(exceptResult.Content, result.Content); } { //Image ResponseMessageNews exceptResult = new ResponseMessageNews() { //Articles = new List
(), CreateTime = DateTimeHelper.GetDateTimeFromXml(63497821905), FromUserName = "gh_a96a4a619366", ToUserName = "olPjZjsXuQPJoV0HlruZkNzKc91E", //FuncFlag = false, //MsgType = ResponseMsgType.News }; var result = ResponseMessageFactory.GetResponseEntity(xmlNews) as ResponseMessageNews; Assert.AreEqual(exceptResult.ToUserName, result.ToUserName); Assert.AreEqual(exceptResult.CreateTime, result.CreateTime); Assert.AreEqual(2, result.ArticleCount); Assert.AreEqual(result.Articles.Count, result.ArticleCount); } //TODO:测试语音和视频类型 { //Music ResponseMessageMusic exceptResult = new ResponseMessageMusic() { Music = new Music() { Title = "标题", Description = "说明", MusicUrl = "https://sdk.weixin.senparc.com/Content/music1.mp3", HQMusicUrl = "" }, CreateTime = DateTimeHelper.GetDateTimeFromXml(63497823450), FromUserName = "gh_a96a4a619366", ToUserName = "olPjZjsXuQPJoV0HlruZkNzKc91E", //FuncFlag = false, //MsgType = ResponseMsgType.Music }; var result = ResponseMessageFactory.GetResponseEntity(xmlMusic) as ResponseMessageMusic; Assert.AreEqual(exceptResult.ToUserName, result.ToUserName); Assert.AreEqual(exceptResult.CreateTime, result.CreateTime); //Assert.AreEqual(exceptResult.Music, result.Music); } } } }