private List<TaxEntry> CreateListOfTaxEntries(Customer customer)
 {
     List<TaxEntry> listOfTaxEntries = (List<TaxEntry>) _taxRateService.GetTaxEntries(
         customer.PostalCode,
         customer.Country);
     return listOfTaxEntries;
 }
        public void BeforeEach()
        {
            _productRepo = Substitute.For<IProductRepository>();
            _orderFulfillmentService = Substitute.For<IOrderFulfillmentService>();
            _customerRepository = Substitute.For<ICustomerRepository>();
            _taxRateService = Substitute.For<ITaxRateService>();
            _emailService = Substitute.For<IEmailService>();

            _subject = new OrderService(_orderFulfillmentService,
                _customerRepository,
                _taxRateService,
                _emailService);

            _bestCustomer = new Customer
            {
                CustomerId = 42,
                PostalCode = "12345",
                Country = "Merica"
            };

            _listOfTaxEntries = new List<TaxEntry>
            {
                new TaxEntry {Description = "High Tax", Rate = (decimal) 0.60},
                new TaxEntry {Description = "Low Tax", Rate = (decimal) 0.10}
            };

            _orderConfirmation = new OrderConfirmation
            {
                OrderId = 1234,
                OrderNumber = "hello"
            };
            _customerRepository.Get(_bestCustomer.CustomerId.Value).Returns(_bestCustomer);
            _taxRateService.GetTaxEntries(_bestCustomer.PostalCode, _bestCustomer.Country).Returns(_listOfTaxEntries);
        }
 private IEnumerable<TaxEntry> RetrieveTaxEntries(Customer customer)
 {
     String customerPostalCode = customer.PostalCode;
     String customerCountry = customer.Country;
     List<TaxEntry> taxes = _taxRateService.GetTaxEntries(customerPostalCode, customerCountry).ToList();
     return taxes;
 }
        public void PlaceOrder_OrderIsValid_OrderSummaryContainsOrderTotal()
        {
            // Arrange
            var customer = new Customer { CustomerId = 1 };
            var taxRate1 = 1.5;
            var taxRate2 = 2.5;
            var netTotal = 6.50;

            _customerRepository.Stub(c => c.Get(Arg<int>.Is.Anything)).Return(customer);
            _orderFulfillmentService.Stub(or => or.Fulfill(Arg<Order>.Is.Anything)).Return(new OrderConfirmation());
            _productRepository.Stub(pr => pr.IsInStock(Arg<string>.Is.Anything)).Return(true);
            _taxRateService.Stub(t => t.GetTaxEntries(customer.PostalCode, customer.Country))
                .Return(new List<TaxEntry>
                {
                    new TaxEntry {Rate = (decimal) taxRate1},
                    new TaxEntry {Rate = (decimal) taxRate2},
                });

            var orderService = new OrderService(_productRepository, _orderFulfillmentService, _emailService, _customerRepository, _taxRateService);

            var order = new Order
            {
                CustomerId = 1,
                OrderItems = new List<OrderItem>
                {
                    new OrderItem
                    {
                        Product = new Product { Sku = "apple", Price = (decimal) 2.00},
                        Quantity = 2
                    },
                    new OrderItem
                    {
                        Product = new Product { Sku = "apple2", Price = (decimal) 2.50 },
                        Quantity = 1
                    }
                }
            };
            var expectedOrderTotal = netTotal * taxRate1 + netTotal * taxRate2;

            // Act
            var result = orderService.PlaceOrder(order);

            // Assert
            Assert.AreEqual(expectedOrderTotal, result.Total);
        }
        public void PlaceOrder_OrderIsValid_OrderSummaryContainsApplicableTaxes()
        {
            // Arrange
            var expectedCustomerId = 1;
            var customer = new Customer{ CustomerId = expectedCustomerId};

            _customerRepository.Stub(c => c.Get(Arg<int>.Is.Anything)).Return(customer);
            _productRepository.Stub(pr => pr.IsInStock(Arg<string>.Is.Anything)).Return(true);
            _orderFulfillmentService.Stub(or => _orderFulfillmentService.Fulfill(Arg<Order>.Is.Anything))
                .Return(new OrderConfirmation());
            _taxRateService.Stub(t => t.GetTaxEntries(customer.PostalCode, customer.Country))
                .Return(new List<TaxEntry> {new TaxEntry {Description = "USA"} });

            var orderService = new OrderService(_productRepository, _orderFulfillmentService, _emailService, _customerRepository, _taxRateService);

            var order = new Order
            {
                CustomerId = expectedCustomerId,
                OrderItems = new List<OrderItem>
                {
                    new OrderItem { Product = new Product { Sku = "apple" } },
                    new OrderItem { Product = new Product { Sku = "apple2" } }
                }
            };

            // Act
            var result = orderService.PlaceOrder(order);

            // Assert
            Assert.That(result.Taxes.ToList().Exists(tax => tax.Description == "USA"));
        }