Exemplo n.º 1
0
        public void MultipleProducts_Mocks()
        {
            // Arrange
            var cart = A.Fake <ICart>();

            A.CallTo(() => cart.Products).Returns(new [] {
                new ProductToPurchase {
                    ProductId = 1, Quantity = 1
                },
                new ProductToPurchase {
                    ProductId = 42, Quantity = 7
                },
            });

            IProductCatalog mockProductCatalog = A.Fake <IProductCatalog>();

            A.CallTo(() => mockProductCatalog.LookupPrice(1)).Returns(1m);
            A.CallTo(() => mockProductCatalog.LookupPrice(42)).Returns(1.5m);

            ITaxCalculator mockTaxCalculator = A.Fake <ITaxCalculator>();

            A.CallTo(() => mockTaxCalculator.CalculateTaxes(11.5m)).Returns(1.15m);

            // Act
            var            calculator = new PricingCalculator(mockProductCatalog, mockTaxCalculator);
            PricingSummary price      = calculator.PriceCart(cart);

            // Assert
            Assert.That(price.ProductPrices.Count, Is.EqualTo(2));
            Assert.That(price.SubTotal, Is.EqualTo(11.5m));
            Assert.That(price.Taxes, Is.EqualTo(1.15m));
            Assert.That(price.Total, Is.EqualTo(12.65m));
        }
Exemplo n.º 2
0
        public void T009_CalculateTotalPersonalTax()
        {
            // Given
            int receivedMoney = 100000;
            // int taxCredit = 8000; kwota wolna od podatku
            // int taxLevel = 85528; zmiana progu podatkowego

            // Once again, you may add a TotalPersonalTaxCalculator class and
            // swap old PersonalTax with this new one in the factory.
            // You may note for previous tests it will work like first level tax, but it will let you
            // CHAIN two calculators. Look at Expected and split money appropriately.
            // If you don't know what I want from you, call me when you get here.
            ITaxCalculator calculator = TaxCalculatorFactory.Create(CustomerType.Personal);

            // Expected
            // Money up to 85528: calculated like T002, so: 13955.04. But we have int, so 13955.
            // Money above 85528: 32%. In this case, 4631.04. But we have int, so 4631.
            // TOTAL: 18586
            int expectedTax = 4631;

            // When
            int actualTax = calculator.CalculateTax(receivedMoney);

            // Then
            Assert.AreEqual(expectedTax, actualTax);
        }
Exemplo n.º 3
0
        public Biller GetBiller(string strategy)
        {
            TaxCalculatorFactory factory = new TaxCalculatorFactory();
            ITaxCalculator       taxCal  = factory.GetTaxCalculator(strategy);

            return(new Biller(taxCal));
        }
 public CheckoutService(
     ICart cart,
     ITaxCalculator taxCalculator)
 {
     _cart          = cart;
     _taxCalculator = taxCalculator;
 }
Exemplo n.º 5
0
        public void InitializeTest()
        {
            var mapper        = new AutoMapperSetup().CreateAutoMapperConfig();
            var configuration = new ConfigurationSetup().CreateConfiguration();

            taxCalculator = new TaxCalculatorTaxJarApi(configuration, mapper);
        }
Exemplo n.º 6
0
        public void CreateTaxCalculator(string state = "")
        {
            _state = state;
            //This is mapper function, where you can create the actual Tax Class required for the specific State.
            //We can have a Tax Admin module which can map the concreate tax class with store and store it in a DB.
            //Here you can use Dictionaly and populate the mapping from DB.
            //Dictionary<String, ITaxCalculator> objTaxCalculatorRepo =
            //     new Dictionary<string, ITaxCalculator>();
            //objTaxCalculatorRepo.Add()

            //But for the current demo, I am just using If condition.
            if (_state == "")
            {
                _taxCalculator = new BasicTaxCalculator();
            }
            if (_state == "FL" || _state == "NM" || _state == "NV")
            {
                _taxCalculator = new PreDiscountTaxCalculator();
            }

            if (_state == "IO")  // Let's say Iowa has Item wise tax
            {
                _taxCalculator = new ItemWiseTaxCalculator();
            }
        }
Exemplo n.º 7
0
        public void T011_BusinessHasSubstractions()
        {
            // Given
            int companyMoney = 23000;

            List <Goods> goods = new List <Goods>()
            {
                new Goods(1000, "keyboard"), new Goods(2000, "mouse")
            };

            // Expected
            // Right. So, 23000 - 3000 from 'costs of generating the profits' = 20000
            // Thus, total tax = 0.19 * 20000 = 3800
            int expectedTax = 3800;

            // Yes, you will have to deal with a new method. You will have to pass appropriate parameters
            // to the calculator using the CONSTRUCTOR, because you have no other way of
            // passing without changing the interface of the method - the contract.
            ITaxCalculator calculator = TaxCalculatorFactory.Create(CustomerType.BusinessLinear, goods);

            // When
            int actualTax = calculator.CalculateTax(companyMoney);

            // Then
            Assert.AreEqual(expectedTax, actualTax);
        }
Exemplo n.º 8
0
 public void testInit()
 {
     taxCalculatorObj = new TaxCalculator();
     biller           = new Biller(taxCalculatorObj);
     shoppingCartObj  = new ShoppingCart();
     storeShelf       = new StoreShelf();
 }
        public PriceCalculationService(
            SmartDbContext db,
            IWorkContext workContext,
            IStoreContext storeContext,
            IPriceCalculatorFactory calculatorFactory,
            ITaxCalculator taxCalculator,
            IProductService productService,
            IProductAttributeMaterializer productAttributeMaterializer,
            ITaxService taxService,
            ICurrencyService currencyService,
            CatalogSettings catalogSettings,
            TaxSettings taxSettings)
        {
            _db                           = db;
            _workContext                  = workContext;
            _storeContext                 = storeContext;
            _calculatorFactory            = calculatorFactory;
            _taxCalculator                = taxCalculator;
            _productService               = productService;
            _productAttributeMaterializer = productAttributeMaterializer;
            _taxService                   = taxService;
            _currencyService              = currencyService;
            _catalogSettings              = catalogSettings;
            _taxSettings                  = taxSettings;

            _primaryCurrency = currencyService.PrimaryCurrency;
        }
Exemplo n.º 10
0
 public TaxCalculatorService(IEmployeeRepository employeeRepository, ITaxCalculator calculator, IPayslipGenerator generator, ILogger logger)
 {
     Repository = employeeRepository;
     Calculator = calculator;
     Generator  = generator;
     Logger     = logger;
 }
Exemplo n.º 11
0
        public void CreateAlbertaTaxCalculator()
        {
            var            taxCalculatorFactory = new TaxCalculatorFactory();
            ITaxCalculator result = taxCalculatorFactory.GetTaxCalculator("AB");

            Assert.IsType <AlbertaTaxCalculator>(result);
        }
Exemplo n.º 12
0
        public void Run()
        {
            Console.WriteLine("Podaj typ podatku: [1] liniowy, [2] progresywny");
            var choiceKey = Console.ReadKey();

            ITaxCalculator taxCalculator = null;
            string         taxName       = null;

            switch (choiceKey.KeyChar)
            {
            case '1':
                taxCalculator = new LinearTaxCalculator();
                taxName       = "liniowy";
                break;

            case '2':
                taxCalculator = new ProgressiveTaxCalculator();
                taxName       = "progresywny";
                break;

            default:
                Console.WriteLine(" Nieprawidłowy wybór!");
                break;
            }

            if (taxCalculator != null)
            {
                var    getRevenue = new RevenueGet();
                double revenue    = getRevenue.GetRevenue();
                int    tax        = taxCalculator.CalculateTax(revenue);
                Console.WriteLine("Podatek {0} za rok: {1}", taxName, tax);
            }

            Console.ReadKey();
        }
Exemplo n.º 13
0
        public IActionResult Index(IncomeDetails obj)
        {
            ITaxCalculator t = null;

            switch (obj.Country)
            {
            case "USA":
                t = new TaxCalculatorForUS();
                break;

            case "UK":
                t = new TaxCalculatorForUK();
                break;

            case "IN":
                t = new TaxCalulatorForIN();
                break;
            }
            t.TotalIncome    = obj.TotalIncome;
            t.TotalDeduction = obj.TotalDeduction;
            TaxCalculator cal = new TaxCalculator();

            ViewBag.TotalTax = cal.CalculateTax(t);
            return(View("Index", obj));
        }
Exemplo n.º 14
0
        public void Test2()
        {
            TaxCalculatorFactory taxCalculatorFactory = new TaxCalculatorFactory();
            ITaxCalculator       result = taxCalculatorFactory.GetCalculator("AB");

            Assert.IsType <AlbertaTaxCalculator>(result);
        }
 public OrderTotalsViewComponent(
     SmartDbContext db,
     ITaxService taxService,
     ITaxCalculator taxCalculator,
     ICurrencyService currencyService,
     IGiftCardService giftCardService,
     IShoppingCartService shoppingCartService,
     ILocalizationService localizationService,
     IOrderCalculationService orderCalculationService,
     ShoppingCartSettings shoppingCartSettings,
     MeasureSettings measureSettings,
     TaxSettings taxSettings)
 {
     _db                      = db;
     _taxService              = taxService;
     _taxCalculator           = taxCalculator;
     _currencyService         = currencyService;
     _giftCardService         = giftCardService;
     _shoppingCartService     = shoppingCartService;
     _localizationService     = localizationService;
     _orderCalculationService = orderCalculationService;
     _shoppingCartSettings    = shoppingCartSettings;
     _measureSettings         = measureSettings;
     _taxSettings             = taxSettings;
 }
Exemplo n.º 16
0
 public void RegisterTaxCalculator(string identifier, ITaxCalculator taxCalculator)
 {
     if (!_taxCalculators.ContainsKey(identifier))
     {
         _taxCalculators.Add(identifier, taxCalculator);
     }
 }
Exemplo n.º 17
0
        public ShoppingCart(ISalesPriceCalculator salesPriceCalculator, ITaxCalculator taxCalculator)
        {
            _salesPriceCalculator = salesPriceCalculator;
            _taxCalculator        = taxCalculator;

            Products = new List <Product>();
        }
Exemplo n.º 18
0
        public Cashier GetCashier(String strategy)
        {
            CalculatorFactory factory = new CalculatorFactory();
            ITaxCalculator    taxCal  = factory.GetTaxCalculator(strategy);

            return(new Cashier(taxCal));
        }
Exemplo n.º 19
0
 public OrderProcessor(IGetObjectService <Order> getOrderService,
                       ITaxCalculator taxCalculator, IShippingCalculator shippingCalculator)
 {
     _getOrderService    = getOrderService;
     _taxCalculator      = taxCalculator;
     _shippingCalculator = shippingCalculator;
 }
Exemplo n.º 20
0
        public void TestSpaceshipTaxCalculatorCalculateMethodForCargoShip()
        {
            Spaceship cargoShip = new CargoShip(yearOfPurchase: 2332, milesTraveled: 344789);

            taxCalculator = new SpaceshipTax(cargoShip);
            Assert.AreEqual(expected: 326768.00, taxCalculator.Calculate(yearOfCalculation: 2369));
        }
Exemplo n.º 21
0
 public CustomTaxCalculator(ITaxCalculator defaultTaxCalculator
                            , IContentRepository contentRepository
                            , ReferenceConverter referenceConverter)
 {
     this._defaultTaxCalculator = defaultTaxCalculator;
     this._contentRepository    = contentRepository;
     this._referenceConverter   = referenceConverter;
 }
Exemplo n.º 22
0
        public void T004_SelectTaxCalculatorAsBusinessLinear()
        {
            // When
            ITaxCalculator calculator = TaxCalculatorFactory.Create("linear business");

            // Then
            Assert.IsTrue(calculator is LinearTaxCalculator);
        }
Exemplo n.º 23
0
        public void T003_SelectTaxCalculatorAsPersonal()
        {
            // When
            ITaxCalculator calculator = TaxCalculatorFactory.Create("personal first tax level");

            // Then
            Assert.IsTrue(calculator is PersonalTaxCalculator);
        }
Exemplo n.º 24
0
        static void CalculateTax()
        {
            ITaxCalculator calculator = GetCalculator();
            decimal        salary     = 20000M;
            decimal        tax        = calculator.CalculateTax(salary);

            Console.WriteLine(tax);
        }
 public TaxWorkerListener(ITaxCalculator taxCalculator, INotificationService notificationService)
 {
     _subcribtion = Observable.FromEventPattern <EventHandler <double>, double>(
         h => taxCalculator.TaxesCalculated += h,
         h => taxCalculator.TaxesCalculated -= h)
                    .Select(e => e.EventArgs)
                    .Subscribe(taxInfo => notificationService.CreateNotification("New tax Info", $"Your Tax Return is:{taxInfo}"));
 }
Exemplo n.º 26
0
        public override Result DoWork()
        {
            ITaxCalculator taxCalculator = _app.Container.Resolve(typeof(ITaxCalculator)) as ITaxCalculator;
            double         taxReturn     = taxCalculator.CalculateTaxes(_instanceCount);

            Log($"Your Tax Return is: {taxReturn}");
            return(Result.InvokeSuccess());
        }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            Calculator  clc  = new Calculator();
            ICalculator clc1 = clc;

            clc1.Add();
            ITaxCalculator clcx = clc;
        }
Exemplo n.º 28
0
        void Initialize()
        {
            country = "Local";
            TaxCalculatorFactory factory = new TaxCalculatorFactory();

            taxCal = factory.GetTaxCalculator(country);
            biller = new Biller(taxCal);
        }
Exemplo n.º 29
0
        public TaxController(ILogger <TaxController> logger, ITaxCalculator taxCalculator, IExternalTaxComms externalTaxComms)
        {
            this._logger           = logger;
            this._taxCalculator    = taxCalculator;
            this._externalTaxComms = externalTaxComms;

            Console.Out.WriteLine("taxController created");
        }
Exemplo n.º 30
0
        public void TestSpaceshipTaxCalculatorCalculateMethodForFamilyShip()
        {
            Spaceship familyShip = new FamilyShip(yearOfPurchase: 2300, milesTraveled: 2344);

            taxCalculator = new SpaceshipTax(familyShip);

            Assert.AreEqual(expected: 2715.00, actual: taxCalculator.Calculate(yearOfCalculation: 2307));
        }
Exemplo n.º 31
0
 public virtual decimal GetPriceWithTax(ITaxCalculator calculator)
 {
     decimal price = 0;
     if (calculator != null)
     {
      price = calculator.GetTax(RawPrice) + RawPrice;
     }
     return price;
 }
Exemplo n.º 32
0
        public PricePresenter(IScanner scanner, IPriceDisplay priceDisplay, IProductRepository productRepository, ITaxCalculator taxCalculator)
        {
            m_Scanner = scanner;
            m_ProductRepository = productRepository;
            m_TaxCalculator = taxCalculator;
            m_PriceDisplay = priceDisplay;

            m_Scanner.BarcodeScanned += Scanner_BarcodeScanned;
        }
Exemplo n.º 33
0
        public uint CalculateExemptionForRent(
            Employee        employee,
            ITaxCalculator  ic)
        {
            var taxExemption = ic.calculate(
                                    employee.Property.IsRented,
                                    employee.Property.Location,
                                    employee.AnnualBasicSalary,
                                    employee.Property.MonthlyRent,
                                    employee.AnnualHouseRentAllowance);

            return taxExemption;
        }
 public ValuesController(ITaxCalculator taxCalculator)
 {
     _taxCalculator = taxCalculator;
 }
Exemplo n.º 35
0
 public OrderProcessor(ITaxCalculator taxCalculator, IShippingCalculator shippingCalculator)
 {
     this.taxCalculator = taxCalculator;
     this.shippingCalculator = shippingCalculator;
 }
 public SiteOrderFormCalculator(IShippingCalculator shippingCalculator, ILineItemCalculator lineItemCalculator, ITaxCalculator taxCalculator)
     : base(shippingCalculator, lineItemCalculator, taxCalculator)
 {
     _lineItemCalculator = lineItemCalculator;
 }
Exemplo n.º 37
0
 public Sale3(ITaxCalculator taxCalculator)
 {
     this.taxCalculator = taxCalculator;
 }
Exemplo n.º 38
0
 public frmTaxPayable()
 {
     InitializeComponent();
     _iTaxCalculator = new TaxController();
 }
Exemplo n.º 39
0
 public ProductService(IProductRepository productRepository, ITaxCalculator calculater)
 {
     _calculate = calculater;
     _productRespository = productRepository;
 }
Exemplo n.º 40
0
 public ShoppingBasket(ITaxCalculator taxCalculator, IReceiptBuilder receiptBuilder)
 {
     _taxCalculator = taxCalculator;
     _receiptBuilder = receiptBuilder;
     _itemsAddedToBasket = new List<Item>();
 }
 public SiteOrderGroupCalculator(IOrderFormCalculator orderFormCalculator, IShippingCalculator shippingCalculator, ITaxCalculator taxCalculator)
     : base(orderFormCalculator, shippingCalculator, taxCalculator)
 {
     _shippingCalculator = shippingCalculator;
     _taxCalculator = taxCalculator;
 }