public async Task Start_returns_close_function() { // Arrange await ReceiveAndForgetAll(); var messageBus = new MessageBus(); var serializer = new JsonMessageSerializer(); var envelope = new Envelope( messageId: Guid.NewGuid(), message: new Fixture().Create <SomeMessage>()); // Act Func <Task> closeFunction = ServiceBusMessageMediator.Start(_connectionStringBuilder, messageBus, serializer); try { await closeFunction.Invoke(); await SendMessage(envelope, serializer); // Assert await Task.WhenAny(Task.Delay(TimeSpan.FromMilliseconds(3000)), messageBus.SentMessage); messageBus.SentMessage.Status.Should().NotBe(TaskStatus.RanToCompletion); } finally { await closeFunction.Invoke(); } }
public async Task message_handler_sends_message_not_having_contributor_correctly() { // Arrange await ReceiveAndForgetAll(); var messageBus = new MessageBus(); var serializer = new JsonMessageSerializer(); var envelope = new Envelope( messageId: Guid.NewGuid(), message: new Fixture().Create <SomeMessage>(), operationId: $"{Guid.NewGuid()}", correlationId: Guid.NewGuid()); // Act Func <Task> closeFunction = ServiceBusMessageMediator.Start(_connectionStringBuilder, messageBus, serializer); try { await SendMessage(envelope, serializer); // Assert await Task.WhenAny(Task.Delay(TimeSpan.FromMilliseconds(3000)), messageBus.SentMessage); messageBus.SentMessage.Status.Should().Be(TaskStatus.RanToCompletion); Envelope actual = await messageBus.SentMessage; actual.Should().BeEquivalentTo(envelope, opts => opts.RespectingRuntimeTypes()); } finally { await closeFunction.Invoke(); } }