public void Remove_Shrub() { var data = new List <Shrub>() { new Shrub { Id = 1, Name = "Shrub1" }, new Shrub { Id = 2, Name = "Shrub2" }, new Shrub { Id = 3, Name = "Shrub3" }, }.AsQueryable(); var mockSet = new Mock <DbSet <Shrub> >(); mockSet.As <IQueryable <Shrub> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Shrub> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Shrub> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Shrub> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <GardenContext>(); mockContext.Setup(x => x.Shrubs).Returns(mockSet.Object); var business = new ShrubBusiness(mockContext.Object); var shrubs = business.GetAllShrubs(); int deletedShrubId = 1; business.Delete(shrubs[0].Id); Assert.IsNull(business.GetAllShrubs().FirstOrDefault(x => x.Id == deletedShrubId)); }
private void Delete() { Console.WriteLine("Enter Id to delete: "); int id = int.Parse(Console.ReadLine()); shrubBusiness.Delete(id); Console.WriteLine("Done."); }