Пример #1
0
        public void Remove_Shrub()
        {
            var data = new List <Shrub>()
            {
                new Shrub {
                    Id = 1, Name = "Shrub1"
                },
                new Shrub {
                    Id = 2, Name = "Shrub2"
                },
                new Shrub {
                    Id = 3, Name = "Shrub3"
                },
            }.AsQueryable();

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

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

            var mockContext = new Mock <GardenContext>();

            mockContext.Setup(x => x.Shrubs).Returns(mockSet.Object);

            var business = new ShrubBusiness(mockContext.Object);
            var shrubs   = business.GetAllShrubs();

            int deletedShrubId = 1; business.Delete(shrubs[0].Id);

            Assert.IsNull(business.GetAllShrubs().FirstOrDefault(x => x.Id == deletedShrubId));
        }
Пример #2
0
        private void Delete()
        {
            Console.WriteLine("Enter Id to delete: ");
            int id = int.Parse(Console.ReadLine());

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