public async Task When_Creates_Product_Order_Then_For_Products_With_Discounts_Applies_Discount(ApplyCharmsToProductOrderResult applyCharmsToProductOrderResult) { // Arrange var productsWithDiscounts = CreateProductsWithDiscounts(); var productWithCharmsOrder = CreateProductsWithCharmsOrderDtos(productsWithDiscounts); var products = Products; var discounts = new List <ProductCategoryDiscount> { ProductCategoryDiscount }; productQueryServiceMock.Setup(x => x.GetRawByIdsAsync(It.IsAny <IList <int> >())).ReturnsAsync(products); productCategoryDiscountQueryServiceMock.Setup(x => x.GetRawActiveAsync()).ReturnsAsync(discounts); productCategoryDiscountQueryServiceMock.Setup(x => x.ApplyDiscountsToProducts(It.IsAny <IList <Product> >(), It.IsAny <IList <ProductCategoryDiscount> >())) .Returns(productsWithDiscounts); productOrderHelperMock.Setup(x => x.ApplyCharmsToProductOrder(It.IsAny <ProductOrder>(), It.IsAny <ProductWithCharmsOrderDto>(), It.IsAny <IList <Charm> >(), It.IsAny <decimal>())).Returns(applyCharmsToProductOrderResult); // Act var result = await sut.CreateAsync(productWithCharmsOrder); // Assert result.Select(x => x.ProductCategoryDiscount).Should().HaveSameCount(productsWithDiscounts.Select(x => x.ProductCategoryDiscount)); }
public async Task When_Creates_Product_Order_Then_For_Products_With_Charms_Applies_Charms(ApplyCharmsToProductOrderResult applyCharmsToProductOrderResult) { // Arrange var productsWithDiscounts = CreateProductsWithDiscounts(); var productWithCharmsOrder = CreateProductsWithCharmsOrderDtos(productsWithDiscounts); var products = Products; var discounts = new List <ProductCategoryDiscount> { ProductCategoryDiscount }; productQueryServiceMock.Setup(x => x.GetRawByIdsAsync(It.IsAny <IList <int> >())).ReturnsAsync(products); productCategoryDiscountQueryServiceMock.Setup(x => x.GetRawActiveAsync()).ReturnsAsync(discounts); productCategoryDiscountQueryServiceMock.Setup(x => x.ApplyDiscountsToProducts(It.IsAny <IList <Product> >(), It.IsAny <IList <ProductCategoryDiscount> >())) .Returns(productsWithDiscounts); productOrderHelperMock.Setup(x => x.ApplyCharmsToProductOrder(It.IsAny <ProductOrder>(), It.IsAny <ProductWithCharmsOrderDto>(), It.IsAny <IList <Charm> >(), It.IsAny <decimal>())).Returns(applyCharmsToProductOrderResult); // Act await sut.CreateAsync(productWithCharmsOrder); // Assert productOrderHelperMock.Verify( x => x.ApplyCharmsToProductOrder( It.IsAny <ProductOrder>(), It.IsAny <ProductWithCharmsOrderDto>(), It.IsAny <IList <Charm> >(), It.IsAny <decimal>()), Times.Exactly(productWithCharmsOrder.Select(x => x.Charms).Count())); }