public async void ChangeSurvey_ValidObjectPassed_ReturnsOk() { // Arrange var mock = new Mock <ISurveyService>(); mock.Setup(s => s.UpdateAsync(It.IsAny <int>(), It.IsAny <SurveyDTO>())).Returns((int id, SurveyDTO s) => FakeServicesMethods.ChangeSurvey(id, s)); var controller = new SurveyController(mock.Object); // Act var survey = new SurveyDTO { Id = 1, Creator = "John", Date = DateTime.Now, Views = 3, Title = "Survey 1", Questions = new List <QuestionDTO>() }; var result = await controller.ChangeSurvey(1, survey); var okResult = result as OkObjectResult; // Assert Assert.NotNull(okResult); Assert.Equal(200, okResult.StatusCode); }
public async void ChangeSurvey_ValidObjectPassed_ReturnedResponseHaUpdatedItem() { // Arrange var mock = new Mock <ISurveyService>(); mock.Setup(s => s.UpdateAsync(It.IsAny <int>(), It.IsAny <SurveyDTO>())).Returns((int id, SurveyDTO s) => FakeServicesMethods.ChangeSurvey(id, s)); var controller = new SurveyController(mock.Object); // Act var survey = new SurveyDTO { Id = 1, Creator = "John", Date = DateTime.Now, Views = 3, Title = "Survey 1", Questions = new List <QuestionDTO>() }; var result = await controller.ChangeSurvey(1, survey); var okResult = result as OkObjectResult; // Assert var item = Assert.IsAssignableFrom <SurveyDTO>(okResult.Value); Assert.Equal(1, (okResult.Value as SurveyDTO)?.Id); }
public async void ChangeSurvey_InvalidObjectPassed_ReturnsBadRequest() { // Arrange var mock = new Mock <ISurveyService>(); mock.Setup(s => s.UpdateAsync(It.IsAny <int>(), It.IsAny <SurveyDTO>())).Returns((int id, SurveyDTO s) => FakeServicesMethods.ChangeSurvey(id, s)); var controller = new SurveyController(mock.Object); // Act var result = await controller.ChangeSurvey(1, null); var badRequestResult = result as BadRequestResult; // Assert Assert.NotNull(badRequestResult); Assert.Equal(400, badRequestResult.StatusCode); }