Beispiel #1
0
        public void FetchListOfStatesTest(int expected)
        {
            var stateTaxList = _oops.FetchListOfStates();
            int result       = stateTaxList.Count();

            Assert.AreEqual(expected, result);
        }
Beispiel #2
0
        public void PromptStateFromUser()
        {
            bool   validState = false;
            string stateInput;
            var    listOfStates = _oops.FetchListOfStates();

            do
            {
                do
                {
                    Console.Clear();
                    Console.WriteLine("List of States that we service:");
                    Console.WriteLine("-------------------------------");

                    foreach (var s in listOfStates)
                    {
                        Console.WriteLine(" {0} - ({1}) - {2}%", s.StateAbbreviation, s.StateName, s.TaxRate);
                    }

                    Console.WriteLine();
                    Console.Write("Enter the State Abbreviation of where you're making this order: ");
                    stateInput = Console.ReadLine();
                    Console.WriteLine();

                    if (stateInput == "")
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("You must enter a State Abbreviation.");
                        Console.WriteLine("Press ENTER to continue...");
                        Console.ResetColor();
                        Console.ReadLine();
                    }

                    else if (stateInput.Length != 2)
                    {
                        _errorResponse.ErrorTime         = DateTime.Now;
                        _errorResponse.ErrorSourceMethod = "Add Order Method";
                        _errorResponse.Message           = "State input not 2 letters long.";
                        _errorResponse.Input             = stateInput;
                        _oops.SubmitErrorToLog(_errorResponse);

                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("That is not a state abbreviation.");
                        Console.WriteLine("Press ENTER to continue...");
                        Console.ResetColor();
                        Console.ReadLine();
                        Console.Clear();
                    }
                } while (stateInput.Length != 2);

                var response = _oops.FetchStateTaxInfo(stateInput);

                if (response.Success)
                {
                    _orderInfo.State   = response.StateTaxInfo.StateAbbreviation;
                    _orderInfo.TaxRate = response.StateTaxInfo.TaxRate;
                    Console.WriteLine("You have chosen {0}. It has a Tax Rate of {1}%.",
                                      response.StateTaxInfo.StateName, _orderInfo.TaxRate);
                    Console.WriteLine("Press ENTER to continue...");
                    Console.ReadLine();
                    validState = true;
                }

                else
                {
                    _errorResponse.ErrorTime         = DateTime.Now;
                    _errorResponse.ErrorSourceMethod = "Add Order Method";
                    _errorResponse.Message           = "State input is not in the database.";
                    _errorResponse.Input             = stateInput;
                    _oops.SubmitErrorToLog(_errorResponse);

                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(response.Message);
                    Console.WriteLine("Press ENTER to continue...");
                    Console.ResetColor();
                    Console.ReadLine();
                }
            } while (!validState);
        }