private List <ProductWithCharmsOrderDto> PrepareTest_ProductWithCharmOrderDto(IList <Guid> charmIds) { var productWithCharmsOrderDtos = new List <ProductWithCharmsOrderDto>(); var count = 1; var timesOfLoop = (int)charmIds.Count / 3; for (int i = 0; i < timesOfLoop; i++) { var productWithCharmOrderDto = new ProductWithCharmsOrderDto { ProductId = i + 1, Charms = new List <CharmOrderDto>() }; foreach (var charmId in charmIds) { if (count <= 3) { productWithCharmOrderDto.Charms.Add(new CharmOrderDto { CharmId = charmId, Sequence = count }); count++; } else { count = 1; break; } } productWithCharmsOrderDtos.Add(productWithCharmOrderDto); } return(productWithCharmsOrderDtos); }
public void When_Applies_Charms_To_Product_Order_And_Product_Does_Not_Accepts_Charms_Then_Throws_Streetwood_Exception( ProductWithCharmsOrderDto productWithCharmsOrder, IList <Charm> charms, decimal finalPrice) { // Arrange var productOrder = ProductOrder; productOrder.Product.SetAcceptCharms(false); // Act Action action = () => sut.ApplyCharmsToProductOrder(productOrder, productWithCharmsOrder, charms, finalPrice); // Assert action.Should().Throw <StreetwoodException>(); }
public void When_Applies_Charms_To_Product_Order_Then_Creates_Product_Order_Charms_With_Helper( ProductWithCharmsOrderDto productWithCharmsOrder, IList <Charm> charms, decimal finalPrice, IList <ProductOrderCharm> productOrderCharms) { // Arrange ProductOrder.Product.SetAcceptCharms(true); productOrderCharmsHelperMock .Setup(x => x.CreateProductOrderCharms(It.IsAny <IEnumerable <CharmOrderDto> >(), It.IsAny <IList <Charm> >())) .Returns(productOrderCharms); // Act sut.ApplyCharmsToProductOrder(ProductOrder, productWithCharmsOrder, charms, finalPrice); // Assert productOrderCharmsHelperMock.Verify(x => x.CreateProductOrderCharms(productWithCharmsOrder.Charms, charms), Times.Once); }
public void When_Applies_Charms_To_Product_Order_Then_Returns_Correct_Final_Price( ProductWithCharmsOrderDto productWithCharmsOrder, IList <Charm> charms, decimal finalPrice, IList <ProductOrderCharm> productOrderCharms) { // Arrange ProductOrder.Product.SetAcceptCharms(true); ProductOrder.AddProductCategoryDiscount(null); productOrderCharmsHelperMock .Setup(x => x.CreateProductOrderCharms(It.IsAny <IEnumerable <CharmOrderDto> >(), It.IsAny <IList <Charm> >())) .Returns(productOrderCharms); var expected = finalPrice + productOrderCharms.Sum(x => x.CurrentPrice) - productOrderCharms.First().CurrentPrice; // Act var result = sut.ApplyCharmsToProductOrder(ProductOrder, productWithCharmsOrder, charms, finalPrice); // Assert result.Should().NotBeNull(); result.FinalPrice.Should().Be(expected); }
public void When_Applies_Charms_To_Product_Order_Then_Adds_Product_Order_Charms_To_Product_Order( ProductWithCharmsOrderDto productWithCharmsOrder, IList <Charm> charms, decimal finalPrice, IList <ProductOrderCharm> productOrderCharms) { // Arrange ProductOrder.Product.SetAcceptCharms(true); productOrderCharmsHelperMock .Setup(x => x.CreateProductOrderCharms(It.IsAny <IEnumerable <CharmOrderDto> >(), It.IsAny <IList <Charm> >())) .Returns(productOrderCharms); // Act var result = sut.ApplyCharmsToProductOrder(ProductOrder, productWithCharmsOrder, charms, finalPrice); // Assert result.Should().NotBeNull(); result.ProductOrder.ProductOrderCharms.Should().NotBeEmpty(); result.ProductOrder.ProductOrderCharms.Should().BeEquivalentTo(productOrderCharms); }
public ApplyCharmsToProductOrderResult ApplyCharmsToProductOrder( ProductOrder productOrder, ProductWithCharmsOrderDto productWithCharmsOrder, IList <Charm> charms, decimal finalPrice) { if (!productOrder.Product.AcceptCharms) { throw new StreetwoodException(ErrorCode.ProductNotAcceptCharms); } var productOrderCharms = productOrderCharmsHelper.CreateProductOrderCharms(productWithCharmsOrder.Charms, charms); productOrder.AddProductOrderCharms(productOrderCharms); var charmsPrice = productOrderCharms.Sum(x => x.CurrentPrice); // we subtract one charm, because first is for free charmsPrice -= productOrderCharms.First().CurrentPrice; finalPrice += charmsPrice; productOrder.SetCharmsPrice(charmsPrice); return(new ApplyCharmsToProductOrderResult(productOrder, finalPrice)); }