/// <summary> /// Main Program - Entry Point /// </summary> /// <param name="args">Custom arguments passed while executing the exe.</param> public static void Main(string[] args) { // Initialise variables bool isValidInput = true; int inputQuantity = 0; string strInput = null; string[] arrInputParts = null; Dictionary <string, Dictionary <int, double> > dicPacksWithRates = null; SortedDictionary <int, int> dicFinalPackSplit = null; try { // Get the pack rates from data source. dicPacksWithRates = Bakery.DataSetup(); } catch (Exception ex) { // Log the exception that data is missing. throw ex; } try { do { // Reset the valid flag to true. isValidInput = true; // Get the user input. Console.Write("Enter Order Item Required : "); strInput = Console.ReadLine(); // Validate the input given by the user. Bakery.ValidateInput(ref strInput, ref isValidInput, ref inputQuantity, ref arrInputParts, ref dicPacksWithRates); if (isValidInput) { // If input stays valid, then try processing the order. Bakery.ProcessOrder(ref inputQuantity, ref arrInputParts, ref dicPacksWithRates, out dicFinalPackSplit); } // Give a lines space between two user inputs. Console.WriteLine(); }while (!HasProgramEnded(ref strInput)); } catch (Exception ex) { // Log the runtime excepion and handle it. throw ex; } // Show exit message. Console.WriteLine($"Quitting..."); }
public void Test_MB11_14() { // Setup bool isValidInput = true; int inputQuantity = 0; string strInput = "14 MB11"; string[] arrInputParts = null; Dictionary <string, Dictionary <int, double> > dicPacksWithRates = null; SortedDictionary <int, int> dicFinalPackSplitActual = null; SortedDictionary <int, int> dicFinalPackSplitExpected = new SortedDictionary <int, int>(); dicFinalPackSplitExpected.Add(2, 3); dicFinalPackSplitExpected.Add(5, 0); dicFinalPackSplitExpected.Add(8, 1); dicPacksWithRates = Bakery.DataSetup(); // Execute Validation // Validate the input given by the user. Bakery.ValidateInput(ref strInput, ref isValidInput, ref inputQuantity, ref arrInputParts, ref dicPacksWithRates); // Assert Validation Assert.IsTrue(isValidInput); // Execute Order if (isValidInput) { // If input stays valid, then try processing the order. Bakery.ProcessOrder(ref inputQuantity, ref arrInputParts, ref dicPacksWithRates, out dicFinalPackSplitActual); } // Assert Order try { CollectionAssert.AreEqual(dicFinalPackSplitExpected, dicFinalPackSplitActual); } catch (AssertFailedException) { Assert.Fail(); } }