public void CheckTheCodeIfOneOfParametersIsNull() { //ARRANGE ManuallyCode mC = ManuallyCode.GetInstance(); List <Product> exampleList = new List <Product>(); Product prod1 = new Product(); prod1.Code = "333"; exampleList.Add(prod1); //ACT bool result = mC.CheckTheCode(null, exampleList); bool secondResult = mC.CheckTheCode("333", null); bool expected = false; //ASSERT Assert.AreEqual(expected, result); Assert.AreEqual(expected, secondResult); }
public void CheckTheCodeIfResultIsWrong() { //ARRANGE ManuallyCode mC = ManuallyCode.GetInstance(); List <Product> exampleList = new List <Product>(); Product prod1 = new Product(); prod1.Code = "333"; exampleList.Add(prod1); //ACT bool result = mC.CheckTheCode("444", exampleList); bool expected = false; //ASSERT Assert.AreEqual(expected, result); }
private async void btnManuallyAdd_Click(object sender, RoutedEventArgs e) { tabFromList.IsEnabled = true; string tagForManuDisplCode = "Kod produktu"; string tagForManuDisplQuan = "Ilość"; ManuallyCode manCod = ManuallyCode.GetInstance(); DataHandler data = DataHandler.GetInstance(); Binding myBinding = new Binding(); if (_flagToTagForManuDisp) { string code = txtManuallyCodeEntry.Text.ToString().Trim(); bool checkCode = manCod.CheckTheCode(code, data.Products); if (checkCode) { lblManuallyTagOfCode.Content = tagForManuDisplQuan; txtManuallyCodeEntry.Text = ""; _flagToTagForManuDisp = false; tabFromList.IsEnabled = false; } else { MessageBox.Show("Zły Kod!"); } } else { if (txtManuallyCodeEntry.Text == "0" || txtManuallyCodeEntry.Text == "") { MessageBox.Show("Dodałeś 0 produktów :)"); } else { int getCount = Convert.ToInt32(txtManuallyCodeEntry.Text.Trim()); int counter = listVBasket.Items.Count; counter++; Task taskOne = new Task(delegate { if (counter == 1) { new TransactionManager().PrepareNewTransaction(); } }); taskOne.Start(); Basket basket = manCod.AddToBasketList(getCount, counter); double SumOfPrices = Convert.ToDouble(lblAmountWithoutDiscount.Content.ToString().Trim()); if (_flagToVat) { basket.ChoseOptionPrice = manCod.BasketContainer.TotalPriceWithVat; basket.BeforeDiscount = basket.ChoseOptionPrice; OverwallAmount = (float)Math.Round((SumOfPrices + basket.ChoseOptionPrice), 2); lblAmount.Content = OverwallAmount; lblAmountWithoutDiscount.Content = lblAmount.Content; } else { basket.ChoseOptionPrice = manCod.BasketContainer.TotalPriceWithoutVat; basket.BeforeDiscount = basket.ChoseOptionPrice; OverwallAmount = (float)Math.Round(((float)SumOfPrices + basket.ChoseOptionPrice), 2); lblAmount.Content = OverwallAmount; lblAmountWithoutDiscount.Content = lblAmount.Content; } if (FlagToOverwallDiscount) { bool flagToChar = true; string discountValue = ""; basket.OverwallDiscountName = DiscountWindow.OverwallDiscount; char[] takeDisCount = DiscountWindow.OverwallDiscount.ToCharArray(); foreach (char v in takeDisCount) { if (v == '%') { flagToChar = true; break; } else if (v == 'z') { flagToChar = false; break; } discountValue = discountValue + v; } double percent = (100 - Convert.ToDouble(discountValue)) * 0.01; if (flagToChar) { DiscountWindow.OverwallAmountWithDiscount = (float)Math.Round((OverwallAmount * percent), 2); lblAmountWithoutDiscount.Content = OverwallAmount; lblAmount.Content = DiscountWindow.OverwallAmountWithDiscount; } else if (!flagToChar) { DiscountWindow.OverwallAmountWithDiscount = (float)(OverwallAmount - Convert.ToDouble(discountValue)); lblAmountWithoutDiscount.Content = OverwallAmount; lblAmount.Content = DiscountWindow.OverwallAmountWithDiscount; } } else { basket.DiscountValue = 0; } ListOfBoughtItems.Add(basket); listVBasket.Items.Add(basket); btnVat.IsEnabled = false; lblManuallyTagOfCode.Content = tagForManuDisplCode; _flagToTagForManuDisp = true; txtManuallyCodeEntry.Text = ""; await taskOne.ContinueWith(_ => { Dispatcher.BeginInvoke(new Action(delegate { lblTransactionNumber.Content = data.Transaction.Id; })); }); } } }