public async Task Sent_commands_are_received([Frozen] IEnvelopeService envelopeService, InMemoryBusEngine sut, CommandMessage <FirstTestCommand> testMessage, IFixture fixture, string headerKey, string headerValue) { fixture.Customize <Envelope>(c => c .With(p => p.Type, testMessage.Type) .With(p => p.Headers, testMessage.Headers) .With(p => p.Content) .With(p => p.MessageId, testMessage.MessageId) .With(p => p.MessageType, testMessage.MessageType) ); Mock.Get(envelopeService).Setup(p => p.CreateEnvelope(It.IsAny <CommandMessage <FirstTestCommand> >())).ReturnsUsingFixture(fixture); Mock.Get(envelopeService).Setup(p => p.CreateCommandMessage(It.IsAny <Envelope>(), It.IsAny <Type>())).Returns(testMessage); testMessage.Headers[headerKey] = headerValue; sut.SubscribeToCommand <FirstTestCommand>(); var sequence = await sut.StartAsync().ConfigureAwait(false); var items = sequence.DumpInList(); await sut.SendMessageAsync(testMessage); Assert.That(items.First().Headers, Contains.Key(headerKey)); Assert.That(items.First().Headers[headerKey], Is.EqualTo(headerValue)); }
public async Task Stop_completes_the_sequence_if_started(InMemoryBusEngine sut) { var sequence = await sut.StartAsync(); var isCompleted = false; sequence.Subscribe( onNext: _ => { }, onError: _ => { }, onCompleted: () => isCompleted = true ); await sut.StopAsync(); Assert.That(isCompleted, Is.True); }
public async Task Events_are_ignored_if_not_registered([Frozen] IMessageDescriptorStore messageDescriptorStore, [Frozen] IEnvelopeService envelopeService, InMemoryBusEngine sut, EventMessage <FirstTestEvent> testMessage, IFixture fixture) { fixture.Customize <Envelope>(c => c .With(p => p.Type, testMessage.Type) .With(p => p.Headers, testMessage.Headers) .With(p => p.Content) .With(p => p.MessageId, testMessage.MessageId) .With(p => p.MessageType, testMessage.MessageType) ); Mock.Get(envelopeService).Setup(p => p.CreateEnvelope(It.IsAny <EventMessage <FirstTestEvent> >())).ReturnsUsingFixture(fixture); Mock.Get(envelopeService).Setup(p => p.CreateEventMessage(It.IsAny <Envelope>(), It.IsAny <Type>())).Returns(testMessage); var sequence = await sut.StartAsync().ConfigureAwait(false); var items = sequence.DumpInList(); await sut.SendMessageAsync(testMessage); Assert.That(items, Is.Empty); }
public async Task Sent_events_are_received([Frozen] IEnvelopeService envelopeService, InMemoryBusEngine sut, EventMessage <FirstTestEvent> testMessage, IFixture fixture) { fixture.Customize <Envelope>(c => c .With(p => p.Type, testMessage.Type) .With(p => p.Headers, testMessage.Headers) .With(p => p.Content) .With(p => p.MessageId, testMessage.MessageId) .With(p => p.MessageType, testMessage.MessageType) ); Mock.Get(envelopeService).Setup(p => p.CreateEnvelope(It.IsAny <EventMessage <FirstTestEvent> >())).ReturnsUsingFixture(fixture); Mock.Get(envelopeService).Setup(p => p.CreateEventMessage(It.IsAny <Envelope>(), It.IsAny <Type>())).Returns(testMessage); sut.SubscribeToEvent <FirstTestEvent>(); var sequence = await sut.StartAsync().ConfigureAwait(false); var items = sequence.DumpInList(); await sut.SendMessageAsync(testMessage); Assert.That(items.First(), Is.EqualTo(testMessage).Using <EventMessage <FirstTestEvent> >((x, y) => x.MessageId == y.MessageId)); }