Example #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>());
        }
Example #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>());
        }
Example #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>());
        }