Beispiel #1
0
    public void FindAllByQuantity_On_WrongArgument_ShouldReturnEmpty_Enumeration()
    {
        //Arrange
        IProductStock stock    = new Instock();
        Product       product1 = new Product("SalamShpekov", 3.50, 50);
        Product       product2 = new Product("BekonNov", 2.65, 43);
        Product       product3 = new Product("MayonezaNiskomaslena", 1.30, 13);
        Product       product4 = new Product("Ketchup", 1.80, 73);
        Product       product5 = new Product("Jelqzo", 0.70, 20);
        Product       product6 = new Product("Belina", .75, 50);
        Product       product7 = new Product("Sirene", .77, 50);

        //Act
        stock.Add(product1);
        stock.Add(product2);
        stock.Add(product3);
        stock.Add(product4);
        stock.Add(product5);
        stock.Add(product6);
        stock.Add(product7);
        stock.ChangeQuantity("Sirene", 5);
        stock.ChangeQuantity("SalamShpekov", 5);
        stock.ChangeQuantity("Belina", 5);
        //Assert
        List <Product> expected = new List <Product>();
        List <Product> actual   = stock.FindAllByQuantity(500).ToList();

        CollectionAssert.AreEqual(expected, actual);
    }
Beispiel #2
0
    public void ChangeQuantity_On_Multiple_Elements_ShouldWorkCorrectly()
    {
        //Arrange
        IProductStock stock    = new Instock();
        Product       product1 = new Product("SalamShpekov", 3.50, 560);
        Product       product2 = new Product("BekonNov", 2.65, 43);
        Product       product3 = new Product("MayonezaNiskomaslena", 1.30, 13);
        Product       product4 = new Product("Ketchup", 1.80, 73);
        Product       product5 = new Product("Jelqzo", 0.70, 130);
        Product       product6 = new Product("Belina", .75, 240);
        Product       product7 = new Product("Sirene", .77, 30);

        //Act
        stock.Add(product1);
        stock.Add(product2);
        stock.Add(product3);
        stock.Add(product4);
        stock.Add(product5);
        stock.Add(product6);
        stock.Add(product7);

        stock.ChangeQuantity(product4.Label, 50);
        stock.ChangeQuantity(product7.Label, 50);
        stock.ChangeQuantity(product3.Label, 50);

        //Assert
        List <Product> expected = new List <Product>()
        {
            product4, product7, product3
        };
        List <Product> actual = stock.FindAllByQuantity(50).ToList();

        CollectionAssert.AreEqual(expected, actual);
    }
Beispiel #3
0
    static void Main(string[] args)
    {
        IProductStock stock    = new Instock();
        Product       product1 = new Product("SalamShpekov", 3.50, 560);
        Product       product2 = new Product("BekonNov", 2.65, 43);
        Product       product3 = new Product("MayonezaNiskomaslena", 1.30, 13);
        Product       product4 = new Product("Ketchup", 1.80, 73);
        Product       product5 = new Product("Jelqzo", 0.70, 130);
        Product       product6 = new Product("Belina", .75, 240);
        Product       product7 = new Product("Sirene", .77, 30);

        //Act
        stock.Add(product1);
        stock.Add(product2);
        stock.Add(product3);
        stock.Add(product4);
        stock.Add(product5);
        stock.Add(product6);
        stock.Add(product7);

        stock.ChangeQuantity(product4.Label, 50);
        stock.ChangeQuantity(product7.Label, 50);
        stock.ChangeQuantity(product3.Label, 50);

        //Assert
        List <Product> expected = new List <Product>()
        {
            product4, product7, product3
        };
        List <Product> actual = stock.FindAllByQuantity(50).ToList();

        ;
    }
Beispiel #4
0
    public void ChangeQuantity_100000_OnSameProduct_ShouldWorkFast()
    {
        // Arrange
        IProductStock  stock    = new Instock();
        const int      count    = 100000;
        List <Product> products = new List <Product>(100000);

        for (int i = 0; i < count; i++)
        {
            Product p = new Product(i.ToString(), i, i);
            stock.Add(p);
            products.Add(p);
        }

        // Act & Assert
        Stopwatch sw   = Stopwatch.StartNew();
        Random    rand = new Random();

        for (int i = 0; i < 50000; i++)
        {
            int qty = rand.Next(50, 10000);
            stock.ChangeQuantity(products[576].Label, qty);
            Assert.AreEqual(products[576].Quantity, qty);
        }
        sw.Stop();
        Assert.Less(sw.ElapsedMilliseconds, 200);
    }
    public void ChangeQuantity_On_NonExisting_Product_ShouldThrow()
    {
        //Arrange
        IProductStock stock = new Instock();
        Product product1 = new Product("SalamShpekov", 3.50, 50);
        Product product2 = new Product("BekonNov", 2.65, 43);
        Product product3 = new Product("MayonezaNiskomaslena", 1.30, 13);

        //Act

        //Assert
        Assert.Throws<ArgumentException>(() => stock.ChangeQuantity("Barekov", 0));
    }
Beispiel #6
0
    public void FindByLabel_Should_Work_Correctly()
    {
        //Arrange
        IProductStock stock    = new Instock();
        Product       product1 = new Product("SalamShpekov", 3.50, 50);
        Product       product2 = new Product("BekonNov", 2.65, 43);
        Product       product3 = new Product("MayonezaNiskomaslena", 1.30, 13);

        //Act
        stock.Add(product1);
        stock.Add(product2);
        stock.Add(product3);

        stock.ChangeQuantity("SalamShpekov", 3);
        //Assert
        Assert.IsTrue(stock.Contains(product1));
        Assert.AreSame(product2, stock.FindByLabel("BekonNov")
                       , "FindByLabel on existing element should return the element itself");
    }
Beispiel #7
0
    public void ChangeQuantity_On_ExistingProduct_ShouldWorkCorrectly()
    {
        //Arrange
        IProductStock stock    = new Instock();
        Product       product1 = new Product("SalamShpekov", 3.50, 50);
        Product       product2 = new Product("BekonNov", 2.65, 43);
        Product       product3 = new Product("MayonezaNiskomaslena", 1.30, 13);

        //Act
        stock.Add(product1);
        stock.Add(product2);
        stock.Add(product3);

        stock.ChangeQuantity("SalamShpekov", 3);
        int expected = 3;
        int actual   = stock.FindByLabel("SalamShpekov").Quantity;

        //Assert
        Assert.AreEqual(3, stock.Count);
        Assert.AreEqual(expected, actual);
    }
    public static void Main()
    {
        var stock = new Instock();

        var productA = new Product("A", 50, 100);
        var productC = new Product("C", 100, 10);
        var productB = new Product("B", 50, 3);

        stock.Add(productA);
        stock.Add(productC);
        stock.Add(productB);

        var contains = stock.Contains(productC);
        var find     = stock.Find(0);

        stock.ChangeQuantity("C", -10);
        var byLabel = stock.FindByLabel("C");
        var firstCountByAscLabel = stock.FindFirstByAlphabeticalOrder(2);

        var byPriceRange       = stock.FindAllInRange(30, 500);
        var byPrice            = stock.FindAllByPrice(50);
        var firstMostExpensive = stock.FindFirstMostExpensiveProducts(2);
    }