コード例 #1
0
        public async Task FirstAidVideoProcessorHandlesNonProductType()
        {
            AddedItemLineToPurchaseOrder response = new AddedItemLineToPurchaseOrder {
                Added = true
            };
            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(m => m.Send(It.IsAny <AddItemLineToPurchaseOrder>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(response)
            .Verifiable("Does not Send a request to add basic first aid video to purchase order.");


            AcceptingPurchaseOrderItemLine item = new AcceptingPurchaseOrderItemLine
            {
                CustomerId      = 3344656,
                PurchaseOrderId = 4567890,
                Item            = new ItemLineRequest {
                    Description = "Comprehensive First Aid Training", Type = ItemLineType.Membership
                }
            };

            var sut = new FirstAidVideoProcessorService(mockMediator.Object);

            await sut.Handle(item);

            mockMediator.Verify(m => m.Send(It.IsAny <AddItemLineToPurchaseOrder>(), It.IsAny <CancellationToken>()), Times.Never);
        }
コード例 #2
0
        public async Task FirstAidVideoProcessorHandlesFirstAidVideo()
        {
            AddedItemLineToPurchaseOrder response = new AddedItemLineToPurchaseOrder {
                Added = true
            };
            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(m => m.Send(It.IsAny <AddItemLineToPurchaseOrder>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(response)
            .Verifiable("Sends request to add basic first aid video to purchase order.");

            //Task task = new Task();
            mockMediator.Setup(m => m.Publish(It.IsAny <AcceptingPurchaseOrderItemLine>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask)
            .Verifiable("Publishes AcceptingPurchaseOrderItemLine event for added item");


            AcceptingPurchaseOrderItemLine item = new AcceptingPurchaseOrderItemLine
            {
                CustomerId      = 3344656,
                PurchaseOrderId = 4567890,
                Item            = new ItemLineRequest {
                    Description = "Comprehensive First Aid Training", Type = ItemLineType.Product
                }
            };

            var sut = new FirstAidVideoProcessorService(mockMediator.Object);

            await sut.Handle(item);

            mockMediator.Verify(m => m.Send(It.IsAny <AddItemLineToPurchaseOrder>(), It.IsAny <CancellationToken>()), Times.Once);
            mockMediator.Verify(m => m.Publish(It.IsAny <AcceptingPurchaseOrderItemLine>(), It.IsAny <CancellationToken>()), Times.Once);
        }