コード例 #1
0
        public void TestExecuteShouldReturnShoppingItems()
        {
            //arrange
            const string testCartId = "TestCartId";

            var mockShoppingCartItemRepository = new Mock <IShoppingCartItemRepository>();


            var expectedShoppingCartItems = new List <ShoppingCartItem>
            {
                _shoppingCartItems.First(),
                _shoppingCartItems.Last()
            };


            mockShoppingCartItemRepository.Setup(s => s.GetAll()).Returns(_shoppingCartItems.AsQueryable);

            var sut = new GetShoppingCartItemsListQuery(mockShoppingCartItemRepository.Object);

            //act
            var results = sut.Execute(testCartId);

            //assert
            Assert.Equal(expectedShoppingCartItems, results);
        }
コード例 #2
0
        public void TestExecuteShouldReturnNoItemsIfNoShoppingCartIdMatchesFound()
        {
            //arrange
            const string testCartId = "NoMatchesId";

            var mockShoppingCartItemRepository = new Mock <IShoppingCartItemRepository>();


            mockShoppingCartItemRepository
            .Setup(s => s.GetAll())
            .Returns(_shoppingCartItems.AsQueryable);

            var sut = new GetShoppingCartItemsListQuery(mockShoppingCartItemRepository.Object);

            //act
            var results = sut.Execute(testCartId);

            //assert
            Assert.Empty(results);
        }