public void should_add_a_variety_to_a_color_with_its_images_and_price() { var product = _productBuilder.Build(); var productColorOptions = new ProductColorVarietyOptions { ColorType = ColorType.Black, ProductDiscountPercent = 10, ColorImageName = Guid.NewGuid().ToString(), Images = new List <string> { Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }, ProductAmount = 1500000, ProductImageType = ProductImageType.Product }; var productVariety = new ProductColorVariety(productColorOptions); product.AddProductColorVariety(productVariety); product.ProductColorVarieties.Should().HaveCount(1); product.ProductColorVarieties.Should().SatisfyRespectively(first => { first.ProductImageType.Should().Be(productColorOptions.ProductImageType); first.Images.Should().Equal(productColorOptions.Images, (actual, expected) => actual.Name == expected); first.ColorImage.Name.Should().Be(productColorOptions.ColorImageName); first.ColorType.Should().Be(productColorOptions.ColorType); first.ProductPrice.Amount.Value.Should().Be(productColorOptions.ProductAmount); first.ProductPrice.DiscountAmount.Value.Should().Be(150000); first.ProductPrice.DiscountPercent.Should().Be(productColorOptions.ProductDiscountPercent); first.ProductPrice.DueAmount.Value.Should().Be(1350000); }); }
public ProductColorVariety(ProductColorVarietyOptions options) { ColorType = options.ColorType; ColorImage = options.ColorImageName; _images = options.Images.Select(p => new Image(p)).ToList(); ProductImageType = options.ProductImageType; ProductPrice = new ProductPrice(options.ProductAmount, options.ProductDiscountPercent); }
public Product BuildWithAProductVariety(ProductColorVarietyOptions productColorVarietyOptions) { var product = new Product(ProductOptions); var productVariety = new ProductColorVariety(productColorVarietyOptions); product.AddProductColorVariety(productVariety); return(product); }
public void should_throw_when_a_product_amount_is_negative(decimal productAmount, int productDiscountPercent) { var productColorOptions = new ProductColorVarietyOptions { ColorType = ColorType.Black, ProductDiscountPercent = productDiscountPercent, ColorImageName = Guid.NewGuid().ToString(), Images = new List <string> { Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }, ProductAmount = productAmount, ProductImageType = ProductImageType.Product }; Action addProductColor = () => new ProductColorVariety(productColorOptions); addProductColor.Should().Throw <MoneyCannotBeANegativeValueException>(); }
public void should_throw_when_a_product_discount_percent_is_not_valid(int productDiscountPercent) { var productColorOptions = new ProductColorVarietyOptions { ColorType = ColorType.Black, ProductDiscountPercent = productDiscountPercent, ColorImageName = Guid.NewGuid().ToString(), Images = new List <string> { Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }, ProductAmount = 1500, ProductImageType = ProductImageType.Product }; Action addProductColor = () => _productBuilder.BuildWithAProductVariety(productColorOptions); addProductColor.Should().Throw <DiscountPercentInvalidException>(); }
public async Task Handle(CreateProductVarietyCommand command) { var product = await _repository.GetByIdAsync(command.ProductId); var options = new ProductColorVarietyOptions() { ColorImageName = command.ColorImageName, ColorType = (ColorType)command.ColorType, Images = command.Images, ProductAmount = command.ProductAmount, ProductDiscountPercent = command.ProductDiscountPercent, ProductImageType = (ProductImageType)command.ProductImageType }; var productVariety = new ProductColorVariety(options); product.AddProductColorVariety(productVariety); _repository.Update(product); }
public void should_remove_a_product_variety_through_the_its_color() { var productColorOptions = new ProductColorVarietyOptions { ColorType = ColorType.Black, ProductDiscountPercent = 10, ColorImageName = Guid.NewGuid().ToString(), Images = new List <string> { Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }, ProductAmount = 10, ProductImageType = ProductImageType.Product }; var product = _productBuilder.BuildWithAProductVariety(productColorOptions); product.RemoveProductColorVariety(productColorOptions.ColorType); product.ProductColorVarieties.Count.Should().Be(0); }
public void should_throw_when_a_color_already_existed() { var productColorOptions = new ProductColorVarietyOptions { ColorType = ColorType.Black, ProductDiscountPercent = 10, ColorImageName = Guid.NewGuid().ToString(), Images = new List <string> { Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }, ProductAmount = 1500000, ProductImageType = ProductImageType.Product }; var product = _productBuilder.Build(); var productVariety = new ProductColorVariety(productColorOptions); product.AddProductColorVariety(productVariety); Action addProductColor = () => product.AddProductColorVariety(productVariety); addProductColor.Should().Throw <DuplicateProductColorException>(); }