public async Task Get_WhenGettingAllQuestions_ThenReturnListOfQuestions() { QuestionPagedItem[] questionItems = new QuestionPagedItem[] { new QuestionPagedItem { ID = Guid.NewGuid(), Number = 1, Section = "Section 1" }, new QuestionPagedItem { ID = Guid.NewGuid(), Number = 2, Section = "Section 2" } }; QuestionPaged questionsPaged = new QuestionPaged { Items = questionItems, TotalCount = questionItems.Length }; questionController.Request = new HttpRequestMessage(HttpMethod.Get, "api/Question/?itemsPerPage=2&pageNumber=1"); questionController.Configuration = new HttpConfiguration(); questionServiceMock.Setup(x => x.GetQuestionsByPageAsync(2, 1)).Returns(Task.FromResult(questionsPaged.DeepCopyTo <Qubiz.QuizEngine.Services.Models.PagedResult <Qubiz.QuizEngine.Services.Models.QuestionListItem> >())); IHttpActionResult actionResult = await questionController.Get(2, 1); QuestionPaged response = (actionResult as OkNegotiatedContentResult <QuestionPaged>).Content; Assert.AreEqual(typeof(OkNegotiatedContentResult <QuestionPaged>), actionResult.GetType()); AssertAreEqual(questionsPaged.Items[0], response.Items[0]); AssertAreEqual(questionsPaged.Items[1], response.Items[1]); Assert.AreEqual(questionsPaged.TotalCount, response.TotalCount); }
public async Task Get_WhenNoQuestionsMatchTheSearch_ThenNoQuestionsAreReturned() { QuestionPaged questions = new QuestionPaged(); questionController.Request = new HttpRequestMessage(HttpMethod.Get, "api/Question/?itemsPerPage=2&pageNumber=1"); questionController.Configuration = new HttpConfiguration(); questionServiceMock.Setup(x => x.GetQuestionsByPageAsync(2, 1)).Returns(Task.FromResult(questions.DeepCopyTo <Qubiz.QuizEngine.Services.Models.PagedResult <Qubiz.QuizEngine.Services.Models.QuestionListItem> >())); IHttpActionResult actionResult = await questionController.Get(2, 1); QuestionPaged response = (actionResult as OkNegotiatedContentResult <QuestionPaged>).Content; Assert.AreEqual(typeof(OkNegotiatedContentResult <QuestionPaged>), actionResult.GetType()); Assert.AreEqual(0, response.Items.Length); Assert.AreEqual(0, response.TotalCount); }