public async void ChangeQuestion_ValidObjectPassed_ReturnsOk() { // Arrange var mock = new Mock <IQuestionService>(); mock.Setup(s => s.UpdateAsync(It.IsAny <int>(), It.IsAny <QuestionDTO>())).Returns((int id, QuestionDTO s) => FakeServicesMethods.ChangeQuestion(id, s)); var controller = new QuestionController(mock.Object); // Act var question = new QuestionDTO { Id = 1, Title = "Question 1", QuestionText = "text", Comment = "", Answers = new List <AnswerDTO>() }; var result = await controller.ChangeQuestion(1, question); var okResult = result as OkObjectResult; // Assert Assert.NotNull(okResult); Assert.Equal(200, okResult.StatusCode); }
public async void ChangeQuestion_ValidObjectPassed_ReturnedResponseHaUpdatedItem() { // Arrange var mock = new Mock <IQuestionService>(); mock.Setup(s => s.UpdateAsync(It.IsAny <int>(), It.IsAny <QuestionDTO>())).Returns((int id, QuestionDTO s) => FakeServicesMethods.ChangeQuestion(id, s)); var controller = new QuestionController(mock.Object); // Act var question = new QuestionDTO { Id = 1, Title = "Question 1", QuestionText = "text", Comment = "", Answers = new List <AnswerDTO>() }; var result = await controller.ChangeQuestion(1, question); var okResult = result as OkObjectResult; // Assert var item = Assert.IsAssignableFrom <QuestionDTO>(okResult.Value); Assert.Equal(1, (okResult.Value as QuestionDTO)?.Id); }
public async void ChangeQuestion_InvalidObjectPassed_ReturnsBadRequest() { // Arrange var mock = new Mock <IQuestionService>(); mock.Setup(s => s.UpdateAsync(It.IsAny <int>(), It.IsAny <QuestionDTO>())).Returns((int id, QuestionDTO s) => FakeServicesMethods.ChangeQuestion(id, s)); var controller = new QuestionController(mock.Object); // Act var result = await controller.ChangeQuestion(1, null); var badRequestResult = result as BadRequestResult; // Assert Assert.NotNull(badRequestResult); Assert.Equal(400, badRequestResult.StatusCode); }