public static void CanCheckRepoForState(string stateAbbreviation, bool expectedResult) { Manager manager = new Manager(new InMemoryOrderRepo(), new InMemoryMaterialRepo(), new InMemoryTaxRepo()); InMemoryTaxRepo repo = new InMemoryTaxRepo(); var stateTaxData = repo.GetStateTaxes(); CheckStateResponse response = manager.CheckForRequestedState(stateAbbreviation); Assert.AreEqual(expectedResult, response.Success); }
private static StateTax EditState(StateTax oldStateTax) { Manager manager = ManagerFactory.Create(); StateTax stateTax = oldStateTax; bool validInput = false; string userInput = ""; while (!validInput) { Console.Clear(); Console.Write($"Please enter a state abbreviation, or press enter to keep ({oldStateTax.StateAbbreviation}) as the order state: "); userInput = Console.ReadLine(); if (userInput == "") { validInput = true; } else { CheckStateResponse response = manager.CheckForRequestedState(userInput); if (response.Success) { validInput = true; stateTax = response.Tax; } else { Console.WriteLine(response.Message); Console.Write("Press any key to retry..."); Console.ReadKey(); } } } return(stateTax); }
public CheckStateResponse CheckForRequestedState(string stateAbbreviation) { CheckStateResponse response = new CheckStateResponse(); try { if (_taxRepo.GetStateTaxes().Any(t => t.StateAbbreviation == stateAbbreviation)) { response.Success = true; response.Tax = _taxRepo.GetStateTaxes().Single(t => t.StateAbbreviation == stateAbbreviation); } else { response.Success = false; response.Message = "Error: currently, we cannot take orders for the requested state."; } } catch (Exception e) { response.Success = false; response.Message = "Error: failed to load the State Tax repository. Please contact IT.\n" + $"({e.Message})"; } return(response); }
private static StateTax GetTax(Manager manager) { bool validState = false; StateTax tax = null; GetStatesResponse stateTaxesResponse = manager.GetStates(); if (stateTaxesResponse.Success) { while (!validState) { Console.Clear(); ConsoleIO.TitleHeader("Add an Order"); Console.WriteLine("(Step 3 of 5)\n"); ConsoleIO.PrintStateTaxInfo(stateTaxesResponse.StateTaxes); string stateAbbreviation = ConsoleIO.GetStateFromUser(); CheckStateResponse stateResponse = manager.CheckForRequestedState(stateAbbreviation); validState = stateResponse.Success; if (!validState) { Console.Clear(); Console.WriteLine(stateResponse.Message); Console.Write("Press any key to continue..."); Console.ReadKey(); } else { tax = stateResponse.Tax; } } } else { Console.WriteLine(stateTaxesResponse.Message); } return(tax); }