Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public void RedirectToFinish_WhenNextStepIsCalled()
        {
            // Arrange
            int    phaseNumber            = 2;
            int    stepNumber             = 20;
            string expectedRedirectAction = "Finish";

            var mockSessionStorage = new Mock <ISessionStorage>();

            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 redirectResult = Assert.IsType <RedirectToActionResult>(actual);

            Assert.Null(redirectResult.ControllerName);
            Assert.Equal(expectedRedirectAction, redirectResult.ActionName);
        }
Exemplo n.º 3
0
        public void ReturnAViewResult_WhenStartTestPhaseIsCalled(int phaseNumber, string expectedPhaseTitle, string expectedPhaseInfos, int expectedPhaseNumber)
        {
            // Arrange
            var mockSessionStorage = new Mock <ISessionStorage>();

            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.StartTestPhase(phaseNumber);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(actual);

            Assert.Equal(expectedPhaseTitle, viewResult.ViewData["PhaseTitle"]);
            Assert.Equal(expectedPhaseInfos, viewResult.ViewData["PhaseInfos"]);
            Assert.Equal(expectedPhaseNumber, viewResult.ViewData["PhaseNumber"]);

            mockSessionStorage.Verify(x => x.SetString(StroopTestController.SESSION_PHASE_NUMBER_KEY, It.IsAny <string>()), Times.Once);
            mockSessionStorage.Verify(x => x.SetString(StroopTestController.SESSION_STEP_NUMBER_KEY, It.IsAny <string>()), Times.Once);
        }
Exemplo n.º 4
0
        public void ReturnAViewResult_WhenIndexIsCalled()
        {
            // Arrange
            var mockSessionStorage = new Mock <ISessionStorage>();
            var mockColorProvider  = new Mock <IColorProvider>();
            var settings           = new StroopTestSettings();

            var controller = new StroopTestController(mockSessionStorage.Object, mockColorProvider.Object, settings);

            // Act
            var actual = controller.Index();

            // Assert
            Assert.IsType <ViewResult>(actual);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        public void StoreColorsModels_WhenStartIsCalled()
        {
            // Arrange
            List <TestPhaseModel> model = new List <TestPhaseModel>();

            var mockSessionStorage = new Mock <ISessionStorage>();

            mockSessionStorage
            .Setup(x => x.GetObjectFromJson <List <TestPhaseModel> >(It.IsAny <string>()))
            .Returns(model);

            var mockColorProvider = new Mock <IColorProvider>();

            var settings = new StroopTestSettings();

            var controller = new StroopTestController(mockSessionStorage.Object, mockColorProvider.Object, settings);

            // Act
            var actual = controller.Start();

            // Assert
            mockColorProvider.Verify(x => x.GetCongruentColor(), Times.Exactly(20));
            mockColorProvider.Verify(x => x.GetIncongruentColor(), Times.Exactly(20));

            mockSessionStorage.Verify(x => x.GetObjectFromJson <List <TestPhaseModel> >(It.IsAny <string>()), Times.Once);

            Assert.Equal(2, model.Count);

            var modelPhase1 = model[0];

            Assert.Equal(1, modelPhase1.PhaseNumber);
            Assert.Equal(20, modelPhase1.StepModels.Count);

            var modelPhase2 = model[1];

            Assert.Equal(2, modelPhase2.PhaseNumber);
            Assert.Equal(20, modelPhase2.StepModels.Count);
        }
Exemplo n.º 8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <ISessionStorage, SessionStorage>();
            services.AddSingleton <IColorProvider, ColorProvider>();
            services.AddSingleton <IColorRepository, ColorRepository>();
            services.AddSingleton <IRandomGenerator, RandomGenerator>();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();


            var config = new StroopTestSettings();

            Configuration.Bind("TestSettings", config);
            services.AddSingleton(config);

            // services.Configure<StroopTestSettings>(
            //     Configuration.GetSection("TestSettings"));

            services.AddMvc()
            .AddSessionStateTempDataProvider();

            services.AddDistributedMemoryCache();
            services.AddSession();
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
 public StroopTestController(ISessionStorage sessionStorage, IColorProvider colorProvider, StroopTestSettings settings)
 {
     _sessionStorage = sessionStorage;
     _colorProvider  = colorProvider;
     _settings       = settings;
 }