示例#1
0
        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);
        }
示例#2
0
        public void AddToBasketListIfGetCountOrCounterAreLessThenOneAndThrowArgumentException()
        {
            //ARRANGE
            ManuallyCode mC = ManuallyCode.GetInstance();

            //ACT

            //ASSERT
            Assert.Throws(typeof(ArgumentException), () => mC.AddToBasketList(-1, -1));
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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;
                        }));
                    });
                }
            }
        }