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); }
public async Task ProductItemProcessorDoesNotHandleMembershipItem() { GeneratedShippingLabel response = new GeneratedShippingLabel { LabelGenerated = true }; var mockMediator = new Mock <IMediator>(); mockMediator.Setup(m => m.Send(It.IsAny <GenerateShippingLabel>(), It.IsAny <CancellationToken>())) .ReturnsAsync(response) .Verifiable("Called GenerateShippingLabel for the item"); AcceptingPurchaseOrderItemLine item = new AcceptingPurchaseOrderItemLine { CustomerId = 3344656, PurchaseOrderId = 4567890, Item = new ItemLineRequest { Description = "Book Club Membership", Type = ItemLineType.Membership } }; var sut = new ProductItemProcessorService(mockMediator.Object); await sut.Handle(item); mockMediator.Verify(m => m.Send(It.IsAny <GenerateShippingLabel>(), It.IsAny <CancellationToken>()), Times.Never); }
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); }
public async Task <AcceptedPurchaseOrder> Handle(AcceptPurchaseOrder message) { foreach (var item in message.Items) { AcceptingPurchaseOrderItemLine itemEvent = new AcceptingPurchaseOrderItemLine { CustomerId = message.CustomerId, PurchaseOrderId = message.PurchaseOrderId, Item = item }; await _Mediator.Publish(itemEvent); } return(new AcceptedPurchaseOrder { Accepted = true }); }
public void BookClubServiceActivateMembership() { AcceptingPurchaseOrderItemLine acceptingPurchaseOrderItemLine = new AcceptingPurchaseOrderItemLine { CustomerId = 3344656, Item = new ItemLineRequest { Description = "Book Club Membership", Type = ItemLineType.Membership, Category = ItemLineCategory.Book } }; ActivatedMembership activatedMembership = new ActivatedMembership { Activated = true }; var mockMediator = new Mock <IMediator>(); IBookClubMembershipRepository bookClubMembershipRepository = GetFakeBookClubMembershipRepository(); var sut = new BookClubService(mockMediator.Object, bookClubMembershipRepository); sut.Handle(acceptingPurchaseOrderItemLine); bookClubMembershipRepository.Get(acceptingPurchaseOrderItemLine.CustomerId).ShouldNotBeNull(); }