Exemple #1
0
        public void Check_That_Order_Service_Adds_Basket_Items_To_Order()
        {
            // Arrange
            var basketItems = new List <BasketItemModel>
            {
                new BasketItemModel(),
                new BasketItemModel(),
            };

            var mock = new Mock <IUnitOfWork>();

            mock.Setup(m => m.OrderRepository.Get(It.IsAny <Expression <Func <Order, bool> > >()))
            .Returns <Expression <Func <Order, bool> > >(x => new List <Order> {
                new Order {
                    OrderId = 1
                }
            });
            mock.Setup(m => m.OrderItemRepository.Insert(It.IsAny <OrderItem>()));
            mock.Setup(m => m.GameRepository.GetById(It.IsAny <int>()))
            .Returns(new Game());

            var orderService = new OrderService(mock.Object);

            const string sessionKey = "sessionKey";

            // Act
            orderService.AddBasketItemsToOrder(basketItems, sessionKey);

            // Assert
            mock.Verify(m => m.OrderRepository.Get(It.IsAny <Expression <Func <Order, bool> > >()));
            mock.Verify(m => m.OrderItemRepository.Insert(It.IsAny <OrderItem>()), Times.Exactly(basketItems.Count));
        }