Exemplo n.º 1
0
        public PricingSummary PriceCart(ICart cart)
        {
            var productTotals = (from p in cart.Products
                                 let price = catalog.LookupPrice(p.ProductId)
                                             where price != -1m
                                             select new { ProductId = p.ProductId, Price = price, Quantity = p.Quantity })
                                .ToDictionary(p => p.ProductId, p => p.Price * p.Quantity);
            var subTotal = productTotals.Values.Sum();

            return(new PricingSummary
            {
                ProductPrices = productTotals,
                SubTotal = subTotal,
                Taxes = taxCalculator.CalculateTaxes(subTotal),
            });
        }
Exemplo n.º 2
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.º 3
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.º 4
0
        public async Task <ActionResult <decimal> > CalculateTax([FromBody] Order myOrder)
        {
            if (string.IsNullOrEmpty(myOrder.from_country))
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "From country is required."));
            }
            if (string.IsNullOrEmpty(myOrder.from_state))
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "From state is required."));
            }
            if (string.IsNullOrEmpty(myOrder.from_zip))
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "From zip is required."));
            }

            decimal taxAmount = await _taxCalculator.CalculateTaxes(myOrder);

            return(Ok(taxAmount));
        }