Beispiel #1
0
        public void Remove_Cactus()
        {
            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(x => x.Cactuses).Returns(mockSet.Object);

            var business = new CactusBusiness(mockContext.Object);
            var cactuses = business.GetAllCactuses();

            int deletedCactusId = 1; business.Delete(cactuses[0].Id);

            Assert.IsNull(business.GetAllCactuses().FirstOrDefault(x => x.Id == deletedCactusId));
        }
        private void Delete()
        {
            Console.WriteLine("Enter Id to delete: ");
            int id = int.Parse(Console.ReadLine());

            cactusBusiness.Delete(id);
            Console.WriteLine("Done.");
        }