public void GetAllOrdersTest() { // arrange Response response = new Response(); string[] orderCSV; // act response = ops.GetAllOrders(new DateTime(2013, 6, 1)); if (projectMode == "prod") { orderCSV = new string[5]; for (int i = 0; i < response.OrderList.Count; i++) { orderCSV[i] = ops.ToCSVForTesting(response.OrderList[i]); } // assert Assert.AreEqual(editedOrders, orderCSV); } else if (projectMode == "test") { orderCSV = new string[4]; for (int i = 0; i < response.OrderList.Count; i++) { orderCSV[i] = ops.ToCSVForTesting(response.OrderList[i]); } // assert Assert.AreEqual(allOrders, orderCSV); } }
public OrderOperations() { _orderRepository = OrderRepositoryFactory.CreateOrderRepository(); _productsRepository = ProductsRepositoryFactory.CreateProductsRepository(); _statesRepository = StatesRepositoryFactory.CreateStatesRepository(); _response = new Response(); }
public void Execute() { var prompts = new UserPrompts(); var ops = new OrderOperations(); EditOrderPrompts query; var response = new Response(); var slip = new OrderSlip(); bool tryAgain = false; do { tryAgain = false; slip = prompts.GetOrderInfoFromUser(); response = ops.GetOrder(slip.OrderNumber, slip.Date); if (!response.Success) { Console.WriteLine(response.Message); tryAgain = prompts.PromptUserToTryAgain(); } else { query = new EditOrderPrompts(response.Order); var queryResponse = query.EditOrder(); if (queryResponse.Updated) { ops.EditOrder(queryResponse.Order, slip.Date); } DisplayOrderInformation.DisplayEditOrderInfo(queryResponse.Order); } } while (tryAgain); }
public void EditOrderTest(DateTime Date, int OrderNumber, string Name, string State, string ProductType, decimal Area, int IndexOfOrder, int IndexOfEditedOrder, bool expected) { // arrange var response = new Response(); var order = ops.LoadFromCSVForTesting(string.Format("{0},\"{1}\",{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}", OrderNumber, Name, State, 0, ProductType, Area, 0, 0, 0, 0, 0, 0)); // act ops.EditOrder(order, Date); response = ops.GetOrder(OrderNumber, Date); string orderOutput = ops.ToCSVForTesting(response.Order); // assert Assert.AreEqual(expected, response.Success); Assert.AreEqual(editedOrders[IndexOfEditedOrder], orderOutput); }
public Response FetchProductInfo(string ProductType) { var response = new Response(); var productsRepo = new ProductsRepo(); var product = productsRepo.GetProductInfo(ProductType); if (product == null) { response.Success = false; response.Message = "That product is not in our database."; } else { response.Success = true; response.ProductInfo = product; } return response; }
public Response FetchStateTaxInfo(string stateAbbreviation) { var stateTaxRepo = new TaxRepo(); var response = new Response(); var stateTaxInfo = stateTaxRepo.GetStateTaxInfo(stateAbbreviation); if (stateTaxInfo == null) { response.Success = false; response.Message = "That state is not in our database."; } else { response.Success = true; response.StateTaxInfo = stateTaxInfo; } return response; }
public void CreateOrderTest(DateTime date, string CustomerName, string State, string ProductType, decimal Area, int orderIndex) { // arrange var slip = new OrderSlip(); Response response = new Response(); slip.CustomerName = CustomerName; slip.State.StateAbbreviation = State; slip.ProductType.ProductType = ProductType; slip.Area = Area; // act response = ops.CreateOrder(slip); response.Slip.Date = date; ops.WriteNewOrderToRepository(response); string order = ops.ToCSVForTesting(response.Order); // assert Assert.AreEqual(order, createdOrders[orderIndex]); }
public Response GetOrdersFromDate(DateTime orderDate) { var orders = _orderRepo.GetOrdersFromDate(orderDate); var response = new Response(); if (orders == null) { response.Success = false; response.Message = "There are no orders on this date."; } else { response.Success = true; response.OrdersList = orders; } return response; }
public RepositoryOperations() { _statesRepository = StatesRepositoryFactory.CreateStatesRepository(); _productsRepository = ProductsRepositoryFactory.CreateProductsRepository(); _response = new Response(); }
public Response EditOrderToRepo(Order OrderWithEdits) { string filePath = @"DataFiles\Prod\Orders_"; filePath += OrderWithEdits.OrderDate.ToString("MMddyyyy") + ".txt"; var ordersList = GetOrdersFromDate(OrderWithEdits.OrderDate); //find index of order to edit in ordersList int index = ordersList.IndexOf(OrderWithEdits); //use index number to make direct reference type modification var response = new Response(); if (index == -1) { response.Success = false; response.Message = "Failed to find order in system. Internal glitch. Report to admin"; return response; } ordersList[index] = OrderWithEdits; using (var writer = File.CreateText(filePath)) { writer.WriteLine( "OrderNumber,CustomerName,State,TaxRate,ProductType,Area,CostPerSquareFoot,LaborCostPerSquareFoot,MaterialCost,LaborCost,Tax,Total"); foreach (var order in ordersList) { writer.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}", order.OrderNumber, order.CustomerName, order.State, order.TaxRate, order.ProductType, order.Area, order.CostPerSquareFoot, order.LaborCostPerSquareFoot, order.MaterialCost, order.LaborCost, order.Tax, order.Total); } } response.Success = true; response.Message = "Your request has been proceessed."; return response; }
public Response RemoveOrderFromRepo(Order OrderToRemove) { string filePath = @"DataFiles\Prod\Orders_"; filePath += OrderToRemove.OrderDate.ToString("MMddyyyy") + ".txt"; var ordersList = GetOrdersFromDate(OrderToRemove.OrderDate); var newOrdersList = ordersList.Where(o => o.OrderNumber != OrderToRemove.OrderNumber); using (var writer = File.CreateText(filePath)) { writer.WriteLine( "OrderNumber,CustomerName,State,TaxRate,ProductType,Area,CostPerSquareFoot,LaborCostPerSquareFoot,MaterialCost,LaborCost,Tax,Total"); foreach (var order in newOrdersList) { writer.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}", order.OrderNumber, order.CustomerName, order.State, order.TaxRate, order.ProductType, order.Area, order.CostPerSquareFoot, order.LaborCostPerSquareFoot, order.MaterialCost, order.LaborCost, order.Tax, order.Total); } } var response = new Response(); response.Success = true; response.Message = "The order was successfully removed."; return response; }
public void GetOrderInvalidInputsTest(int orderNumber, DateTime date, bool expected) { // arrange Response response = new Response(); // act response = ops.GetOrder(orderNumber, date); // assert Assert.AreEqual(expected, response.Success); }
public void WriteNewOrderToRepository(Response response) { Logger.Info("Writing new order to repo", "OrderOps - WriteNewOrderToRepo"); List<Order> orders = new List<Order>(); if (!_orderRepository.CheckIfRepositoryExists(response.Slip.Date)) { Logger.Info("Repo for this date does not exist, new repo created", "OrderOps - WriteNewOrderToRepo"); response.Order.OrderNumber = 1; orders.Add(response.Order); _orderRepository.OverwriteFile(orders, response.Slip.Date); } else { Logger.Info("Repo for this date exists, add new line to file", "OrderOps - WriteNewOrderToRepo"); response.Order.OrderNumber = NewOrderNumber(response.Slip.Date); _orderRepository.WriteNewLine(response.Order, response.Slip.Date); } }
public void RemoveOrderTest(int orderNumber, bool expected) { // arrange Response response = new Response(); // act ops.RemoveOrder(orderNumber, new DateTime(2013, 6, 1)); response = ops.GetOrder(orderNumber, new DateTime(2013, 6, 1)); // assert Assert.AreEqual(expected, response.Success); }
public void RemoveOrderTest(DateTime Date, int OrderNumber, bool OrderExists, bool IsOrderStillThere) { var response = new Response(); //var order = ops.LoadFromCSVForTesting(string.Format("{0},\"{1}\",{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}", OrderNumber, Name, State, 0, ProductType, Area, 0, 0, 0, 0, 0, 0)); //Check to make sure it exists. response = ops.GetOrder(OrderNumber, Date); Assert.AreEqual(response.Success, OrderExists); //act ops.RemoveOrder(OrderNumber, Date); //Make sure order is no longer there. Return Message should be false. response = ops.GetOrder(OrderNumber, Date); Assert.AreEqual(response.Success, IsOrderStillThere); }
public void GetOrderValidInputsTest(int orderNumber, DateTime date, int indexOfOrdersArray) { // arrange Response response = new Response(); // act response = ops.GetOrder(orderNumber, date); string orderCSV = ops.ToCSVForTesting(response.Order); // assert Assert.AreEqual(orders[indexOfOrdersArray], orderCSV); }
private void GetProductTypeFromUser() { var productResponse = new Response(); do { Console.WriteLine("Enter Product Type - Choose from (C)arpet, (L)aminate, (T)ile or (W)ood."); Console.Write("Current Product Type - {0}. Edit or leave blank and press enter to leave as-is: ", Response.Order.ProductType.ProductType); string productTypeInput = Console.ReadLine().ToUpper(); if (productTypeInput == "") { _isValidInput = true; } else { productResponse = ValidateProductType(productTypeInput); if (Response.Success) { Response.Order.ProductType = productResponse.Product; Response.Updated = true; _isValidInput = true; } } Console.WriteLine(Response.Message); } while (!_isValidInput); _isValidInput = false; }
public Response GetOrderInfo(Order OrderInfo) { var response = new Response(); var order = _orderRepo.GetOrder(OrderInfo); if (order == null) { response.Success = false; response.Message = "That order is not in our database."; } else { response.Success = true; response.Order = order; } return response; }
private void GetStateFromUser() { var stateResponse = new Response(); do { Console.WriteLine("Type the state abbreviation (MI), (OH), (IN) or (PA)."); Console.Write("Current State ({0}). Edit or leave blank and press enter to leave as-is: ", Response.Order.State.StateAbbreviation); string stateInput = Console.ReadLine().ToUpper(); if (stateInput == "") { _isValidInput = true; } else { stateResponse = ValidateState(stateInput); if (stateResponse.Success) { var repoOpsResponse = _repositoryOperations.CheckIfStateExists(stateResponse.State); if (repoOpsResponse.Success) { Response.Order.State = repoOpsResponse.State; Response.Updated = true; _isValidInput = true; } else { Response.Success = false; Response.Message = "That is not a state/province/country/territory we do business in...\n"; } } } Console.WriteLine(Response.Message); } while (!_isValidInput); _isValidInput = false; }
public Response RemoveOrderFromRepo(Order OrderToRemove) { string dictionaryKeyDate = OrderToRemove.OrderDate.ToString("MMddyyyy"); List<Order> ordersComplete = new List<Order>(); _ordersDictionary.TryGetValue(dictionaryKeyDate, out ordersComplete); ordersComplete.RemoveAll(o => o.OrderNumber == OrderToRemove.OrderNumber); var response = new Response(); response.Success = true; response.Message = "The order was successfully removed!!"; return response; }
public ValidateUserInputs() { Response = new Response(); }