Пример #1
0
        public async Task GetCartItems_WhenCalled_ReturnsAllCartItems()
        {
            //Arrange
            var myDbContextMoq = new DbContextMock <ShoppingCartContext>(myDummyOptions);

            //Create list of CartItems
            myDbContextMoq.CreateDbSetMock(x => x.CartItems, new[]
            {
                new CartItem {
                    ProductId = 1, Price = 3, Quantity = 2
                },
                new CartItem {
                    ProductId = 2, Price = 2, Quantity = 5
                },
                new CartItem {
                    ProductId = 3, Price = 21, Quantity = 1
                }
            });

            //Act
            //Pass myDbContextMoq.Object to the CartItemService class
            CartItemService service = new CartItemService(myDbContextMoq.Object);

            //Call GetAllCartItems() function
            var result = await service.GetAllCartItems();

            //Assert
            Assert.NotNull(result);
        }