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)); }
public void Gives_All_Flowers() { var data = new List <Grass> { new Grass { Name = "First" }, new Grass { Name = "Second" }, new Grass { Name = "Third" }, }.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(c => c.Grasses).Returns(mockSet.Object); var business = new GrassBusiness(mockContext.Object); var Grasses = business.GetAllGrasses(); Assert.AreEqual(3, Grasses.Count); Assert.AreEqual("First", Grasses[0].Name); Assert.AreEqual("Second", Grasses[1].Name); Assert.AreEqual("Third", Grasses[2].Name); }
private void ListAllGrasses() { Console.WriteLine(new string('-', 40)); Console.WriteLine(new string(' ', 16) + "Grasses" + new string(' ', 16)); Console.WriteLine(new string('-', 40)); var grasses = grassBusiness.GetAllGrasses(); foreach (var grass in grasses) { var Seasons = grassBusiness.GetSeason(grass.Name); Console.WriteLine($"{grass.Id } - {grass.Name}, {grass.Height}, {Seasons.Name}"); } Console.WriteLine(new string('-', 40)); }