Beispiel #1
0
        /// <summary>
        /// 创建请求消息实例。
        /// </summary>
        /// <param name="requestMessageFactory">请求消息工厂。</param>
        /// <param name="stream">数据流。</param>
        /// <returns>请求消息。</returns>
        public static IMessageBase CreateRequestMessage(this IRequestMessageFactory requestMessageFactory, Stream stream)
        {
            stream.NotNull("stream");
            var bytes = new byte[stream.Length];

            stream.Read(bytes, 0, bytes.Length);
            var content = Encoding.UTF8.GetString(bytes);

            return(requestMessageFactory.CreateRequestMessage(content));
        }
Beispiel #2
0
        public void TextMessageTest()
        {
            const string xmlContent = @"<xml>
 <ToUserName><![CDATA[toUser]]></ToUserName>
 <FromUserName><![CDATA[fromUser]]></FromUserName>
 <CreateTime>1348831860</CreateTime>
 <MsgType><![CDATA[text]]></MsgType>
 <Content><![CDATA[this is a test]]></Content>
 <MsgId>1234567890123456</MsgId>
 </xml>";

            var model = _requestMessageFactory.CreateRequestMessage <RequestMessageText>(xmlContent);

            Assert.AreEqual("toUser", model.ToUserName);
            Assert.AreEqual("fromUser", model.FromUserName);
            Assert.AreEqual(RequestMessageType.Text, model.MessageType);
            Assert.AreEqual(DateTimeHelper.GetTimeByTimeStamp(1348831860), model.CreateTime);
            Assert.AreEqual("this is a test", model.Content);
            Assert.AreEqual(1234567890123456, model.MessageId);
        }
Beispiel #3
0
 /// <summary>
 /// 创建请求消息实例。
 /// </summary>
 /// <typeparam name="T">请求消息类型。</typeparam>
 /// <param name="requestMessageFactory">请求消息工厂。</param>
 /// <param name="xmlContent">xml内容。</param>
 /// <returns>请求消息。</returns>
 public static T CreateRequestMessage <T>(this IRequestMessageFactory requestMessageFactory, string xmlContent) where T : class, IMessageBase
 {
     return(requestMessageFactory.CreateRequestMessage(xmlContent) as T);
 }