public static OrderManager Create() { string mode = ConfigurationManager.AppSettings["Mode"].ToString(); IOrderRepository orderRepository; ITaxRepository taxRepository; IProductRepository productRepository; switch (mode) { case "Test": orderRepository = new TestOrderRepository(); taxRepository = new TestTaxRepository(); productRepository = new TestProductRepository(); return(new OrderManager(orderRepository, taxRepository, productRepository)); case "Production": orderRepository = new FileOrderRepository(); taxRepository = new TaxRepository(); productRepository = new ProductRepository(); return(new OrderManager(orderRepository, taxRepository, productRepository)); default: throw new Exception("Mode value in app config is not valid"); } }
public void OrderManagerAddOrderTest(DateTime date, string customerName, string state, string productType, decimal area, bool expectedResult, int expectedCount) { TestOrderRepository testOrderRepo = new TestOrderRepository(); TestProductRepository testProductRepo = new TestProductRepository(); TestTaxRepository testTaxRepo = new TestTaxRepository(); OrderManager addOrderRule = new OrderManager(testOrderRepo, testProductRepo, testTaxRepo); AddOrderResponse response = addOrderRule.BuildNewOrder(date, customerName, state, productType, area); //Order order = new Order(); //order.Date = date; //order.OrderNumber = orderNumber; //order.CustomerName = customerName; //order.State = state; //order.TaxRate = taxRate; //order.ProductType = productType; //order.Area = area; //order.CostPerSquareFoot = costPerSqFt; //order.LaborCostPerSquareFoot = laborCostPerSqFt; Assert.AreEqual(expectedResult, response.Success); if (response.Success) { testOrderRepo.CommitThisOrder(response.Order); Assert.AreEqual(expectedCount, testOrderRepo.GetAllOrdersForDate(date).Count); } }
public void ProductRepoShouldFailOnIncorrectLaborCost(string productType, decimal laborCost) { IProductRepository productRepository = new TestProductRepository(); Product product = productRepository.GetProduct(productType); Assert.AreNotEqual(laborCost, product.LaborCostPerSquareFoot); }
public void ProductRepoShouldReturnCorrectProductData(string expectedProductType, decimal expectedMaterialCost, decimal expectedLaborCost) { IProductRepository productRepository = new TestProductRepository(); Product product = productRepository.GetProduct(expectedProductType); Assert.AreEqual(expectedProductType, product.ProductType); Assert.AreEqual(expectedMaterialCost, product.CostPerSquareFoot); Assert.AreEqual(expectedLaborCost, product.LaborCostPerSquareFoot); }
static void Main(string[] args) { var productRepository = new TestProductRepository(); // Create the product service using the repository var productService = new ProductService(productRepository); //Create the Basket using the appropriate product service var myBusket = new Basket(productService); //Put some dummy products in the Basket myBusket.Products = productService.GetProducts(); WriteLine($"Discounted amount: {myBusket.DiscountAmount()}"); }
public static void TestAllProducts() { //Create the product repository to use var productRepository = new TestProductRepository(); // Create the product service using the repository var productService = new ProductService(productRepository); //Create the Basket using the appropriate product service var myBusket = new Basket(productService); //Add all dummy products in the Basket myBusket.Products = productService.GetProducts(); Assert.AreEqual(myBusket.TotalAmount(), 30); Assert.AreEqual(myBusket.DiscountAmount(), 5); Assert.AreEqual(myBusket.FinalAmount(), 25); }
public static void TestProducts2() { //Create the product repository to use var productRepository = new TestProductRepository(); // Create the product service using the repository var productService = new ProductService(productRepository); //Create the Basket using the appropriate product service var myBusket = new Basket(productService); //Add one more with id 3 in the Basket var testProducts = productService.GetProducts(); myBusket.Products = new List <IProduct> { testProducts.First(p => p.Id == 1), testProducts.First(p => p.Id == 2), testProducts.First(p => p.Id == 3), testProducts.First(p => p.Id == 3), }; Assert.AreEqual(myBusket.FinalAmount(), 25); }
public static FlooringProgramManager CreateFlooringProgramManager(string modeChoice) { if (modeChoice == "TEST") { IClient testClientRepo = new TestClientRepository(); IOrderRepository testOrderRepo = new TestOrderRepository(); IProducts testProdRepo = new TestProductRepository(); ITaxRate testTaxRepo = new TestTaxRepository(); return(new FlooringProgramManager(testClientRepo, testOrderRepo, testProdRepo, testTaxRepo)); } else { IClient clientRepo = new ClientRepository(); IOrderRepository orderRepo = new OrderRepository(); IProducts prodRepo = new ProductRepository(); ITaxRate taxRepo = new TaxRepository(); return(new FlooringProgramManager(clientRepo, orderRepo, prodRepo, taxRepo)); } }
public void ProductRepoShouldFailOnUnknownProduct(string productType) { IProductRepository productRepository = new TestProductRepository(); Assert.IsNull(productRepository.GetProduct(productType)); }