示例#1
0
        private void Update()
        {
            Console.WriteLine("Enter Name to update: ");
            string name   = Console.ReadLine();
            Cactus cactus = cactusBusiness.GetCactusByName(name);

            if (cactus != null)
            {
                Console.WriteLine("Enter name: ");
                cactus.Name = Console.ReadLine();
                Console.WriteLine("Enter height: ");
                cactus.Height = decimal.Parse(Console.ReadLine());
                Console.WriteLine("Enter thorns: ");
                cactus.Thorns = Console.ReadLine();
                Console.WriteLine("Enter seasons Id: ");
                Console.WriteLine("(1-spring, 2-summer, 3-autumn, 4-winter)");
                cactus.SeasonsId = int.Parse(Console.ReadLine());
                cactusBusiness.Update(cactus);
                Console.WriteLine("The cactus was updated successfully!");
            }
            else
            {
                Console.WriteLine("Cactus not found!");
            }
        }
示例#2
0
        public void Gives_Cactus_By_Name()
        {
            var data = new List <Cactus>()
            {
                new Cactus {
                    Id = 1, Name = "Cactus1"
                },
                new Cactus {
                    Id = 2, Name = "Cactus2"
                },
                new Cactus {
                    Id = 3, Name = "Cactus3"
                },
            }.AsQueryable();

            var mockSet = new Mock <DbSet <Cactus> >();

            mockSet.As <IQueryable <Cactus> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <Cactus> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Cactus> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Cactus> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock <GardenContext>();

            mockContext.Setup(c => c.Cactuses).Returns(mockSet.Object);

            var business = new CactusBusiness(mockContext.Object);

            var cactus = business.GetCactusByName("Cactus1");

            Assert.AreEqual("Cactus1", cactus.Name);
        }