コード例 #1
0
        public void can_serialize_bson_fail_commandresponse()
        {
            var cmd      = new TestCommands.TypedTestCommand(Guid.NewGuid(), null);
            var nearSide = cmd.Fail(new CommandException("O_Ops", cmd), 15);

            TestCommands.TestFailedCommandResponse farSide;
            var ms = new MemoryStream();

            using (var writer = new BsonWriter(ms))
            {
                var serializer = new JsonSerializer();
                serializer.Serialize(writer, nearSide);
            }
            var array = ms.ToArray();

            StringBuilder sb = new StringBuilder();
            StringWriter  sw = new StringWriter(sb);

            using (var writer = new JsonTextWriter(sw))
            {
                var serializer = new JsonSerializer();
                serializer.Serialize(writer, nearSide);
            }
            var foo = sb.ToString();

            var ms2 = new MemoryStream(array);

            using (var reader = new BsonReader(ms2))
            {
                var serializer = new JsonSerializer();
                farSide = serializer.Deserialize <TestCommands.TestFailedCommandResponse>(reader);
            }

            Assert.Equal(nearSide.MsgId, farSide.MsgId);
            Assert.Equal(nearSide.MsgTypeId, farSide.MsgTypeId);
            Assert.Equal(nearSide.CorrelationId, farSide.CorrelationId);
            Assert.Equal(nearSide.CommandType, farSide.CommandType);
            Assert.Equal(nearSide.CommandId, farSide.CommandId);
            Assert.Equal(nearSide.SourceId, farSide.SourceId);
            Assert.Equal(nearSide.Exception.Message, farSide.Exception.Message);

            Assert.Equal(nearSide.Data, farSide.Data);
        }
コード例 #2
0
        public void can_serialize_json_fail_commandresponse()
        {
            var cmd      = new TestCommands.TypedTestCommand(Guid.NewGuid(), null);
            var nearSide = cmd.Fail(new CommandException("O_Ops", cmd), 15);

            TestCommands.TestFailedCommandResponse farSide;


            StringBuilder sb = new StringBuilder();
            StringWriter  sw = new StringWriter(sb);

            using (var writer = new JsonTextWriter(sw))
            {
                var serializer = new JsonSerializer();
                serializer.Serialize(writer, nearSide);
            }
            var foo = sb.ToString();



            using (var reader = new JsonTextReader(new StringReader(foo)))
            {
                var serializer = new JsonSerializer();
                serializer.Binder           = new TestDeserializer();
                serializer.ContractResolver = new TestContractResolver();
                farSide = serializer.Deserialize <TestCommands.TestFailedCommandResponse>(reader);
            }

            Assert.Equal(nearSide.MsgId, farSide.MsgId);
            Assert.Equal(nearSide.MsgTypeId, farSide.MsgTypeId);
            Assert.Equal(nearSide.CorrelationId, farSide.CorrelationId);
            Assert.Equal(nearSide.CommandType, farSide.CommandType);
            Assert.Equal(nearSide.CommandId, farSide.CommandId);
            Assert.Equal(nearSide.SourceId, farSide.SourceId);
            Assert.Equal(nearSide.Exception.Message, farSide.Exception.Message);
            Assert.Equal(nearSide.Data, farSide.Data);
        }