示例#1
0
        public void ArgumentInline()
        {
            var            id      = Guid.NewGuid().ToString("N").ToUpper();
            IInlineMessage message = new InlineMessage
            {
                ID       = id,
                State    = MessageState.Accept,
                Service  = "Topic",
                Method   = "Title",
                Argument = @"{""Value"": ""Content""}",
                Result   = @"{""Value"": ""Result""}"
            };

            message.CheckState();
            Assert.IsTrue(message.DataState == (MessageDataState.ArgumentOffline | MessageDataState.ResultOffline), message.DataState.ToString());

            //message.PrepareResult(null, ApiResultHelper.State);
            message.RestoryContent(DependencyHelper.GetService <IJsonSerializeProxy>(), typeof(Argument));;
            Assert.IsTrue(message.ArgumentData is Argument, message.ArgumentData.GetTypeName());
            Assert.IsTrue(message.DataState == (MessageDataState.ArgumentOffline | MessageDataState.ResultOffline | MessageDataState.ArgumentInline),
                          message.DataState.ToString());
        }
示例#2
0
        public void ToMessageResult()
        {
            var            id      = Guid.NewGuid().ToString("N").ToUpper();
            IInlineMessage message = new InlineMessage
            {
                ID       = id,
                State    = MessageState.Accept,
                Service  = "Topic",
                Method   = "Title",
                Argument = @"{""Value"": ""Content""}",

                ResultData = new Argument <int>
                {
                    Value = 1
                }
            };

            message.CheckState();
            Assert.IsTrue(message.DataState == (MessageDataState.ArgumentOffline | MessageDataState.ResultInline),
                          message.DataState.ToString());

            message.OfflineResult();
            Assert.IsTrue(message.Result != null, message.Result);
            Assert.IsTrue(message.DataState == (MessageDataState.ArgumentOffline | MessageDataState.ResultOffline | MessageDataState.ResultInline),
                          message.DataState.ToString());

            var result = message.ToMessageResult(true);

            var json = SmartSerializer.ToString(result);

            var result2 = SmartSerializer.ToObject <MessageResult>(json);

            Assert.IsTrue(result2.ID == message.ID, result2.ID);
            Assert.IsTrue(result2.ResultData == null, result2.ResultData.GetTypeName());
            Assert.IsTrue(result2.State == message.State, result2.State.ToString());
            Assert.IsTrue(result2.DataState == MessageDataState.ResultOffline, result2.DataState.ToString());
            Assert.IsTrue(result2.Result == message.Result, result2.Result);
            Assert.IsTrue(result2.Trace.LocalMachine == message.TraceInfo.LocalMachine, result2.Trace.LocalMachine);
        }
示例#3
0
        public void MessageLifeCycle()
        {
            var            id      = Guid.NewGuid().ToString("N").ToUpper();
            IInlineMessage message = new InlineMessage
            {
                ID       = id,
                State    = MessageState.Accept,
                Service  = "Topic",
                Method   = "Title",
                Argument = @"{""Value"": ""Content""}",

                Result = @"{""Value"": ""Result""}"
            };

            message.CheckState();
            Assert.IsTrue(message.DataState == (MessageDataState.ArgumentOffline | MessageDataState.ResultOffline), message.DataState.ToString());

            //message.PrepareResult(null, ApiResultHelper.State);
            message.RestoryContent(DependencyHelper.GetService <IJsonSerializeProxy>(), typeof(Argument));;
            Assert.IsTrue(message.ArgumentData is Argument, message.ArgumentData.GetTypeName());
            Assert.IsTrue(message.DataState == (MessageDataState.ArgumentOffline | MessageDataState.ResultOffline | MessageDataState.ArgumentInline),
                          message.DataState.ToString());

            message = new InlineMessage
            {
                ID       = id,
                State    = MessageState.Accept,
                Service  = "Topic",
                Method   = "Title",
                Argument = @"{""Value"": ""Content""}",

                Result = @"{""Value"": ""Result""}"
            };
            message.ResetToRequest();
            Assert.IsTrue(message.DataState == MessageDataState.ArgumentOffline, message.DataState.ToString());
            Assert.IsTrue(message.Result == null, message.Result);
            //message.PrepareResult(null, ApiResultHelper.State);
            message.RestoryContent(DependencyHelper.GetService <IJsonSerializeProxy>(), typeof(Argument));;
            Assert.IsTrue(message.DataState == (MessageDataState.ArgumentOffline | MessageDataState.ArgumentInline), message.DataState.ToString());

            message.ResultData = new Argument <int>
            {
                Value = 1
            };
            Assert.IsTrue(message.DataState == (MessageDataState.ArgumentOffline | MessageDataState.ArgumentInline | MessageDataState.ResultInline),
                          message.DataState.ToString());

            message.OfflineResult();
            Assert.IsTrue(message.Result != null, message.Result);
            Assert.IsTrue(message.DataState == (MessageDataState.ArgumentOffline | MessageDataState.ArgumentInline | MessageDataState.ResultOffline | MessageDataState.ResultInline),
                          message.DataState.ToString());

            var result = message.ToMessageResult(true);

            var json = SmartSerializer.ToString(result);

            var result2 = SmartSerializer.ToObject <MessageResult>(json);

            Assert.IsTrue(result2.ID == message.ID, result2.ID);
            Assert.IsTrue(result2.ResultData == result.ResultData, result2.ResultData.GetTypeName());
            Assert.IsTrue(result2.State == result.State, result2.State.ToString());
            Assert.IsTrue(result2.DataState == result.DataState, result2.DataState.ToString());
            Assert.IsTrue(result2.Result == result.Result, result2.Result);
            Assert.IsTrue(result2.Trace.LocalMachine == message.TraceInfo.LocalMachine, result2.Trace.LocalMachine);
        }