public async Task Handle_WhenGetInvoiceMessage_ShouldReplyWithInvoice()
        {
            // Arrange
            var invoice  = string.Empty;
            var clientId = "test_client_id";

            var equipmentRepository = Substitute.For <IEquipmentRepository>();
            var getInvoiceMessage   = new GetInvoiceCommand
            {
                ClientId   = clientId,
                OrderItems = new List <OrderItem>()
            };

            var handler = new GetInvoiceCommandHandler(equipmentRepository);
            var context = new TestableMessageHandlerContext();

            var expectedInvoiceGeneratedMessage = new InvoiceGeneratedMessage
            {
                ClientId = clientId,
                Invoice  = invoice
            };

            // Act
            await handler.Handle(getInvoiceMessage, context);

            // Assert
            context.RepliedMessages.Length.Should().Be(1);
            context.RepliedMessages[0].Message.Should().BeEquivalentTo(expectedInvoiceGeneratedMessage);
        }
Example #2
0
        public async Task Handle(GetInvoiceCommand command, IMessageHandlerContext context)
        {
            Log.Info($"Billing has received GetInvoiceMessage, ClientId = {command.ClientId}");

            Invoice invoice        = _billingService.GenerateInvoice(command.OrderItems);
            var     invoiceMessage = new InvoiceGeneratedMessage
            {
                ClientId = command.ClientId,
                Invoice  = invoice.ToString()
            };

            await context.Reply(invoiceMessage);

            Log.Info($"Billing has replied to the calling endpoint with InvoiceGeneratedMessage, ClientId = {command.ClientId}");
        }