コード例 #1
0
        public async void TestDeleteIdEqualsZero()
        {
            var optionsBuilder = new DbContextOptionsBuilder <HomeMyDayDbContext>();

            optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            HomeMyDayDbContext context = new HomeMyDayDbContext(optionsBuilder.Options);

            context.FaqCategory.AddRange(
                new FaqCategory()
            {
                CategoryName = "Test"
            }
                );

            await context.SaveChangesAsync();

            IFaqRepository repository = new EFFaqRepository(context);

            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => repository.DeleteCategory(0));
        }
コード例 #2
0
        public async void TestDeleteExistingCategory()
        {
            var optionsBuilder = new DbContextOptionsBuilder <HomeMyDayDbContext>();

            optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            HomeMyDayDbContext context = new HomeMyDayDbContext(optionsBuilder.Options);

            context.FaqCategory.AddRange(
                new FaqCategory()
            {
                Id = 1, CategoryName = "Test"
            }
                );

            await context.SaveChangesAsync();

            IFaqRepository repository = new EFFaqRepository(context);

            await repository.DeleteCategory(1);

            FaqCategory deletedCat = await context.FaqCategory.FindAsync((long)1);

            Assert.Null(deletedCat);
        }