예제 #1
0
        public async Task FormatTypeAsExpected_Custom()
        {
            var serializer = new JsonSerializer(new CustomTypeNameConventionBuilder()
                                                .AddWithShortName <SomeType>()
                                                .GetConvention());

            const string expectedTypeName = "SomeType";

            var message          = new Message(new Dictionary <string, string>(), new SomeType());
            var transportMessage = await serializer.Serialize(message);

            var type = transportMessage.Headers.GetValue(Headers.Type);

            Console.WriteLine($@"

Serialized type name: {type}
  Expected type name: {expectedTypeName}

");

            var roundtrippedMessage = await serializer.Deserialize(transportMessage);

            Assert.That(type, Is.EqualTo(expectedTypeName));
            Assert.That(roundtrippedMessage.Body, Is.TypeOf <SomeType>());
        }
예제 #2
0
        public async Task WorksWithoutFullTypeNameHandlingToo()
        {
            var simpleSerializer = new JsonSerializer(new JsonSerializerSettings());
            var message          = new RandomMessage("hei allihoppa");
            var transportMessage = await simpleSerializer.Serialize(new Message(new Dictionary <string, string>(), message));

            var roundtrippedMessage = (await simpleSerializer.Deserialize(transportMessage)).Body;

            Assert.That(roundtrippedMessage, Is.TypeOf <RandomMessage>());
        }
예제 #3
0
        public async Task FormatTypeAsExpected_Default()
        {
            var expectedTypeName = typeof(SomeType).GetSimpleAssemblyQualifiedName();
            var serializer       = new JsonSerializer(new SimpleAssemblyQualifiedMessageTypeNameConvention());

            var message          = new Message(new Dictionary <string, string>(), new SomeType());
            var transportMessage = await serializer.Serialize(message);

            var type = transportMessage.Headers.GetValue(Headers.Type);

            Console.WriteLine($@"

Serialized type name: {type}
  Expected type name: {expectedTypeName}

");

            var roundtrippedMessage = await serializer.Deserialize(transportMessage);

            Assert.That(type, Is.EqualTo(expectedTypeName));
            Assert.That(roundtrippedMessage.Body, Is.TypeOf <SomeType>());
        }
예제 #4
0
 protected override void SetUp()
 {
     _serializer = new JsonSerializer();
 }
예제 #5
0
 protected override void SetUp()
 {
     _serializer = new JsonSerializer(new SimpleAssemblyQualifiedMessageTypeNameConvention());
 }
예제 #6
0
 protected override void SetUp()
 {
     _serializer = new JsonSerializer(new DefaultMessageTypeMapper());
 }