예제 #1
0
        public async Task OrderProcessorHandlesAcceptPurchaseOrder()
        {
            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(m => m.Publish(It.IsAny <AcceptingPurchaseOrderItemLine>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask)
            .Verifiable("Called for each item line");

            AcceptPurchaseOrder command = new AcceptPurchaseOrder
            {
                CustomerId      = 3344656,
                PurchaseOrderId = 4567890,
                Items           = new List <ItemLineRequest>
                {
                    new ItemLineRequest {
                        Description = "Comprehensive First Aid Training", Type = ItemLineType.Product
                    },
                    new ItemLineRequest {
                        Description = "The Girl on the Train", Type = ItemLineType.Product
                    },
                    new ItemLineRequest {
                        Description = "Book Clum Membership", Type = ItemLineType.Membership
                    }
                }
            };
            AcceptedPurchaseOrder reply;

            OrderProcessorService sut = new OrderProcessorService(mockMediator.Object);

            reply = await sut.Handle(command);

            reply.Accepted.ShouldBeTrue();
            mockMediator.Verify(m => m.Publish(It.IsAny <AcceptingPurchaseOrderItemLine>(), It.IsAny <CancellationToken>()), Times.Exactly(command.Items.Count()));
        }
예제 #2
0
        public async Task Accept()
        {
            AcceptPurchaseOrder acceptPurchase = new AcceptPurchaseOrder
            {
                CustomerId      = CustomerId,
                PurchaseOrderId = Id,
                Items           = ItemLines.Select(il => new ItemLineRequest {
                    Description = il.Description, Type = il.Type
                }).ToList()
            };
            AcceptedPurchaseOrder response = await _Mediator.Send(acceptPurchase);

            Accepted = response.Accepted;
            if (response.Accepted)
            {
                ProcessedPurchaseOrder processedPurchaseOrder = new ProcessedPurchaseOrder
                {
                    CustomerId      = CustomerId,
                    PurchaseOrderId = Id,
                    Items           = ItemLines.Select(il => new ItemLineRequest {
                        Description = il.Description, Type = il.Type
                    }).ToList()
                };
                await _Mediator.Publish(processedPurchaseOrder);
            }
        }