public async Task when_create_case_command_received_it_should_create_case_in_store() { var container = RoutingTests.SetupContainer <EmptyPipeFitter, FinishTestPipeFitter, EmptyPipeFitter, FinishTestPipeFitter>( api => api .WithId("ingress-case-office") .WithQueueNamePatternsProvider <VentureQueueNamePatternsProvider>() .WithPipeFitter <VentureIngressPipeFitter>() .WithMessageKey <Ignore>() .WithMessagePayload <byte[]>() .WithMessageTypesRegistry <CaseOfficeIngressApiMessageTypesRegistry>() .WithHandlerRegistry <VentureServiceHandlersRegistry>(), api => api .WithId("egress-case-office") .WithMessageKey <int>() .WithMessagePayload <byte[]>() .WithMessageTypesRegistry <EmptyEgressApiMessageTypesRegistry>() .WithPipeFitter <EmptyPipeFitter>(), _testOutput); container.RegisterSingleton <VentureQueueNamePatternsProvider>(); AddIngressPipeline(container); var registry = new CaseOfficeIngressApiMessageTypesRegistry(); registry.Initialize(); container.RegisterInstance(registry); const string topic = "venture.commands.case-office.v1"; var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(value: 5)).Token; await using var kafkaTestContext = _kafkaTestContextFactory.Create <int, byte[]>(timeout); await kafkaTestContext.CreateTopics(topic); var testIsFinished = RoutingTests.AddTestFinishSemaphore(container); var router = container.GetMessageRouter(); await router.Start(timeout); var stringCreator = new StringCreator(); var expectedReason = stringCreator.Get(length: 10); var(command, serialized) = CreateSerializedMessage(expectedReason); var headers = CreateHeaders(command.GetType()); await kafkaTestContext.Produce( topic, int.MaxValue, serialized, headers); await testIsFinished.WaitAsync(timeout); var justiceCaseStorage = (IAggregateStorageTestBackdoor <JusticeCase>)container.GetInstance <IAggregateStorage <JusticeCase> >(); justiceCaseStorage.GetAll().Should().HaveCount(expected: 1); justiceCaseStorage.GetAll().Single().Reason.Should().Be(expectedReason); // TODO: assert }
public async Task when_message_published_to_kafka_topic_it_should_be_received_by_properly_configured_poezd() { var timeoutOrDoneSource = new CancellationTokenSource(TimeSpan.FromSeconds(value: 5)); var doneOrTimeout = timeoutOrDoneSource.Token; var topic = RoutingTests.GetRandomTopic(); await using var kafkaTestContext = _kafkaTestContextFactory.Create <string, string>(doneOrTimeout); await kafkaTestContext.CreateTopics(topic); var enterProperties = new MessageLoggingStep.Properties(); var exitProperties = new MessageCountingStep.Properties(expectedMessageCount: 2, timeoutOrDoneSource); var publishedKey1 = CreateString(length: 10); var publishedPayload1 = CreateString(length: 10); await ProduceMessage( topic, publishedKey1, publishedPayload1, kafkaTestContext); var container = BuildContainerToHandleMessages(enterProperties, exitProperties); container.RegisterSingleton( () => CreateMessageRouterConfigurationToHandleMessages().CreateMessageRouter(new SimpleInjectorAdapter(container))); await container.GetInstance <IMessageRouter>().Start(doneOrTimeout); var publishedKey2 = CreateString(length: 20); var publishedPayload2 = CreateString(length: 20); await ProduceMessage( topic, publishedKey2, publishedPayload2, kafkaTestContext); await doneOrTimeout; enterProperties.Messages.Select(message => (string)message.Key).Should().Equal( new[] { publishedKey1, publishedKey2 }, "these messages were published in this order"); enterProperties.Messages.Select(message => (string)message.Value).Should().Equal( new[] { publishedPayload1, publishedPayload2 }, "these messages were published in this order"); }
public async Task when_message_published_to_kafka_topic_it_should_be_received_from_same_topic() { var topic = RoutingTests.GetRandomTopic(); var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(value: 5)).Token; await using var kafkaTestContext = _kafkaTestContextFactory.Create <string, string>(timeout); await kafkaTestContext.CreateTopics(topic); var expectedValue = RoutingTests.GetRandomString(); await kafkaTestContext.Produce( topic, string.Empty, expectedValue, new Dictionary <string, byte[]> { { "header1", new byte[0] } }); var consumeResult = kafkaTestContext.Consume(topic); consumeResult.Message.Value.Should().Be(expectedValue, "this thing was sent"); consumeResult.Message.Headers.Count.Should().Be(expected: 1, "one header was set"); }