public void GetTotalPriceTest()
        {
            //Arrange
            var cart     = new ProductCartService();
            var ProductA = new GetTotalPrice {
            };
            var ProductB = new GetTotalPrice {
            };
            var ProductC = new GetTotalPrice {
            };
            var ProductD = new GetTotalPrice {
            };

            // Act
            cart.Add(ProductA);
            cart.Add(ProductB);
            cart.Add(ProductC);
            cart.Add(ProductD);
            // Assert
            Assert.AreEqual(2, cart.Items[0].Quantity);
        }
예제 #2
0
        public override void PaymentMethod()
        {
            Console.WriteLine("Your amount is: " + GetTotalPrice.CalculateFinalCost());
            try
            {
                do
                {
                    Console.WriteLine("Please enter card pin below: ");
                    CardNumber = int.Parse(Console.ReadLine());
                } while (cardNumber.ToString().Length < cardNumberlength || cardNumber.ToString().Length > cardNumberlength);

                Console.WriteLine(" Please enter your pin Number");
                UserCardPin = int.Parse(Console.ReadLine());

                Console.WriteLine("Thank you payment has been successful");
            }
            catch (Exception error)
            {
                Console.WriteLine(error.Message);
            }
        }
예제 #3
0
 public override void PaymentMethod()
 {
     Console.WriteLine("Please enter the amount of cash given below");
     getCash = double.Parse(Console.ReadLine());
     if (getCash == GetTotalPrice.CalculateFinalCost())
     {
         Console.WriteLine("Thanks for the payment.");
     }
     else if (getCash > GetTotalPrice.CalculateFinalCost())
     {
         change = GetTotalPrice.CalculateFinalCost() - getCash;
         Console.WriteLine("Your Change is: " + change);
     }
     else if (getCash < GetTotalPrice.CalculateFinalCost())
     {
         Console.WriteLine("You need more cash!!!");
     }
     else
     {
         Console.WriteLine("Invalid Input");
     }
 }
예제 #4
0
        public void ShowReceipt()
        {
            recieptGrid.ShowGridLines = false;
            recieptGrid.Background    = Brushes.White;
            recieptGrid.Margin        = new Thickness(30);

            for (int i = 0; i < 3; i++)
            {
                recieptGrid.ColumnDefinitions.Add(new ColumnDefinition());
            }
            for (int j = 0; j < 5; j++)
            {
                recieptGrid.RowDefinitions.Add(new RowDefinition {
                    Height = GridLength.Auto
                });
            }

            StackPanel headerInfo = new StackPanel()
            {
                Orientation         = Orientation.Vertical,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Margin = new Thickness(0, 25, 0, 25)
            };

            Grid.SetRow(headerInfo, 0);
            Grid.SetColumnSpan(headerInfo, 3);
            recieptGrid.Children.Add(headerInfo);

            Label company = CreateLabel("SaMic Driks", 25);

            company.HorizontalContentAlignment = HorizontalAlignment.Center;
            headerInfo.Children.Add(company);

            TextBlock adress = new TextBlock()
            {
                TextWrapping  = TextWrapping.Wrap,
                FontSize      = 14,
                Text          = "Adress: Kungsgatan 1 \r\n415 42 Gothenburg \r\nPhone: 073 445 45 45\r\n" + DateTime.Now,
                TextAlignment = TextAlignment.Center,
            };

            headerInfo.Children.Add(adress);

            Random rnd         = new Random();
            int    recieptNr   = rnd.Next(143, 236565);
            Label  recieptText = CreateLabel("Reciept No", 20);

            recieptText.Content   += " # " + recieptNr;
            recieptText.Foreground = Brushes.White;
            recieptText.Background = Brushes.Green;
            Grid.SetRow(recieptText, 1);
            Grid.SetColumnSpan(recieptText, 3);
            recieptGrid.Children.Add(recieptText);

            Grid productGrid = new Grid();

            productGrid.ShowGridLines = false;
            productGrid.ColumnDefinitions.Add(new ColumnDefinition());
            productGrid.ColumnDefinitions.Add(new ColumnDefinition());
            productGrid.ColumnDefinitions.Add(new ColumnDefinition());
            productGrid.RowDefinitions.Add(new RowDefinition());
            Grid.SetRow(productGrid, 2);
            Grid.SetColumnSpan(productGrid, 3);
            recieptGrid.Children.Add(productGrid);

            Label prodName   = CreateLabel("Product", 15);
            Label prodAmount = CreateLabel("Amount", 15);
            Label prodPrice  = CreateLabel("Price", 15);

            Grid.SetRow(prodName, 0);
            Grid.SetRow(prodAmount, 0);
            Grid.SetRow(prodPrice, 0);
            Grid.SetColumn(prodName, 0);
            Grid.SetColumn(prodAmount, 1);
            Grid.SetColumn(prodPrice, 2);
            productGrid.Children.Add(prodName);
            productGrid.Children.Add(prodAmount);
            productGrid.Children.Add(prodPrice);

            for (int i = 0; i < ReceiptProducts.Count; i++)
            {
                productGrid.RowDefinitions.Add(new RowDefinition());
                Label l1 = CreateLabel(ReceiptProducts[i].ProductName, 15);
                l1.Name = "nameLabel" + i;
                Label l2 = CreateLabel(ReceiptProducts[i].Amount.ToString(), 15);
                l2.Name = "amountLabel" + i;
                Label l3 = CreateLabel((ReceiptProducts[i].Amount * ReceiptProducts[i].Price) + " SEK", 15);
                l3.Name = "costLabel" + i;
                Grid.SetRow(l1, i + 1);
                Grid.SetRow(l2, i + 1);
                Grid.SetRow(l3, i + 1);
                Grid.SetColumn(l1, 0);
                Grid.SetColumn(l2, 1);
                Grid.SetColumn(l3, 2);
                productGrid.Children.Add(l1);
                productGrid.Children.Add(l2);
                productGrid.Children.Add(l3);
            }

            StackPanel priceInfo = new StackPanel()
            {
                Orientation         = Orientation.Vertical,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(0, 10, 0, 0)
            };

            Grid.SetRow(priceInfo, 3);
            Grid.SetColumn(priceInfo, 1);
            recieptGrid.Children.Add(priceInfo);

            Label totalPriceTxt     = CreateLabel("Total price: ", 15);
            Label discountTxt       = CreateLabel("Discount: ", 15);
            Label discountedAmntTxt = CreateLabel("With discount: ", 18);

            totalPriceTxt.FontWeight     = FontWeights.Bold;
            discountTxt.FontWeight       = FontWeights.Bold;
            discountedAmntTxt.FontWeight = FontWeights.UltraBlack;
            priceInfo.Children.Add(totalPriceTxt);
            priceInfo.Children.Add(discountTxt);
            priceInfo.Children.Add(discountedAmntTxt);

            StackPanel priceData = new StackPanel()
            {
                Orientation         = Orientation.Vertical,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(0, 10, 0, 0)
            };

            Grid.SetRow(priceData, 3);
            Grid.SetColumn(priceData, 2);
            recieptGrid.Children.Add(priceData);

            double totalWithDiscount = GetTotalPrice - (GetTotalPrice * ((double)GetDiscount / 100));
            Label  totPrice          = CreateLabel(GetTotalPrice.ToString() + " SEK", 15);
            Label  disc   = CreateLabel(GetDiscount.ToString() + " %", 15);
            Label  tPrice = CreateLabel(totalWithDiscount.ToString() + " SEK", 15);

            totPrice.FontWeight = FontWeights.Bold;
            disc.FontWeight     = FontWeights.Black;
            disc.Foreground     = Brushes.Green;
            tPrice.FontWeight   = FontWeights.UltraBold;
            priceData.Children.Add(totPrice);
            priceData.Children.Add(disc);
            priceData.Children.Add(tPrice);

            Label welcomeAgain = CreateLabel("Happy Shopping, don't drink it all at once!", 15);

            welcomeAgain.HorizontalAlignment = HorizontalAlignment.Center;
            welcomeAgain.Margin = new Thickness(0, 25, 0, 0);
            Grid.SetRow(welcomeAgain, 4);
            Grid.SetColumnSpan(welcomeAgain, 3);
            recieptGrid.Children.Add(welcomeAgain);
        }