//===================================================================== public bool runTest(TestCase aTest) { //map from TestCase to InterfaceToBLL object InterfaceToBLL aCase = new InterfaceToBLL(); aCase.Count_4_6_Gloss_Day = aTest.inputs[0]; aCase.Count_4_6_Gloss_Hour = aTest.inputs[3]; aCase.Count_4_6_Matte_Day = aTest.inputs[6]; aCase.Count_4_6_Matte_Hour = aTest.inputs[9]; aCase.Count_5_7_Gloss_Day = aTest.inputs[1]; aCase.Count_5_7_Gloss_Hour = aTest.inputs[4]; aCase.Count_5_7_Matte_Day = aTest.inputs[7]; aCase.Count_5_7_Matte_Hour = aTest.inputs[10]; aCase.Count_8_10_Gloss_Day = aTest.inputs[2]; aCase.Count_8_10_Gloss_Hour = aTest.inputs[5]; aCase.Count_8_10_Matte_Day = aTest.inputs[8]; aCase.Count_8_10_Matte_Hour = aTest.inputs[11]; aCase.Discount_Code = aTest.discountCode; //process the BLL object. Console.WriteLine("~~~~~~~~~~~~~~~~~~~~ Starting Test ~~~~~~~~~~~~~~~~"); Console.WriteLine("Test id: " + aTest.id); var returnedBLL = new BLL_Final().Calculate(aCase); //now check for the results.. //check total price is equal to expected if (!(returnedBLL.Total_Price == aTest.expectTotalPrice)) { Console.WriteLine("****************Failed Test***************"); Console.WriteLine("Test id: " + aTest.id); Console.WriteLine("Expected final price: " + aTest.expectTotalPrice.ToString("0.00")); Console.WriteLine("Resulted final price: " + returnedBLL.Total_Price); Console.WriteLine("Receipt: " + returnedBLL.Receipt); Console.WriteLine("************** End of Message ************"); return(false); } else { Console.WriteLine("---------------Passed Test----------------"); Console.WriteLine("Test id: " + aTest.id); Console.WriteLine("------------- End of Message--------------"); return(true); } }
private void b_Calculate_Click(object sender, RoutedEventArgs e) { Int32 totalcount = 0; /// Create the object that will be passed to Business Logic BLL.InterfaceToBLL iBLL = new BLL.InterfaceToBLL(); /// Populate business logic iBLL.Count_4_6_Gloss_Day = ValidateInput(t_Count_4_6_Gloss_Day); iBLL.Count_4_6_Gloss_Hour = ValidateInput(t_Count_4_6_Gloss_Hour); iBLL.Count_4_6_Matte_Day = ValidateInput(t_Count_4_6_Matte_Day); iBLL.Count_4_6_Matte_Hour = ValidateInput(t_Count_4_6_Matte_Hour); iBLL.Count_5_7_Gloss_Day = ValidateInput(t_Count_5_7_Gloss_Day); iBLL.Count_5_7_Gloss_Hour = ValidateInput(t_Count_5_7_Gloss_Hour); iBLL.Count_5_7_Matte_Day = ValidateInput(t_Count_5_7_Matte_Day); iBLL.Count_5_7_Matte_Hour = ValidateInput(t_Count_5_7_Matte_Hour); iBLL.Count_8_10_Gloss_Day = ValidateInput(t_Count_8_10_Gloss_Day); iBLL.Count_8_10_Gloss_Hour = ValidateInput(t_Count_8_10_Gloss_Hour); iBLL.Count_8_10_Matte_Day = ValidateInput(t_Count_8_10_Matte_Day); iBLL.Count_8_10_Matte_Hour = ValidateInput(t_Count_8_10_Matte_Hour); iBLL.Discount_Code = t_Discount_Code.Text; totalcount = 0; totalcount = totalcount + iBLL.Count_4_6_Gloss_Day; totalcount = totalcount + iBLL.Count_4_6_Gloss_Hour; totalcount = totalcount + iBLL.Count_4_6_Matte_Day; totalcount = totalcount + iBLL.Count_4_6_Matte_Hour; totalcount = totalcount + iBLL.Count_5_7_Gloss_Day; totalcount = totalcount + iBLL.Count_5_7_Gloss_Hour; totalcount = totalcount + iBLL.Count_5_7_Matte_Day; totalcount = totalcount + iBLL.Count_5_7_Matte_Hour; totalcount = totalcount + iBLL.Count_8_10_Gloss_Day; totalcount = totalcount + iBLL.Count_8_10_Gloss_Hour; totalcount = totalcount + iBLL.Count_8_10_Matte_Day; totalcount = totalcount + iBLL.Count_8_10_Matte_Hour; /// If checked then perform calculations with Debug Version of Business Logic /// if ((totalcount > 0) & (totalcount <= 100)) { if (c_Debug_Mode.IsChecked == true) { BLL.InterfaceToBLL returnIBLL = new BLL.InterfaceToBLL(); BLL.BLL_Debug testBLL = new BLL.BLL_Debug(); try { returnIBLL = testBLL.Calculate(iBLL); t_Receipt_Area.Document = new FlowDocument(); t_Receipt_Area.AppendText(returnIBLL.Receipt); t_Total_Count.Text = returnIBLL.Total_Count.ToString(); t_Total_Price.Text = returnIBLL.Total_Price.ToString(); } catch (Exception ex) { t_log_area.Document = new FlowDocument(); t_log_area.AppendText(ex.Message); } } else { BLL.InterfaceToBLL returnIBLL = new BLL.InterfaceToBLL(); BLL.BLL_Final testBLL = new BLL.BLL_Final(); try { returnIBLL = testBLL.Calculate(iBLL); /// t_Receipt_Area.Document = new FlowDocument(); t_Receipt_Area.AppendText(returnIBLL.Receipt); t_Total_Count.Text = returnIBLL.Total_Count.ToString(); t_Total_Price.Text = returnIBLL.Total_Price.ToString(); } catch (Exception ex) { t_log_area.Document = new FlowDocument(); t_log_area.AppendText(ex.Message); } } } }
//====================================================================================================== public KeyValuePair <decimal, string> applyDiscount(KeyValuePair <decimal, string> tempResult, TempResult got, InterfaceToBLL iBLL) { Decimal upcharge_per_temp; iBLL.Receipt = tempResult.Value; iBLL.Total_Price = tempResult.Key; Decimal tempTotalDiscountCode = 0; Decimal tempTotalOver35 = 0; //---------------------------------------- //Discount Code //---------------------------------------- //iBLL.Total_Discount = (decimal).5; iBLL.Receipt = iBLL.Receipt + "\n" + "----------------------"; iBLL.Receipt = iBLL.Receipt + "\n" + "Checking For Discounts"; iBLL.Receipt = iBLL.Receipt + "\n" + "----------------------"; // check code conditions // charect discount code // homogenous order // max count 100 is required. // James - Bug-7 - convert to upper case iBLL.Discount_Code = iBLL.Discount_Code.ToUpper(); //james Bug-7 if ((iBLL.Discount_Code == "N56M2") & (got.Mode == "Homogeneous") & (got.GrossTotal == 100)) { iBLL.Receipt = iBLL.Receipt + "\n" + "Discount $2: ";// +iBLL.Discount_Code; iBLL.Receipt = iBLL.Receipt + "\n" + "-------- Discount Code: " + iBLL.Discount_Code; iBLL.Receipt = iBLL.Receipt + "\n" + "-------- All Same Type: True"; iBLL.Receipt = iBLL.Receipt + "\n" + "-------- Count = 100: True:: " + got.GrossTotal; tempTotalDiscountCode = 2; iBLL.Receipt = iBLL.Receipt + "\n" + "Potential Discount from Code:: 2$"; } else if (iBLL.Discount_Code.Length > 0) { iBLL.Receipt = iBLL.Receipt + "\n" + "---INVALID Discount Code Requirements--- ";// +iBLL.Discount_Code + " total : " + iBLL.Total_Discount.ToString(); if (iBLL.Discount_Code != "N56M2") { iBLL.Receipt = iBLL.Receipt + "\n" + "INVALID Discount Code Requirements: Invalid Code:: ((" + iBLL.Discount_Code + "))"; } if (got.Mode != "Homogeneous") { iBLL.Receipt = iBLL.Receipt + "\n" + "INVALID Discount Code Requirements: Not Homogeneous Order"; } if (got.GrossTotal < 100) { iBLL.Receipt = iBLL.Receipt + "\n" + "INVALID Discount Code Requirements: Not 100 Count: " + got.GrossTotal.ToString(); } //iBLL.Total_Discount = (decimal)0.0; //iBLL.Receipt = iBLL.Receipt + "\n" + "INVALID Discount Code Requirements: " + iBLL.Discount_Code + " total : " + iBLL.Total_Discount.ToString(); } //---------------------------------------- //Discount > 35$ // check if the 35$ discount applies //---------------------------------------- if ((iBLL.Total_Price > (Decimal)34.0)) { upcharge_per_temp = iBLL.Total_Price * (Decimal).05; tempTotalOver35 = upcharge_per_temp; iBLL.Receipt = iBLL.Receipt + "\n" + "Potential Discount > 35$, 5%:: " + upcharge_per_temp;// +" Total: " + tempTotalOver35; } //--------------- //pick largest discount //between the two options iBLL.Receipt = iBLL.Receipt + "\n" + "---Picking Largest Discount---"; if ((tempTotalDiscountCode == 0) && (tempTotalOver35 == 0)) { iBLL.Total_Price = Math.Round(iBLL.Total_Price, 2, MidpointRounding.AwayFromZero); iBLL.Receipt = iBLL.Receipt + "\n" + "No Discount, Total: " + iBLL.Total_Price; } else if ((tempTotalDiscountCode > tempTotalOver35)) { iBLL.Total_Price = iBLL.Total_Price - tempTotalDiscountCode; iBLL.Total_Price = Math.Round(iBLL.Total_Price, 2, MidpointRounding.AwayFromZero); iBLL.Receipt = iBLL.Receipt + "\n" + "Applying Discount Code Discount: " + tempTotalDiscountCode + " Total Price: " + iBLL.Total_Price; } else if ((tempTotalOver35 >= tempTotalDiscountCode)) { iBLL.Total_Price = iBLL.Total_Price - tempTotalOver35; iBLL.Total_Price = Math.Round(iBLL.Total_Price, 2, MidpointRounding.AwayFromZero); iBLL.Receipt = iBLL.Receipt + "\n" + "Applying Discount 35$, 5%, Discount: " + tempTotalOver35 + " Total Price: " + iBLL.Total_Price; } else { // iBLL.Receipt = iBLL.Receipt + "\n" + "No Discount, Total: " + iBLL.Total_Price; iBLL.Receipt = iBLL.Receipt + "\n" + "wut"; } iBLL.Receipt = iBLL.Receipt + "\n" + "---------------------"; iBLL.Receipt = iBLL.Receipt + "\n" + "Total :: " + iBLL.Total_Price; iBLL.Receipt = iBLL.Receipt + "\n" + "---------------------"; //iBLL.Total_Price = Math.Round(iBLL.Total_Price, 2, MidpointRounding.AwayFromZero); return(new KeyValuePair <decimal, string>(iBLL.Total_Price, iBLL.Receipt)); }