public void AddToBasketListIfReturnGoodBasket(int x, int y) { //ARRANGE byte[] image = new byte[] { 0x20 }; Product product = new Product() { Name = "ex", Image = new byte[] { 0x20 }, Price = 20 }; ManuallyCode mC = ManuallyCode.GetInstance(); mC.CheckedProduct = product; //ACT Basket basketExpected = new Basket() { Name = product.Name, Image = product.Image, SingleWithoutVatPrice = product.Price, Number = y, Count = x }; Basket basketResult = mC.AddToBasketList(x, y); //ASSERT Assert.IsTrue(basketExpected.Count == basketResult.Count && basketExpected.Number == basketResult.Number && basketExpected.Name == basketResult.Name && basketExpected.Image == basketResult.Image && basketExpected.SingleWithoutVatPrice == basketResult.SingleWithoutVatPrice); }
public void AddToBasketListIfGetCountOrCounterAreLessThenOneAndThrowArgumentException() { //ARRANGE ManuallyCode mC = ManuallyCode.GetInstance(); //ACT //ASSERT Assert.Throws(typeof(ArgumentException), () => mC.AddToBasketList(-1, -1)); }
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; })); }); } } }