public void RedirectToStartTestPhase_WhenStartIsCalled() { // Arrange var expectedModels = TestDatas.GetFakeTestPhaseModels(); string expectedRedirectAction = "StartTestPhase"; var mockSessionStorage = new Mock <ISessionStorage>(); mockSessionStorage .Setup(x => x.GetObjectFromJson <List <TestPhaseModel> >(It.IsAny <string>())) .Returns(expectedModels); var mockColorProvider = new Mock <IColorProvider>(); var settings = new StroopTestSettings(); var controller = new StroopTestController(mockSessionStorage.Object, mockColorProvider.Object, settings); // Act var actual = controller.Start(); // Assert var redirectResult = Assert.IsType <RedirectToActionResult>(actual); Assert.Null(redirectResult.ControllerName); Assert.Equal(expectedRedirectAction, redirectResult.ActionName); mockSessionStorage.Verify(x => x.GetObjectFromJson <List <TestPhaseModel> >(It.IsAny <string>()), Times.Once); }
public void UpdateModelInSession_ThenRedirectToNextStep_WhenGoToNextStepIsCalled() { // Arrange var postedModel = new StepModel() { PhaseNumber = 1, StepNumber = 1, ElapsedTime = 1000, SameColor = true, }; var expectedModel = TestDatas.GetFakeTestPhaseModels(); var mockSessionStorage = new Mock <ISessionStorage>(); mockSessionStorage .Setup(x => x.GetObjectFromJson <List <TestPhaseModel> >(It.IsAny <string>())) .Returns(expectedModel); mockSessionStorage .Setup(x => x.SetObjectAsJson(It.IsAny <string>(), It.IsAny <List <TestPhaseModel> >())); mockSessionStorage .Setup(x => x.SetString(It.IsAny <string>(), It.IsAny <string>())); var mockColorProvider = new Mock <IColorProvider>(); var settings = new StroopTestSettings(); var controller = new StroopTestController(mockSessionStorage.Object, mockColorProvider.Object, settings); // Act var actual = controller.GoToNextStep(postedModel); // Assert var redirectResult = Assert.IsType <RedirectToActionResult>(actual); Assert.Null(redirectResult.ControllerName); Assert.Equal("NextStep", redirectResult.ActionName); mockSessionStorage.Verify(x => x.GetObjectFromJson <List <TestPhaseModel> >(It.IsAny <string>()), Times.Once); mockSessionStorage.Verify(x => x.SetObjectAsJson(It.IsAny <string>(), It.IsAny <List <TestPhaseModel> >()), Times.Once); mockSessionStorage.Verify(x => x.SetString(StroopTestController.SESSION_STEP_NUMBER_KEY, It.IsAny <string>()), Times.Once); }
public void ReturnAViewResult_WhenNextStepIsCalled(int phaseNumber, int stepNumber, int expectedPhaseNumber, int expectedStepNumber) { // Arrange var expectedColorModel = new ColorsModel() { ColorAsHex = "#FF0000", ColorAsWord = Color.BLUE }; var expectedModels = TestDatas.GetFakeTestPhaseModels(); var mockSessionStorage = new Mock <ISessionStorage>(); mockSessionStorage .Setup(x => x.GetObjectFromJson <List <TestPhaseModel> >(It.IsAny <string>())) .Returns(expectedModels); mockSessionStorage .Setup(x => x.GetString(StroopTestController.SESSION_PHASE_NUMBER_KEY)) .Returns(phaseNumber.ToString()); mockSessionStorage .Setup(x => x.GetString(StroopTestController.SESSION_STEP_NUMBER_KEY)) .Returns(stepNumber.ToString()); var mockColorProvider = new Mock <IColorProvider>(); var settings = new StroopTestSettings(); var controller = new StroopTestController(mockSessionStorage.Object, mockColorProvider.Object, settings); // Act var actual = controller.NextStep(); // Assert var viewResult = Assert.IsType <ViewResult>(actual); var model = Assert.IsType <StepModel>(viewResult.ViewData.Model); Assert.Equal(expectedPhaseNumber, model.PhaseNumber); Assert.Equal(expectedStepNumber, model.StepNumber); }
public void ReturnAViewResult_WhenFinishIsCalled() { // Arrange var expectedModels = TestDatas.GetFakeTestPhaseModels(); var expectedCongruentsWords = expectedModels .Where(x => 1.Equals(x.PhaseNumber)) .SelectMany(x => x.StepModels) .ToList(); var expectedIncongruentsWords = expectedModels .Where(x => 2.Equals(x.PhaseNumber)) .SelectMany(x => x.StepModels) .ToList(); var mockSessionStorage = new Mock <ISessionStorage>(); mockSessionStorage .Setup(x => x.GetObjectFromJson <List <TestPhaseModel> >(It.IsAny <string>())) .Returns(expectedModels); var mockColorProvider = new Mock <IColorProvider>(); var settings = new StroopTestSettings(); var controller = new StroopTestController(mockSessionStorage.Object, mockColorProvider.Object, settings); // Act var actual = controller.Finish(); // Assert var viewResult = Assert.IsType <ViewResult>(actual); Assert.IsType <ResultsModel>(viewResult.ViewData.Model); var models = viewResult.ViewData.Model as ResultsModel; Assert.Equal(expectedCongruentsWords.Count(), models.CongruentWords.Results.Count); Assert.Equal(expectedIncongruentsWords.Count(), models.IncongruentWords.Results.Count); }