Пример #1
0
        public void Add_1Item_1ItemReturn()
        {
            //arrange
            var basket = new Basket();
            var candy  = RandomData.Create <Candy>();

            //act
            basket.Add(candy);

            //assert
            Assert.Single(basket.items);
        }
Пример #2
0
        public void GetCost_ItemCount_Cost_Return(int itemCount, int itemCost, int result)
        {
            //arrange
            var basket  = new Basket();
            var product = RandomData.Create <Candy>();

            product.Count = itemCount;
            product.Cost  = itemCost;

            //act
            var totalCost = basket.GetCost(product);

            //assert
            Assert.Equal(result, totalCost);
        }
Пример #3
0
        public void Ctor_2Item_10ReturnTotalCost()
        {
            //arrange

            var products = new Dictionary <Product, int>();
            var product1 = RandomData.Create <Candy>();
            var product2 = RandomData.Create <Candy>();

            products.Add(product1, 4);
            products.Add(product2, 6);

            //act
            var bill = new Bill(products);

            //assert
            Assert.Equal(10, bill.TotalCost);
        }
Пример #4
0
        public void Discounting_5Cost_3Discont_2Result()
        {
            //arrange
            //var basket = new Basket();
            var product   = RandomData.Create <Candy>();
            var discounts = RandomData.Create <Dictionary <int, Discount> >();
            var basket    = FakeUtils.Resolve <Basket>();

            basket.FakeMethod(nameof(Basket.GetDiscount), 3);
            basket.FakeMethod(nameof(Basket.GetCost), 5);

            //act
            var totalCost = basket.Discounting(product, discounts);

            //assert
            Assert.Equal(2, totalCost);
        }
Пример #5
0
        public void Remove_1Item_EmptyItemList()
        {
            //arrange
            var basket  = new Basket();
            var items   = new Dictionary <int, Product>();
            var product = RandomData.Create <Candy>();

            product.Count = 1;
            items.Add(product.Id, product);

            basket.items = items;

            //act
            basket.Remove(product);

            //assert
            Assert.Empty(basket.items);
        }
Пример #6
0
        public void Add_2ItemWithDifferendID_2ItemResult()
        {
            //arrange
            var basket      = new Basket();
            var firstCandy  = RandomData.Create <Candy>();
            var secondCandy = RandomData.Create <Candy>();

            firstCandy.Id  = 1;
            secondCandy.Id = 2;

            //act
            basket.Add(firstCandy);
            basket.Add(secondCandy);
            var itemCount = basket.items.Count;

            //assert
            Assert.Equal(2, itemCount);
        }
Пример #7
0
        public void GetDiscount_NoDiscount_0Result()
        {
            //arrange
            var basket    = new Basket();
            var discounts = new Dictionary <int, Discount>();
            var discount  = FakeUtils.Resolve <Discount>().FakeMethod(nameof(Discount.CountPriceWithDiscount), 1);

            discounts.Add(1, discount);
            var product = RandomData.Create <Candy>();

            product.Id = 2;

            //act
            var totalDiscount = basket.GetDiscount(product, discounts);

            //assert
            Assert.Equal(0, totalDiscount);
        }
Пример #8
0
        public void GetDiscount_IsPresent_Result(int discountCost, int productCount, int result)
        {
            //arrange
            var basket    = new Basket();
            var discounts = new Dictionary <int, Discount>();
            var discount  = FakeUtils.Resolve <Discount>().FakeMethod(nameof(Discount.CountPriceWithDiscount), discountCost);

            discounts.Add(1, discount);
            var product = RandomData.Create <Candy>();

            product.Id    = 1;
            product.Count = productCount;

            //act
            var totalDiscount = basket.GetDiscount(product, discounts);

            //assert
            Assert.Equal(result, totalDiscount);
        }
Пример #9
0
        public void Remove_4ReduceBy2Count_2CountReturn()
        {
            //arrange
            var basket  = new Basket();
            var items   = new Dictionary <int, Product>();
            var product = RandomData.Create <Candy>();

            product.Count = 4;
            items.Add(product.Id, product);

            basket.items = items;

            //act
            basket.Remove(product, 2);
            var countFirstItem = basket.items.First().Value.Count;

            //assert
            Assert.Equal(2, countFirstItem);
        }
Пример #10
0
        public void Add_2ItemWithSameID_Result_MergeItem()
        {
            //arrange
            var basket      = new Basket();
            var firstCandy  = RandomData.Create <Candy>();
            var secondCandy = RandomData.Create <Candy>();

            firstCandy.Id    = 1;
            firstCandy.Count = 1;

            secondCandy.Id    = 1;
            secondCandy.Count = 1;

            //act
            basket.Add(firstCandy);
            basket.Add(secondCandy);

            //assert
            Assert.Single(basket.items);
        }
Пример #11
0
        public void Add_2ItemWithSameID_4ResultCount()
        {
            //arrange
            var basket      = new Basket();
            var firstCandy  = RandomData.Create <Candy>();
            var secondCandy = RandomData.Create <Candy>();

            firstCandy.Id    = 1;
            firstCandy.Count = 2;

            secondCandy.Id    = 1;
            secondCandy.Count = 2;

            //act
            basket.Add(firstCandy);
            basket.Add(secondCandy);
            var totalCount = basket.items.First().Value.Count;

            //assert
            Assert.Equal(4, totalCount);
        }