public void GetItemList_GivenManyItems_ShouldReturnListOfThoseItems()
 {
     
     //---------------Set up test pack-------------------
     var testItemList = SetUpItemDataContext();
     var context = Substitute.For<ILendingLibraryContext>();
     SetContextWithDtos(context, testItemList);
     var repo = new ItemRepository(context);
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     var result = repo.GetItemList();
     //---------------Test Result -----------------------
     Assert.AreEqual(testItemList, result);
     CollectionAssert.AreEqual(testItemList, result);
 }
        public void GetItemList_GivenOneItem_ShouldReturnThatItem()
        {
            var testItem = new ItemDto()
            {
                Id = 1,
                Description = "Description one",
                ItemName = "Ball"
            };
            var testItemList = new List<ItemDto>() { testItem };

            var context = Substitute.For<ILendingLibraryContext>();
            SetContextWithDtos(context, testItemList);
            //---------------Set up test pack-------------------
            var repo = new ItemRepository(context);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var result = repo.GetItemList();
            //---------------Test Result -----------------------
            Assert.AreEqual(testItemList, result);
        }
        public void Update_GivenItemId_ShouldUpdateTheItem()
        {
            var items = SetUpItemDataContext();
            //---------------Set up test pack-------------------
            var itemToUpdate = items[0];
            var context = Substitute.For<ILendingLibraryContext>();
            var repo = new ItemRepository(context);
            SetContextWithDtos(context, items);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------

            //---------------Test Result -----------------------
            Assert.IsTrue(repo.GetItemList().Contains(itemToUpdate));

            itemToUpdate.ItemName = "Book One v2.0";
            repo.Update(itemToUpdate);

            var updatedItem = context.Items.FirstOrDefault(i => i.Id == itemToUpdate.Id);
            Assert.IsNotNull(updatedItem);

            Assert.AreEqual(itemToUpdate, updatedItem);

        }
        public void Delete_GivenItemId_ShouldDeleteThatItem()
        {
            //---------------Set up test pack-------------------
            var items = SetUpItemDataContext();

            var context = Substitute.For<ILendingLibraryContext>();
            SetContextWithDtos(context, items);
            var repo = new ItemRepository(context);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            //---------------Test Result -----------------------
            Assert.IsTrue(repo.GetItemList().Contains(items[1]));

            repo.Delete(items[1].Id);

            var newItem = context.Items.FirstOrDefault(x => x.Id != items[1].Id);

            Assert.IsNotNull(newItem);
        }