Exemple #1
0
        public async Task BasketCanBeDeleted()
        {
            var basket         = CreateEmptyBasket();
            var mockRepository = CreateMockBasketRepositoryForBasket(basket);
            var sut            = new BasketService(mockRepository.Object, CreateMockLogger());

            await sut.DeleteBasketAsync(basket.Id);

            mockRepository.Verify(x => x.DeleteAsync(It.Is <Basket>(i => i == basket)), Times.Once);
        }
Exemple #2
0
        public async Task Should_InvokeBasketRepositoryDeleteAsync_Once()
        {
            var basket = new Basket();

            basket.AddItem(1, It.IsAny <decimal>(), It.IsAny <int>());
            basket.AddItem(2, It.IsAny <decimal>(), It.IsAny <int>());
            _mockBasketRepo.Setup(x => x.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(basket);
            var basketService = new BasketService(_mockBasketRepo.Object, null);

            await basketService.DeleteBasketAsync(It.IsAny <int>());

            _mockBasketRepo.Verify(x => x.DeleteAsync(It.IsAny <Basket>()), Times.Once);
        }
Exemple #3
0
        public async Task Should_InvokeBasketRepoOnceAndBasketItemRepoTwice_Given_TwoItemsInBasket()
        {
            var basket = new Basket();

            basket.AddItem(1, It.IsAny <decimal>(), It.IsAny <int>());
            basket.AddItem(2, It.IsAny <decimal>(), It.IsAny <int>());
            _mockBasketRepo.Setup(x => x.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(basket);
            var basketService = new BasketService(_mockBasketRepo.Object, null, _mockBasketItemRepo.Object);

            await basketService.DeleteBasketAsync(It.IsAny <int>());

            _mockBasketRepo.Verify(x => x.DeleteAsync(It.IsAny <Basket>()), Times.Once);
            _mockBasketItemRepo.Verify(x => x.DeleteAsync(It.IsAny <BasketItem>()), Times.Exactly(2));
        }
        public async Task DeleteBasketAsync_Should_Execute_DeleteAsync_ExactlyOnce()
        {
            var basketRepoMock = new Mock <IAsyncRepository <Basket> >();
            var loggerMock     = new Mock <IAppLogger <BasketService> >();
            var basket         = new Basket()
            {
                BuyerId = Guid.NewGuid().ToString(),
                Id      = 1
            };

            basketRepoMock.Setup(x => x.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(basket);
            var basketService = new BasketService(basketRepoMock.Object, loggerMock.Object);

            await basketService.DeleteBasketAsync(1);

            basketRepoMock.Verify(x => x.DeleteAsync(basket), Times.Once);
        }