Пример #1
0
        public void AddItemThenRemove()
        {
            // arrange
            var sut = new BasketOfItems(1);

            // act
            sut.AddUpdateOrRemoveItem(1, 1);
            sut.AddUpdateOrRemoveItem(1, 0);

            //assert
            Assert.That(sut.Id, Is.GreaterThan(0));
            Assert.That(sut.CustomerId, Is.EqualTo(1));
            Assert.That(sut.BasketItems, Is.Empty);
        }
Пример #2
0
        public void AddSameItemMultipleTimes()
        {
            // arrange
            var sut = new BasketOfItems(1);

            // act
            sut.AddUpdateOrRemoveItem(1, 1);
            sut.AddUpdateOrRemoveItem(1, 1);

            //assert
            Assert.That(sut.Id, Is.GreaterThan(0));
            Assert.That(sut.CustomerId, Is.EqualTo(1));
            Assert.That(sut.BasketItems, Has.Count.EqualTo(1));
            Assert.That(sut.BasketItems.All(x => x.Quantity.Equals(1)));
        }
Пример #3
0
        public async Task GetBasketsWithDifferentPage()
        {
            // arrange
            var basket1 = new BasketOfItems(1);

            basket1.AddUpdateOrRemoveItem(1, 3);
            await _sut.CreateBasketAsync(basket1);

            var basket2 = new BasketOfItems(1);

            basket2.AddUpdateOrRemoveItem(2, 3);
            await _sut.CreateBasketAsync(basket2);

            var basket3 = new BasketOfItems(1);

            basket3.AddUpdateOrRemoveItem(3, 3);
            await _sut.CreateBasketAsync(basket3);

            // act
            var actual = await _sut.GetBaskets(1, 2);

            // assert
            Assert.That(actual.Count(), Is.EqualTo(1));
            Assert.That(actual.Select(x => x.Id).ToArray(), Does.Contain(basket3.Id));
        }
Пример #4
0
        public async Task GetBasketById()
        {
            // arrange
            var basket = new BasketOfItems(1);

            basket.AddUpdateOrRemoveItem(1, 3);
            await _sut.CreateBasketAsync(basket);

            // act
            var actual = await _sut.GetBasketById(basket.Id);

            // assert
            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.Id, Is.GreaterThan(0));
            Assert.That(actual.BasketItems, Has.Count.EqualTo(1));
        }
Пример #5
0
        public async Task DeleteBasket()
        {
            // arrange
            var basket = new BasketOfItems(1);

            basket.AddUpdateOrRemoveItem(1, 3);
            await _sut.CreateBasketAsync(basket);

            // act
            await _sut.DeleteBasket(basket.Id);

            // assert
            var dbBasket = await _context.Baskets.FirstOrDefaultAsync(x => x.Id.Equals(basket.Id));

            Assert.That(dbBasket, Is.Null);
        }
Пример #6
0
        public async Task UpdateBasket()
        {
            // arrange
            var basket = new BasketOfItems(1);
            await _sut.CreateBasketAsync(basket);

            basket.AddUpdateOrRemoveItem(1, 4);

            // act
            await _sut.UpdateBasket(basket);

            // assert
            var dbBasket = await _context.Baskets.FirstOrDefaultAsync(x => x.Id.Equals(basket.Id));

            Assert.That(dbBasket, Is.Not.Null);
            Assert.That(dbBasket.BasketItems, Has.Count.EqualTo(1));
            Assert.That(dbBasket.BasketItems.All(x => x.Quantity.Equals(4)));
        }