public void ItemsEngine_GetListItems()
        {
            //Arrange: Seeds the Mocked Accessor's list of Items and creates the expected list of Items with shared GListId
            SeedItems();
            int groceryListId = 1;
            var expected      = new List <Item>
            {
                new Item
                {
                    Id            = 1,
                    Name          = "Candy",
                    GroceryListId = 1
                },
                new Item
                {
                    Id            = 2,
                    Name          = "Juice",
                    GroceryListId = 1
                }
            };


            //Act: Calls the ItemsEngine GetListItems() method which returns a list of all items on a certain grocery list
            IEnumerable <Item> result = itemsEngine.GetListItems(groceryListId);


            //Assert: Checks whether the expected and result lists contain the same amount of lists and then if they are the same
            Assert.AreEqual(expected.Count(), result.Count(), "More than two results were returned");
            for (int i = 0; i < expected.Count; i++)
            {
                Assert.AreEqual(expected.ElementAt(i), result.ElementAt(i), $"The Item at index {i} was retrieved incorrectly.");
            }
        }
示例#2
0
        public void DeleteList(string id)
        {
            var parsedId = int.Parse(id);

            GList glist = _gListEngine.GetList(parsedId);

            // deletes each item in the grocery list before deleting the list itself to prevent SQL errors
            var itemsInGList = _itemsEngine.GetListItems(parsedId);

            // checks if there are any items in the list
            if (itemsInGList.Any())
            {
                // iterates through each item in the glist and deletes them by their Id's
                foreach (Item item in itemsInGList)
                {
                    _itemsEngine.DeleteItem(item.Id);
                }
            }

            // deleting the actual list itself
            _gListEngine.DeleteList(glist.Id);
        }
示例#3
0
        public IEnumerable <Item> GetListItems(string id)
        {
            var parsedId = int.Parse(id);

            return(_itemsEngine.GetListItems(parsedId));
        }