Exemplo n.º 1
0
        public void GetTaxableProductDecorator_FlatTax_FlatTaxDecorator()
        {
            //Arrange
            IProduct product = new Product(1, 1, "1 imported book", "book", true, CategoryType.Books);

            //Act
            ProductDecorator productDecorator = _flatTax.GetTaxableProductDecorator(product);

            //Assert
            Assert.AreEqual("1 imported book, Basic Sales Tax", productDecorator.GetDescription());
            Assert.IsInstanceOf <FlatTaxDecorator>(productDecorator);
        }
    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    {
        ProductDecorator tmpEntity = (ProductDecorator)validationContext.ObjectInstance;
        var tmpCollection          = (ObservableCollection <ProductUmDecorator>)value;

        if (tmpCollection.Count == 0)
        {
            return(ValidationResult.Success);
        }
        foreach (var item in tmpCollection)
        {
            if (item.IsSelected == true)
            {
                return(ValidationResult.Success);
            }
        }
        return(new ValidationResult(ErrorMessage));
    }
        public IList<TaxedProduct> ApplyTaxes(ShoppingBasket shoppingBasket)
        {
            if (shoppingBasket == null) throw new ArgumentNullException(nameof(shoppingBasket));

            IList<TaxedProduct> taxedProducts = new List<TaxedProduct>();
            for (var i = 0; i < shoppingBasket.Products.Count; i++)
            {
                IProduct product = shoppingBasket.Products[i];
                foreach (Tax taxRule in _taxRules)
                {
                    if (taxRule.IsApplicableFor(product))
                    {
                        ProductDecorator productDecorator = taxRule.GetTaxableProductDecorator(product);
                        product = productDecorator;
                    }
                }
                decimal grossAmount = product.CalculateGrossAmount();
                taxedProducts.Add(new TaxedProduct(product, grossAmount));
            }
            return taxedProducts;
        }