Пример #1
0
        public void Check_That_Basket_Service_Cleans_Basket_For_User()
        {
            // Arrange
            var mock = new Mock <IUnitOfWork>();

            mock.Setup(m => m.BasketRepository.Get(It.IsAny <Expression <Func <Basket, bool> > >()))
            .Returns(new List <Basket> {
                new Basket {
                    BasketItems = new List <BasketItem> {
                        new BasketItem()
                    }
                }
            });
            mock.Setup(m => m.BasketItemRepository.Delete(It.IsAny <BasketItem>()));
            mock.Setup(m => m.BasketRepository.Delete(It.IsAny <Basket>()));

            const string sessionKey    = "sessionKey";
            var          basketService = new BasketService(mock.Object);

            // Act
            basketService.CleanBasketForUser(sessionKey);

            // Assert
            mock.Verify(m => m.BasketItemRepository.Delete(It.IsAny <BasketItem>()));
            mock.Verify(m => m.BasketRepository.Delete(It.IsAny <Basket>()));
            mock.Verify(m => m.SaveChanges());
        }
Пример #2
0
        public void Check_That_Basket_Service_Clean_Basket_For_User_Rethrows_An_Exception()
        {
            // Arrange
            var mock = new Mock <IUnitOfWork>();

            mock.Setup(m => m.BasketRepository.Get(It.IsAny <Expression <Func <Basket, bool> > >()))
            .Callback(() => { throw new Exception(); });

            const string sessionKey    = "sessionKey";
            var          basketService = new BasketService(mock.Object);

            // Act
            basketService.CleanBasketForUser(sessionKey);
        }