public void Remove_Grass() { var data = new List <Grass>() { new Grass { Id = 1, Name = "Grass1" }, new Grass { Id = 2, Name = "Grass2" }, new Grass { Id = 3, Name = "Grass3" }, }.AsQueryable(); var mockSet = new Mock <DbSet <Grass> >(); mockSet.As <IQueryable <Grass> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Grass> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Grass> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Grass> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <GardenContext>(); mockContext.Setup(x => x.Grasses).Returns(mockSet.Object); var business = new GrassBusiness(mockContext.Object); var grasses = business.GetAllGrasses(); int deletedGrassId = 1; business.Delete(grasses[0].Id); Assert.IsNull(business.GetAllGrasses().FirstOrDefault(x => x.Id == deletedGrassId)); }
private void Delete() { Console.WriteLine("Enter Id to delete: "); int id = int.Parse(Console.ReadLine()); grassBusiness.Delete(id); Console.WriteLine("Done."); }