示例#1
0
        static void Serialize2()
        {
            try
            {
                var          id      = Guid.NewGuid().ToString("N").ToUpper();
                IMessageItem message = new MessageItem
                {
                    ID      = id,
                    State   = MessageState.Accept,
                    Topic   = "Topic",
                    Title   = "Title",
                    Content = @"{""Value"": ""Content""}",
                    Trace   = TraceInfo.New(id),
                    Result  = @"{""Value"": ""Result""}"
                };
                var serialize = new JsonSerializeProxy();
                serialize.ToString(message, false);

                DateTime start = DateTime.Now;
                for (int i = 0; i < testCount; i++)
                {
                    serialize.ToString(message, false);
                }
                var time = (DateTime.Now - start).TotalSeconds;
                Console.WriteLine($"{time}s {testCount / time} qps");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"发生异常\n{ex}");
            }
        }
示例#2
0
        public void OperatorStatusJson()
        {
            var status = new OperatorStatus
            {
                Success      = true,
                Code         = 1,
                Message      = "Message",
                InnerMessage = "InnerMessage",
                Exception    = new System.Exception("Exception")
            };
            var microsoft  = new JsonSerializeProxy();
            var newtonsoft = new NewtonJsonSerializeProxy();
            var json1      = newtonsoft.ToString(status, true);
            var json2      = microsoft.ToString(status, true);

            Assert.IsTrue(json2 == json1, json2);
            var status1 = newtonsoft.ToObject <OperatorStatus>(json1);
            var status2 = microsoft.ToObject <OperatorStatus>(json2);

            Assert.IsTrue(status1.Message == status2.Message, json2);
            Assert.IsTrue(status1.Exception == null, json2);

            var xml     = new XmlSerializeProxy();
            var status3 = xml.ToObject <OperatorStatus>(xml.ToString(status));

            Assert.IsTrue(status3.Message == status.Message, json2);
            Assert.IsTrue(status3.Exception == null, json2);

            var cdata   = new CDataXmlSerializeProxy();
            var status4 = cdata.ToObject <OperatorStatus>(cdata.ToString(status));

            Assert.IsTrue(status4.Message == status.Message, json2);
            Assert.IsTrue(status4.Exception == null, json2);
        }
示例#3
0
        public void ArgumentJson()
        {
            var status = new Argument
            {
                Value = "Value"
            };
            var microsoft  = new JsonSerializeProxy();
            var newtonsoft = new NewtonJsonSerializeProxy();
            var json1      = newtonsoft.ToString(status, true);
            var status1    = newtonsoft.ToObject <Argument>(json1);

            Assert.IsTrue(status1.Value == status.Value, json1);

            var json2   = microsoft.ToString(status, true);
            var status2 = microsoft.ToObject <Argument>(json2);

            Assert.IsTrue(status2.Value == status.Value, json2);

            Assert.IsTrue(json2 == json1, json2);

            var xml     = new XmlSerializeProxy();
            var xml1    = xml.ToString(status);
            var status3 = xml.ToObject <Argument>(xml1);

            Assert.IsTrue(status3.Value == status.Value, xml1);

            var cdata   = new CDataXmlSerializeProxy();
            var xml2    = cdata.ToString(status);
            var status4 = cdata.ToObject <Argument>(xml2);

            Assert.IsTrue(status4.Value == status.Value, xml2);
        }
示例#4
0
        public void OperatorTraceJson()
        {
            var status = new OperatorTrace
            {
                RequestId = "RequestId",
                Point     = "Point",
                Guide     = "Guide",
            };
            var microsoft  = new JsonSerializeProxy();
            var newtonsoft = new NewtonJsonSerializeProxy();
            var json1      = newtonsoft.ToString(status, true);
            var json2      = microsoft.ToString(status, true);

            Assert.IsTrue(json2 == json1, json2);

            var status1 = newtonsoft.ToObject <OperatorTrace>(json1);

            Assert.IsTrue(status1.RequestId == status.RequestId, json1);

            var status2 = microsoft.ToObject <OperatorTrace>(json2);

            Assert.IsTrue(status2.Point == status.Point, json2);

            var xml     = new XmlSerializeProxy();
            var status3 = xml.ToObject <OperatorTrace>(xml.ToString(status));

            Assert.IsTrue(status3.Describe == status.Describe, json2);

            var cdata   = new CDataXmlSerializeProxy();
            var status4 = cdata.ToObject <OperatorTrace>(cdata.ToString(status));

            Assert.IsTrue(status4.Guide == status.Guide, json2);
        }
示例#5
0
        public void ApiResultJson()
        {
            var status = new ApiResult <string>
            {
                ResultData   = "data",
                Success      = true,
                Code         = 1,
                Message      = "Message",
                InnerMessage = "InnerMessage",
                Exception    = new System.Exception("Exception"),
                Trace        = new OperatorTrace
                {
                    RequestId = "RequestId",
                    Point     = "Point",
                    Guide     = "Guide",
                }
            };
            var microsoft  = new JsonSerializeProxy();
            var newtonsoft = new NewtonJsonSerializeProxy();
            var json1      = newtonsoft.ToString(status, true);
            var json2      = microsoft.ToString(status, true);

            Assert.IsTrue(json2 == json1, json2);
            var status1 = newtonsoft.ToObject <ApiResult <string> >(json1);
            var status2 = microsoft.ToObject <ApiResult <string> >(json2);

            Assert.IsTrue(status1.Message == status2.Message, json2);
            Assert.IsTrue(status1.Exception == null, json2);

            var xml     = new XmlSerializeProxy();
            var status3 = xml.ToObject <ApiResult <string> >(xml.ToString(status));

            Assert.IsTrue(status3.Message == status.Message, json2);
            Assert.IsTrue(status3.ResultData == status.ResultData, json2);

            var cdata   = new CDataXmlSerializeProxy();
            var status4 = cdata.ToObject <ApiResult <string> >(cdata.ToString(status));

            Assert.IsTrue(status4.Message == status.Message, json2);
            Assert.IsTrue(status4.Trace.Point == status.Trace.Point, json2);
        }