Example #1
0
    public void removeInvalProdWQty()
    {
        string  id         = "1000";
        string  name       = "Level 1 Server";
        string  desc       = "2 Processors, 256GB DDR4, 15 3.25 Drive Bays";
        decimal price      = 10000;
        int     qty        = 10;
        int     AmountAdd1 = 5;
        Product product    = new Product(id, name, desc, price, qty);

        id    = "1001";
        name  = "Level 12Server";
        desc  = "2 Processors, 256GB DDR4, 15 3.25 Drive Bays";
        price = 15250;
        qty   = 10;
        int     AmountAdd2 = 5;
        Product product2   = new Product(id, name, desc, price, qty);

        id    = "1002";
        name  = "Level 3 Server";
        desc  = "2 Processors, 256GB DDR4, 15 3.25 Drive Bays";
        price = 15250;
        qty   = 10;
        int     AmountAdd3 = 5;
        Product product3   = new Product(id, name, desc, price, qty);


        Sale newSale = new Sale();

        newSale.Add(product, AmountAdd1);
        newSale.Add(product2, AmountAdd2);
        Assert.IsFalse(newSale.Delete(product3, AmountAdd3));
        Assert.AreEqual(product.Price * AmountAdd1 + product2.Price * AmountAdd2, newSale.Total);
        Assert.AreEqual(AmountAdd1 + AmountAdd2, newSale.NumbOfProd);
    }
Example #2
0
    public void SearchPopulatedList()
    {
        string  id         = "1000";
        string  name       = "Level 1 Server";
        string  desc       = "2 Processors, 256GB DDR4, 15 3.25 Drive Bays";
        decimal price      = 10000;
        int     qty        = 10;
        int     AmountAdd1 = 5;
        Product product    = new Product(id, name, desc, price, qty);

        id    = "1001";
        name  = "Level 12Server";
        desc  = "2 Processors, 256GB DDR4, 15 3.25 Drive Bays";
        price = 15250;
        qty   = 10;
        int     AmountAdd2 = 5;
        Product product2   = new Product(id, name, desc, price, qty);

        id    = "1002";
        name  = "Level 3 Server";
        desc  = "2 Processors, 256GB DDR4, 15 3.25 Drive Bays";
        price = 15250;
        qty   = 10;
        int     AmountAdd3 = 5;
        Product product3   = new Product(id, name, desc, price, qty);

        Sale newSale = new Sale();

        newSale.Add(product, AmountAdd1);
        newSale.Add(product2, AmountAdd2);
        newSale.Add(product3, AmountAdd3);
        int count = newSale.Search(product2);

        Assert.AreEqual(AmountAdd2, count);
    }
Example #3
0
    public void removeProduct()
    {
        string  id      = "1000";
        string  name    = "Level 1 Server";
        string  desc    = "2 Processors, 256GB DDR4, 15 3.25 Drive Bays";
        decimal price   = 10000;
        int     qty     = 10;
        Product product = new Product(id, name, desc, price, qty);

        id    = "1001";
        name  = "Level 1 Server";
        desc  = "2 Processors, 256GB DDR4, 15 3.25 Drive Bays";
        price = 15250;
        qty   = 10;
        Product product2 = new Product(id, name, desc, price, qty);


        Sale newSale = new Sale();

        newSale.Add(product);
        newSale.Add(product2);
        Assert.AreEqual(product.Price + product2.Price, newSale.Total);
        Assert.AreEqual(2, newSale.NumbOfProd);
        Assert.IsTrue(newSale.Delete(product));
        Assert.AreEqual(product2.Price, newSale.Total);
        Assert.AreEqual(1, newSale.NumbOfProd);
        Assert.AreEqual(10, product.Qty);
    }
Example #4
0
        public void Add_DistinctProducts_ReturnsSumOfUnitPrices()
        {
            var sale = new Sale();

            sale.Add(new Product("A", 1));
            sale.Add(new Product("B", 2));
            sale.Add(new Product("C", 3));

            Assert.Equal(6, sale.GetTotalPrice());
        }
Example #5
0
        public void Add_MixOfVolumeAndSingleProducts_ReturnsCorrectTotalPrice()
        {
            var sale          = new Sale();
            var volumeProduct = new Product("A", 1, new VolumeDiscount(2, 3));

            sale.Add(volumeProduct);
            sale.Add(volumeProduct);
            sale.Add(volumeProduct);
            sale.Add(new Product("B", 5));

            Assert.Equal(7, sale.GetTotalPrice());
        }
Example #6
0
        public void Checkout_WithDiscountCard_NoDiscountForVolume()
        {
            var sale1        = new Sale();
            var product      = new Product("A", 2000, new VolumeDiscount(3000, 2));
            var discountCard = new DiscountCard(1000);

            sale1.Add(product);
            sale1.Add(product);
            sale1.AddDiscountCard(discountCard);

            Assert.Equal(1, discountCard.CurrentPercent());
            Assert.Equal(3000, sale1.Checkout());
            Assert.Equal(1, discountCard.CurrentPercent());
        }
Example #7
0
        public void Checkout_WithDiscountCard_DiscountCardAddsOnlyUnitPriceToBalance()
        {
            var sale         = new Sale();
            var discountCard = new DiscountCard(1000);
            var product      = new Product("A", 1000, new VolumeDiscount(2000, 3));

            sale.Add(product);
            sale.Add(product);
            sale.Add(product);
            sale.Add(product);

            sale.AddDiscountCard(discountCard);

            Assert.Equal(1000, discountCard.Balance);
            Assert.Equal(2990, sale.Checkout());
            Assert.Equal(2000, discountCard.Balance);
        }
Example #8
0
 /// <summary>
 /// loadButtons() creates a button or each item in inventory that has product in stock.
 /// </summary>
 private void loadButtons()
 {
     // Check each product to see if it has quantity greater than 0. Then create a button for it.
     foreach (Product temp in Form1.products)
     {
         if (temp.Qty > 0)
         {
             //Variables to dynamically create a button and its click event.
             Button newButton = new Button();
             newButton.Text   = "ID:" + temp.ID + "\n" + temp.Name + "\n$" + temp.Price.ToString();
             newButton.Size   = new Size(75, 75);
             newButton.Click += (se, ev) =>
             {
                 //This checks to see what mode the POS form is in.
                 if (addQuantityCheckBox.Checked) //This mode asks the user to input a qunatity to add.
                 {
                     int intIn = 0;               //Will hold the quantity to add
                     intIn = testInput(temp);     //Get user input
                     if (intIn > 0)               //If more than zero add the item to the list
                     {
                         newSale.Add(temp, intIn);
                     }
                     else
                     {
                         return;
                     }
                 }
                 else                            //This mode adds 1 of the product to the list
                 {
                     newSale.Add(temp);
                 }
                 //Recreate the buttons as there may be items that are no longer available as they
                 // where all added to the list to be sold.
                 removeButtons();              //Remove all the buttons
                 loadButtons();                //Create new buttons
                 setButtonLoc();               // Display them
                 UpdateAll();                  // update all the lists,labels and refresh the other forms.
             };
             //Add the button the list
             buttons.Add(newButton);
             //Add the button to the form.
             this.Controls.Add(newButton);
         }
     }
 }
        private Sale CreateRandomSale(int id)
        {
            var sale = new Sale(id, Vendor.Name);

            for (var index = 1; index <= MaxItems; index++)
            {
                sale.Add(new Item(index, sale.Id, ItemQuantity, ItemPrice));
            }

            return(sale);
        }
Example #10
0
        public void Checkout_WithDiscountCard_AmountOfSaleIsAddedToDiscountCard()
        {
            var sale         = new Sale();
            var discountCard = new DiscountCard(1000);

            sale.Add(new Product("A", 2000));
            sale.AddDiscountCard(discountCard);

            Assert.Equal(1, discountCard.CurrentPercent());
            Assert.Equal(1980, sale.Checkout());
            Assert.Equal(3, discountCard.CurrentPercent());
        }
Example #11
0
        public void Checkout_WithDiscountCard_DiscountAppliesToProductIfVolumeIsNotReached()
        {
            var sale1        = new Sale();
            var discountCard = new DiscountCard(1000);
            var product      = new Product("A", 2000, new VolumeDiscount(3000, 2));

            sale1.Add(product);
            sale1.AddDiscountCard(discountCard);

            Assert.Equal(1, discountCard.CurrentPercent());
            Assert.Equal(1980, sale1.Checkout());
            Assert.Equal(3, discountCard.CurrentPercent());
        }
Example #12
0
        [TestCase(new[] { "10 imported bottles of whiskey at 27.99", "10 bottles of local whiskey at 18.99", "10 packets of iodine tablets at 9.75", "10 boxes of imported potato chips at 11.25" }, "10 imported bottles of whiskey: 321.88\n10 bottles of local whiskey: 208.89\n10 packets of iodine tablets: 97.50\n10 imported boxes of potato chips: 118.12\nSales Taxes: 66.59\nTotal: 746.40", TestName = "10 Bottles of Whiskey, 10 Bottles of Local Whiskey, 10 Packets of Iodine Tablets & 10 Boxes of Potato Chips (Test 4)", Category = "Mixed")] // Test 4
        public void PrintReceipt_OutputsExpectedResult(string[] input, string expectedResult)
        {
            // Arrange
            Sale     sale    = new Sale();
            IPrinter printer = new BasicPrinter();

            // Act
            foreach (string item in input)
            {
                sale.Add(item);
            }

            // Assert
            Assert.That(printer.PrintReceipt(sale), Is.EqualTo(expectedResult));
        }
Example #13
0
        private Sale GenerateSale()
        {
            if (_order.buyVehicle == null || _saleRep == null)
            {
                throw new System.ArgumentException("Invalid code path. Need to declare builder parameters!");
            }

            Sale sInvoice = new Sale(IdGenerator.UniqueId(), _saleRep, _order.buyVehicle, _order.tradeVehicle);

            foreach (Addon a in _order.addons)
            {
                sInvoice.Add(a);
            }

            return(sInvoice);
        }
Example #14
0
    public void addInvalidProd()
    {
        string  id      = "1000";
        string  name    = "Level 1 Server";
        string  desc    = "2 Processors, 256GB DDR4, 15 3.25 Drive Bays";
        decimal price   = 10000;
        int     qty     = 0;
        Product product = new Product(id, name, desc, price, qty);


        Sale newSale = new Sale();

        Assert.IsFalse(newSale.Add(product));
        Assert.AreEqual(0, newSale.Total);
        Assert.AreEqual(0, newSale.NumbOfProd);
    }
Example #15
0
    public void testTotal()
    {
        string  id      = "1000";
        string  name    = "Level 1 Server";
        string  desc    = "2 Processors, 256GB DDR4, 15 3.25 Drive Bays";
        decimal price   = 10000;
        int     qty     = 10;
        Product product = new Product(id, name, desc, price, qty);


        Sale newSale1 = new Sale();

        Assert.IsTrue(newSale1.Add(product));
        Assert.AreEqual(product.Price, newSale1.Total);
        Assert.AreEqual(1, newSale1.NumbOfProd);
        Assert.AreEqual(9, product.Qty);
    }
Example #16
0
        public void Checkout_WithoutDiscountCard_DiscountCardDoesntApplyToNewSale()
        {
            var sale1        = new Sale();
            var discountCard = new DiscountCard(1000);
            var product      = new Product("A", 2000);

            sale1.Add(product);
            sale1.AddDiscountCard(discountCard);
            sale1.Checkout();
            var sale2 = new Sale();

            sale2.Add(product);

            Assert.Equal(3, discountCard.CurrentPercent());
            Assert.Equal(2000, sale2.Checkout());
            Assert.Equal(3, discountCard.CurrentPercent());
        }
        public bool AddSale(Sales sale)
        {
            try
            {
                if (Sale == null)
                {
                    Sale = new List <Sales>();
                }

                Sale.Add(sale);
                BindSales();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #18
0
    public void addProductWQty()
    {
        string  id      = "1000";
        string  name    = "Level 1 Server";
        string  desc    = "2 Processors, 256GB DDR4, 15 3.25 Drive Bays";
        decimal price   = 10000;
        int     qty     = 10;
        Product product = new Product(id, name, desc, price, qty);

        int numOfProdToAdd = 3;


        Sale newSale = new Sale();

        Assert.IsTrue(newSale.Add(product, numOfProdToAdd));
        Assert.AreEqual(product.Price * 3, newSale.Total);
        Assert.AreEqual(3, newSale.NumbOfProd);
        Assert.AreEqual(7, product.Qty);
    }
Example #19
0
        static void Main(string[] args)
        {
            Sale   sale;
            string input;

            sale = new Sale();
            Console.WriteLine("Enter sales in the format <qty> <description> at <unit price>\nFor example: 2 books at 13.25\nEntering a blank line completes the sale\n");
            input = GetInput();
            while (!string.IsNullOrEmpty(input))
            {
                if (!sale.Add(input))
                {
                    Console.WriteLine("Sales should be in the format of <qty> <description> at <unit price>\nFor example: 2 books at 13.25");
                }
                input = GetInput();
            }
            Console.WriteLine(sale.ToString());
            Console.WriteLine("--- Press Enter to Finish ---");
            Console.ReadLine();
        }
Example #20
0
        private static void Main()
        {
            Sale sale = new Sale();

            Console.WriteLine("Enter sales in the format <qty> <description> at <unit price>\nFor example: 2 books at 13.25\nEntering a blank line completes the sale\n");
            string input = GetInput();

            while (!string.IsNullOrEmpty(input))
            {
                if (!sale.Add(input))
                {
                    Console.WriteLine("Sales should be in the format of <qty> <description> at <unit price>\nFor example: 2 books at 13.25");
                }
                input = GetInput();
            }

            IPrinter receiptPrinter = new BasicPrinter();

            Console.WriteLine(receiptPrinter.PrintReceipt(sale));
            Console.WriteLine("--- Press Enter to Finish ---");
            Console.ReadLine();
        }
Example #21
0
 public void SaleAddAddonTest()
 {
     si01.Add(a1);
     Assert.AreEqual(155, si01.AddonCost);
 }