public async Task TestQuestion1SavesCurrentName() { // Arrange var response = SurveyResponse.CreateNew(FakeNow); response.Respondent.Name = "Wrong name"; var clientStorage = Substitute.For <IClientSideStorageService>(); var dateTime = Substitute.For <IDateTimeService>(); var repo = Substitute.For <ISurveyResponseRepository>(); var controller = new SurveyController(clientStorage, dateTime, null, null, repo) { CurrentResponse = response }; var questionAnswer = new NameQuestionViewModel { Answer = ExcellentName }; // Act var result = await controller.Question1(questionAnswer); // Assert await repo.Received().SaveChanges(); Assert.IsType <RedirectToActionResult>(result); Assert.Equal(ExcellentName, controller.CurrentResponse.Respondent.Name); }
public void TestQuestion1ShowsCurrentName() { // Arrange var response = SurveyResponse.CreateNew(FakeNow); response.Respondent.Name = ExcellentName; var clientStorage = Substitute.For <IClientSideStorageService>(); var dateTime = Substitute.For <IDateTimeService>(); var repo = Substitute.For <ISurveyResponseRepository>(); var controller = new SurveyController(clientStorage, dateTime, null, null, repo) { CurrentResponse = response }; // Act var result = controller.Question1(); // Assert Assert.IsType <ViewResult>(result); var viewResult = result as ViewResult; Assert.IsType <QuestionPageViewModel <string> >(viewResult.Model); var model = viewResult.Model as QuestionPageViewModel <string>; Assert.Equal(ExcellentName, model.Question.Answer); }