public void Remove_Tree() { var data = new List <Tree>() { new Tree { Id = 1, Name = "Tree1" }, new Tree { Id = 2, Name = "Tree2" }, new Tree { Id = 3, Name = "Tree3" }, }.AsQueryable(); var mockSet = new Mock <DbSet <Tree> >(); mockSet.As <IQueryable <Tree> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Tree> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Tree> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Tree> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <GardenContext>(); mockContext.Setup(x => x.Trees).Returns(mockSet.Object); var business = new TreeBusiness(mockContext.Object); var trees = business.GetAllTrees(); int deletedTreeId = 1; business.Delete(trees[0].Id); Assert.IsNull(business.GetAllTrees().FirstOrDefault(x => x.Id == deletedTreeId)); }
private void Delete() { Console.WriteLine("Enter Id to delete: "); int id = int.Parse(Console.ReadLine()); treeBusiness.Delete(id); Console.WriteLine("Done."); }