Beispiel #1
0
        public async Task WithServiceBusRouting_IgnoreMissingMembers_ResultsInDifferentMessageHandler(AdditionalMemberHandling additionalMemberHandling)
        {
            // Arrange
            var services         = new ServiceCollection();
            var collection       = new ServiceBusMessageHandlerCollection(services);
            var messageHandlerV1 = new OrderV1AzureServiceBusMessageHandler();
            var messageHandlerV2 = new OrderV2AzureServiceBusMessageHandler();

            collection.WithServiceBusMessageHandler <OrderV1AzureServiceBusMessageHandler, Order>(provider => messageHandlerV1)
            .WithServiceBusMessageHandler <OrderV2AzureServiceBusMessageHandler, OrderV2>(provider => messageHandlerV2);

            // Act
            services.AddServiceBusMessageRouting(options => options.Deserialization.AdditionalMembers = additionalMemberHandling);

            // Assert
            IServiceProvider serviceProvider = services.BuildServiceProvider();
            var router = serviceProvider.GetRequiredService <IAzureServiceBusMessageRouter>();

            OrderV2 orderV2 = OrderV2Generator.Generate();
            ServiceBusReceivedMessage     message = orderV2.AsServiceBusReceivedMessage();
            AzureServiceBusMessageContext context = AzureServiceBusMessageContextFactory.Generate();
            var correlationInfo = new MessageCorrelationInfo("operation-id", "transaction-id");
            await router.RouteMessageAsync(message, context, correlationInfo, CancellationToken.None);

            Assert.Equal(additionalMemberHandling is AdditionalMemberHandling.Error, messageHandlerV2.IsProcessed);
            Assert.Equal(additionalMemberHandling is AdditionalMemberHandling.Ignore, messageHandlerV1.IsProcessed);
        }
        public async Task WithMessageRouting_WithIgnoreMissingMembers_GoesThroughDifferentMessageHandler(AdditionalMemberHandling additionalMemberHandling)
        {
            // Arrange
            var services         = new ServiceCollection();
            var collection       = new MessageHandlerCollection(services);
            var messageHandlerV1 = new OrderV1MessageHandler();
            var messageHandlerV2 = new OrderV2MessageHandler();

            collection.WithMessageHandler <OrderV1MessageHandler, Order>(provider => messageHandlerV1)
            .WithMessageHandler <OrderV2MessageHandler, OrderV2>(provider => messageHandlerV2);

            // Act
            services.AddMessageRouting(options => options.Deserialization.AdditionalMembers = additionalMemberHandling);

            // Assert
            IServiceProvider serviceProvider = services.BuildServiceProvider();
            var router = serviceProvider.GetRequiredService <IMessageRouter>();

            OrderV2 order           = OrderV2Generator.Generate();
            var     context         = new MessageContext("message-id", new Dictionary <string, object>());
            var     correlationInfo = new MessageCorrelationInfo("operation-id", "transaction-id");
            string  json            = JsonConvert.SerializeObject(order);

            await router.RouteMessageAsync(json, context, correlationInfo, CancellationToken.None);

            Assert.Equal(additionalMemberHandling is AdditionalMemberHandling.Ignore, messageHandlerV1.IsProcessed);
            Assert.Equal(additionalMemberHandling is AdditionalMemberHandling.Error, messageHandlerV2.IsProcessed);
        }