public async void TestQuestionListWithItemsPageBelowZeroPageSizeBelowZero() { var optionsBuilder = new DbContextOptionsBuilder <HomeMyDayDbContext>(); optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString()); HomeMyDayDbContext context = new HomeMyDayDbContext(optionsBuilder.Options); context.FaqCategory.AddRange( new FaqCategory() { Id = 1, CategoryName = "TestA", Questions = new System.Collections.Generic.List <FaqQuestion>() { new FaqQuestion() { Question = "Question 1", Answer = "Answer 1" }, new FaqQuestion() { Question = "Question 2", Answer = "Answer 2" } } }, new FaqCategory() { Id = 2, CategoryName = "TestB" } ); await context.SaveChangesAsync(); IFaqRepository repository = new EFFaqRepository(context); PaginatedList <FaqQuestion> paginatedQuestions = await repository.ListQuestions(1, -8, -10); Assert.NotNull(paginatedQuestions); Assert.Equal(2, paginatedQuestions.Count); Assert.Equal(1, paginatedQuestions.PageIndex); Assert.Equal(10, paginatedQuestions.PageSize); Assert.Equal(1, paginatedQuestions.TotalPages); Assert.False(paginatedQuestions.HasPreviousPage); Assert.False(paginatedQuestions.HasNextPage); }
public async void TestQuestionListWithIdBelowZero() { var optionsBuilder = new DbContextOptionsBuilder <HomeMyDayDbContext>(); optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString()); HomeMyDayDbContext context = new HomeMyDayDbContext(optionsBuilder.Options); context.FaqCategory.AddRange( new FaqCategory() { Id = 1, CategoryName = "TestA", Questions = new System.Collections.Generic.List <FaqQuestion>() { new FaqQuestion() { Question = "Question 1", Answer = "Answer 1" }, new FaqQuestion() { Question = "Question 2", Answer = "Answer 2" } } }, new FaqCategory() { Id = 2, CategoryName = "TestB" } ); await context.SaveChangesAsync(); IFaqRepository repository = new EFFaqRepository(context); await Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => repository.ListQuestions(-5, 1, 10)); }