示例#1
0
        private void Update()
        {
            Console.WriteLine("Enter Name to update: ");
            string name = Console.ReadLine();
            Tree   tree = treeBusiness.GetTreeByName(name);

            if (tree != null)
            {
                Console.WriteLine("Enter name: ");
                tree.Name = Console.ReadLine();
                Console.WriteLine("Enter type: ");
                tree.Type = Console.ReadLine();
                Console.WriteLine("Enter height: ");
                tree.Height = decimal.Parse(Console.ReadLine());
                Console.WriteLine("Enter stem diameter: ");
                tree.StemDiameter = decimal.Parse(Console.ReadLine());
                Console.WriteLine("Enter seasons Id: ");
                Console.WriteLine("(1-spring, 2-summer, 3-autumn, 4-winter)");
                tree.SeasonsId = int.Parse(Console.ReadLine());
                treeBusiness.Update(tree);
                Console.WriteLine("The tree was updated successfully!");
            }
            else
            {
                Console.WriteLine("Tree not found!");
            }
        }
示例#2
0
        public void Gives_Tree_By_Name()
        {
            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(c => c.Trees).Returns(mockSet.Object);

            var business = new TreeBusiness(mockContext.Object);

            var tree = business.GetTreeByName("Tree1");

            Assert.AreEqual("Tree1", tree.Name);
        }