public async Task Deserialize_deserializes_envelope_correctly() { var correlationId = Guid.NewGuid(); var message = fixture.Create <BlogPostCreated>(); var envelope = new Envelope(correlationId, message); BrokeredMessage brokeredMessage = await sut.Serialize(envelope); Envelope actual = await sut.Deserialize(brokeredMessage); actual.ShouldBeEquivalentTo( envelope, opts => opts.RespectingRuntimeTypes()); }
private async Task Process(BrokeredMessage brokeredMessage) { Envelope envelope = null; try { envelope = await _serializer.Deserialize(brokeredMessage).ConfigureAwait(false); await _messageHandler.Handle(envelope, _cancellationToken).ConfigureAwait(false); await brokeredMessage.CompleteAsync().ConfigureAwait(false); } catch (Exception exception) { try { var exceptionContext = envelope == null ? new MessageProcessingExceptionContext <BrokeredMessage>(brokeredMessage, exception) : new MessageProcessingExceptionContext <BrokeredMessage>(brokeredMessage, envelope, exception); await _exceptionHandler.Handle(exceptionContext).ConfigureAwait(false); if (exceptionContext.Handled) { return; } } catch (Exception unhandleable) { Trace.TraceError(unhandleable.ToString()); } throw; } }
public async Task Send_sends_message_correctly() { // Arrange BrokeredMessage received = null; try { var message = fixture.Create <BlogPostCreated>(); var envelope = new Envelope(message); // Act await sut.Send(envelope, CancellationToken.None); // Assert received = await queueClient.ReceiveAsync(TimeSpan.FromSeconds(3)); received.Should().NotBeNull(); Envelope actual = await serializer.Deserialize(received); actual.ShouldBeEquivalentTo(envelope, opts => opts.RespectingRuntimeTypes()); } finally { // Cleanup received?.Complete(); } }