コード例 #1
0
        public void ShouldSerializeToYaml()
        {
            IMessageSerializer serializer = new YamlMessageSerializer();

            var message = new TestMessageProto {
                Id = 123, Name = "SomeName"
            };
            var serialize = YamlMessageDefaults.Encoding.GetString(serializer.Serialize(message));

            Assert.NotNull(serialize);
            Assert.Contains(message.Id.ToString(), serialize);
            Assert.Contains(message.Name, serialize);
        }
コード例 #2
0
        public void ShouldDeserializeFromYaml()
        {
            IMessageSerializer serializer = new YamlMessageSerializer();
            IMessageDeserializer <TestMessageProto> deserializer = new YamlMessageDeserializer <TestMessageProto>();

            var message = new TestMessageProto {
                Id = 123, Name = "SomeName"
            };
            var serialize   = serializer.Serialize(message);
            var deserialize = deserializer.Deserialize(serialize);

            Assert.Equal(message, deserialize);
        }
コード例 #3
0
        public void YamlDeserializerFactoryShouldWork()
        {
            var factory = new YamlMessageDeserializerFactory(typeof(YamlMessageDeserializer <>));
            var deses   = factory.Create <TestMessage, IMessage>(ShouldLoadAssembly);
            var des     = deses.FirstOrDefault(d => d.GetTypeName() == typeof(TestMessage).Name);

            IMessageSerializer serializer = new YamlMessageSerializer();
            var messageBefore             = new TestMessage {
                Id = 123, Name = "SomeName"
            };
            var bytes = serializer.Serialize(messageBefore);

            var messageAfter = des.Deserialize(bytes);

            Assert.Equal(messageBefore, messageAfter);
        }