public async Task TestGetQuestionsPastPageOne() { // Arrange var repo = new Mock <IRepositoryEnq>(); var questions = QuestionData.TestQuestions().ToList(); var maxPage = MaxPage(questions.Count); var midPage = 2; var midSkip = midPage * PageLength - PageLength; var maxSkip = maxPage * PageLength - PageLength; SetUpPastOneRepo(repo, midSkip, maxSkip, questions); var controller = new ReadonlyApiController(repo.Object); // Act var result = await controller.GetQuestions(midPage); await controller.GetQuestions(maxPage + 1000); // Assert Assert.Equal(PageLength, (result.Value as List <Question>).Count); repo.Verify(r => r.GetAllAsync (null, Desc(), true, It.IsIn(new [] { midSkip, maxSkip }), PageLength, null) , Times.Exactly(2) ); repo.Verify(r => r.GetCountAsync <Question>(null), Times.Exactly(2)); repo.VerifyNoOtherCalls(); }
public async Task TestGetQuestionsPageOne() { // Arrange var repo = new Mock <IRepositoryEnq>(); repo.Setup(r => r.GetAllAsync <Question>( null, Desc(), true, 0, PageLength, null) ).ReturnsAsync( QuestionData.TestQuestions().ToList().GetRange(0, PageLength) ); var controller = new ReadonlyApiController(repo.Object); // Act var result = await controller.GetQuestions(1); await controller.GetQuestions(0); await controller.GetQuestions(-1); // Assert Assert.IsType <OkObjectResult>(result); Assert.IsType <List <Question> >(result.Value); Assert.Equal(PageLength, (result.Value as List <Question>).Count); repo.Verify(r => r.GetAllAsync <Question> (null, Desc(), true, 0, PageLength, null), Times.Exactly(3) ); repo.VerifyNoOtherCalls(); }