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)); }
public void Gives_All_Flowers() { var data = new List <Tree> { new Tree { Name = "First" }, new Tree { Name = "Second" }, new Tree { Name = "Third" }, }.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(c => c.Trees).Returns(mockSet.Object); var business = new TreeBusiness(mockContext.Object); var Trees = business.GetAllTrees(); Assert.AreEqual(3, Trees.Count); Assert.AreEqual("First", Trees[0].Name); Assert.AreEqual("Second", Trees[1].Name); Assert.AreEqual("Third", Trees[2].Name); }
private void ListAllTrees() { Console.WriteLine(new string('-', 40)); Console.WriteLine(new string(' ', 16) + "Trees" + new string(' ', 16)); Console.WriteLine(new string('-', 40)); var trees = treeBusiness.GetAllTrees(); foreach (var tree in trees) { var Seasons = treeBusiness.GetSeason(tree.Name); Console.WriteLine($"{tree.Id} - {tree.Name}, {tree.Type}, {tree.Height}, {tree.StemDiameter}, {Seasons.Name}"); } Console.WriteLine(new string('-', 40)); }