예제 #1
0
        public void GListEngine_DeleteList()
        {
            //Arrange: Seeds the Mocked Accessor's list of GLists
            SeedGLists();
            var expected = new GList {
                Id       = 3,
                ListName = "MyList"
            };

            //Act: Calls the GListEngine DeleteList() method, which should delete the GList with the given id from the lists of GLists
            var deletedList = gListEngine.DeleteList(3);


            //Assert: Checks if a GList was deleted, if the correct GList was returned, and if the list of GLists does not contain the deleted GList
            Assert.IsNotNull(deletedList, "The deleted list is null.");
            Assert.AreEqual(2, mockedGListAccessor.GetState().Count(), "A GList was not deleted from the list of GLists.");
            Assert.AreEqual(expected, deletedList, "An incorrect list was returned or no list was returned.");
            CollectionAssert.DoesNotContain(mockedGListAccessor.GetState(), deletedList, "The list still contains the GList that needed to be deleted.");
        }
예제 #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);
        }