Exemplo n.º 1
0
        public void CanPersistOrder()
        {
            IRepository repo = new HibernateRepo();

            try
            {
                repo.BeginTransaction();
                Customer            customer        = repo.First <Customer>(c => c.CustomerId == 1);
                ISalesTaxCalculator salesCalculator = new SalesTaxCalculator();
                Order order = new Order(customer, salesCalculator);
                order.With(new OrderLine(this.GetProduct(repo, 3), 1))
                .With(new OrderLine(this.GetProduct(repo, 4), 12));
                repo.Add <Order>(order);
                repo.SaveChanges();
                repo.CommitTransaction();
            }
            catch (Exception ex)
            {
                repo.Rollback();
                throw ex;
            }
            finally
            {
                repo.Dispose();
            }
        }
Exemplo n.º 2
0
        public void taxes_are_10percent_of_the_price(decimal price, decimal salesTax)
        {
            var exceptions = new List <Type>();
            var actual     = new SalesTaxCalculator(new RoundAndQuantize(), exceptions).CalculateOn(new Item("An item", price));

            actual.Should().Be.EqualTo(salesTax);
        }
Exemplo n.º 3
0
        public virtual void Init()
        {
            _taxProviderMock = new Mock <ITaxRateProvider>();
            _taxProviderMock.Setup(x => x.GetBasicSalesTaxRate()).Returns(0.1m);
            _taxProviderMock.Setup(x => x.GetImportDutySalesTaxRate()).Returns(0.05m);

            _calculator = new BasicSalesTaxCalculator(_taxProviderMock.Object);
        }
Exemplo n.º 4
0
        public void taxes_are_not_applied_to_books()
        {
            var exceptions = new List <Type> {
                typeof(Book)
            };
            var actual = new SalesTaxCalculator(new RoundAndQuantize(), exceptions).CalculateOn(new Book("Q", 100));

            actual.Should().Be.EqualTo(0);
        }
Exemplo n.º 5
0
        public virtual void Init()
        {
            _taxProviderMock = new Mock <ITaxRateProvider>();
            _taxProviderMock.Setup(x => x.GetBasicSalesTaxRate()).Returns(0.1m);
            _taxProviderMock.Setup(x => x.GetImportDutySalesTaxRate()).Returns(0.05m);

            _calculator = new ImportDutySalesTaxCalculator(_taxProviderMock.Object);
            _product    = new Product(ProductType.Book, ".NET book");
        }
Exemplo n.º 6
0
        public void CreateOrder()
        {
            ISalesTaxCalculator salesCalculator = new SalesTaxCalculator();
            Order order = new Order(new Customer("sony", "blr"), salesCalculator);

            Assert.AreNotEqual(order, null, "Order created successfully");
            order.With(new OrderLine(_productCatalogs[0], 1))
            .With(new OrderLine(_productCatalogs[1], 1));
            Assert.AreEqual(28.98, order.GetGrandTotal().Value);
            Assert.AreEqual(1.5, order.GetTotalTax().Value);
        }
Exemplo n.º 7
0
        public virtual void Init()
        {
            _taxProviderMock = new Mock <ITaxRateProvider>();
            _calculator      = new TotalSalesTaxCalculator(new List <SalesTaxCalculator>
            {
                new BasicSalesTaxCalculator(_taxProviderMock.Object),
                new ImportDutySalesTaxCalculator(_taxProviderMock.Object)
            });

            _product = new Product(ProductType.Music, "1 music CD");
        }
        public void SecondExample()
        {
            var receiptDetails = SalesTaxCalculator.Process(
                new Item("Imported box of chocolates", 10m, Category.Food, true),
                new Item("Imported bottle of perfume", 47.50m, true));
            var receiptItems = receiptDetails.ReceiptItems.ToList();

            Assert.That(receiptItems[0].PriceIncludingSalesTax, Is.EqualTo(11.00m));
            Assert.That(receiptItems[1].PriceIncludingSalesTax, Is.EqualTo(59.38m));
            Assert.That(receiptDetails.SalesTax, Is.EqualTo(12.88m));
            Assert.That(receiptDetails.Total, Is.EqualTo(70.38m));
        }
Exemplo n.º 9
0
        public ShoppingCartItem(SalesTaxCalculator salesTaxCalculator, Product product, bool isImported, decimal basePrice)
        {
            if (salesTaxCalculator == null || product == null || basePrice < 0)
            {
                throw new ArgumentException("Shopping Cart Item is invalid");
            }

            _salesTaxCalculator = salesTaxCalculator;
            Product             = product;
            BasePrice           = basePrice;
            IsImported          = isImported;
        }
        public void FirstExample()
        {
            var receiptDetails = SalesTaxCalculator.Process(
                new Item("Magazine", 10.49m, Category.Magazines),
                new Item("Shirt", 34.99m),
                new Item("Package of milk", 0.85m, Category.Food));
            var receiptItems = receiptDetails.ReceiptItems.ToList();

            Assert.That(receiptItems[0].PriceIncludingSalesTax, Is.EqualTo(10.49m));
            Assert.That(receiptItems[1].PriceIncludingSalesTax, Is.EqualTo(40.24m));
            Assert.That(receiptItems[2].PriceIncludingSalesTax, Is.EqualTo(0.85m));
            Assert.That(receiptDetails.SalesTax, Is.EqualTo(5.25m));
            Assert.That(receiptDetails.Total, Is.EqualTo(51.58m));
        }
        public virtual void Init()
        {
            _taxProviderMock = new Mock <ITaxRateProvider>();
            _taxProviderMock.Setup(x => x.GetBasicSalesTaxRate()).Throws(new TaxRateProviderException(It.IsAny <string>(), new Exception()));
            _taxProviderMock.Setup(x => x.GetImportDutySalesTaxRate()).Returns(0.05m);

            _calculator = new TotalSalesTaxCalculator(new List <SalesTaxCalculator>
            {
                new BasicSalesTaxCalculator(_taxProviderMock.Object),
                new ImportDutySalesTaxCalculator(_taxProviderMock.Object)
            });

            _product          = new Product(ProductType.Music, "1 music CD");
            _shoppingCartItem = new ShoppingCartItem(_calculator, _product, false, 14.99m);
        }
        public void ThirdExample()
        {
            var receiptDetails = SalesTaxCalculator.Process(
                new Item("Imported bottle of perfume", 27.99m, true),
                new Item("Bottle of perfume", 18.99m),
                new Item("USB drive", 9.75m, Category.Electronics),
                new Item("Box of imported chocolates", 11.25m, Category.Food, true));
            var receiptItems = receiptDetails.ReceiptItems.ToList();

            Assert.That(receiptItems[0].PriceIncludingSalesTax, Is.EqualTo(34.99m));
            Assert.That(receiptItems[1].PriceIncludingSalesTax, Is.EqualTo(21.84m));
            Assert.That(receiptItems[2].PriceIncludingSalesTax, Is.EqualTo(9.75m));
            Assert.That(receiptItems[3].PriceIncludingSalesTax, Is.EqualTo(12.38m));
            Assert.That(receiptDetails.SalesTax, Is.EqualTo(10.97m));
            Assert.That(receiptDetails.Total, Is.EqualTo(78.95m));
        }
        public void CalculateSalesTax_IsBasicSales_CalculateBasicSalesTax()
        {
            var salesTaxCalculator = new SalesTaxCalculator();

            //Create basic product
            var basicProduct = new Product
            {
                Name        = "bottle of perfume",
                SalePrice   = 10.00m,
                ProductType = ProductType.Other,
            };

            var expected = new ShoppingCartItem();

            expected.SaleTax = 1.00m;

            Assert.AreEqual(expected.SaleTax, salesTaxCalculator.CalculateSalesTax(basicProduct));
        }
        public void CalculateSalesTax_NeitherBasicAndImportedSales_NoTaxCalculated()
        {
            var salesTaxCalculator = new SalesTaxCalculator();

            //Create basic product
            var basicProduct = new Product
            {
                Name        = "bottle of chocolates",
                SalePrice   = 10.00m,
                ProductType = ProductType.Food,
            };


            var expected = new ShoppingCartItem();

            expected.SaleTax = 0.00m;

            Assert.AreEqual(expected.SaleTax, salesTaxCalculator.CalculateSalesTax(basicProduct));
        }
        public void CalculateSalesTax_IsBasicAndImportedSales_CalculateAndSumBothTax()
        {
            var salesTaxCalculator = new SalesTaxCalculator();

            //Create imported product
            var importedProduct = new Product
            {
                Name        = "Imported bottle of perfume",
                SalePrice   = 10.00m,
                ProductType = ProductType.Other,
            };


            var expected = new ShoppingCartItem();

            expected.SaleTax = 1.50m;

            Assert.AreEqual(expected.SaleTax, salesTaxCalculator.CalculateSalesTax(importedProduct));
        }
        public void CalculateSalesTax_IsImportedSales_CalculateImportedSalesTax()
        {
            var salesTaxCalculator = new SalesTaxCalculator();

            //Create imported product
            var importedProduct = new Product
            {
                Name        = "Imported box of chocolates",
                SalePrice   = 10.00m,
                ProductType = ProductType.Food,
            };


            var expected = new ShoppingCartItem();

            expected.SaleTax = 0.50m;

            Assert.AreEqual(expected.SaleTax, salesTaxCalculator.CalculateSalesTax(importedProduct));
        }
Exemplo n.º 17
0
 public StrategyPattern_SalesTaxCalculatorTests()
 {
     _taxCalculator = new SalesTaxCalculator();
     _products      = new List <Product>()
     {
         new Product {
             ProductId = 1, Price = 10000, Name = "Camping Tent", Category = "Sportsware", Description = "Nice Product"
         },
         new Product {
             ProductId = 2, Price = 10500.99, Name = "Used Car", Category = "Auto", Description = "Nice Product"
         },
         new Product {
             ProductId = 3, Price = 100000.11, Name = "New Camper Bus", Category = "Auto", Description = "Nice Product"
         },
         new Product {
             ProductId = 4, Price = 1000000, Name = "New House", Category = "Housing", Description = "Nice Product"
         },
         new Product {
             ProductId = 5, Price = 1000.56, Name = "Game Console", Category = "Entertainment", Description = "Nice Product"
         },
         new Product {
             ProductId = 6, Price = 1500.22, Name = "New Computer", Category = "Electronics", Description = "Nice Product"
         },
         new Product {
             ProductId = 7, Price = 5000, Name = "New Couch", Category = "Home funishing", Description = "Nice Product"
         },
         new Product {
             ProductId = 8, Price = 33000, Name = "New Pickup Truck", Category = "Auto", Description = "Nice Product"
         },
         new Product {
             ProductId = 9, Price = 150000, Name = "Fancy Sports Car", Category = "Auto", Description = "Nice Product"
         },
         new Product {
             ProductId = 10, Price = 200.79, Name = "Real crappy car", Category = "Auto", Description = "Nice Product"
         }
     };
 }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            SalesTaxCalculator tc = new SalesTaxCalculator();

            Console.WriteLine(tc.CalcTotal(1d));
        }
Exemplo n.º 19
0
 public void NegativePriceThrowsError()
 {
     Exception ex = Assert.Throws <Exception>(delegate { SalesTaxCalculator.Process(new Item("Magazine", -10.49m, Category.Magazines)); });
 }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            SalesTaxCalculator server = new SalesTaxCalculator();

            server.Start();
        }