Esempio n. 1
0
        public void FormControllerTemplateShouldReturnFormViewModel()
        {
            // Arrange
            var expectedSessionId = Guid.NewGuid();
            var session = new FillingSessionMother().GetBasicSession();
            var sessionId = session.Id;
            var template = new FormMother().GetBasicSurvey();
            var templateId = template.Id;

            // Setup Mock FormService
            var formServiceMock = new Mock<IFormService>(MockBehavior.Strict);
            formServiceMock.Setup(s => s.Get(templateId)).Returns(template);

            // Setup Mock FillingSessionService
            var fillingSessionServiceMock = new Mock<IFillingSessionService>(MockBehavior.Strict);
            fillingSessionServiceMock.Setup(s => s.Get(sessionId)).Returns(session);

            var controller = new FormController(formServiceMock.Object, fillingSessionServiceMock.Object);

            // Act
            var actual = controller.Template(templateId, sessionId) as ViewResult;
            var actualViewModel = actual.Model;

            // Assert
            Assert.IsNotNull(actual);
            Assert.IsNotNull(actualViewModel);
            Assert.IsInstanceOfType(actualViewModel, typeof(UserForm));
            formServiceMock.Verify(s => s.Get(templateId));
            fillingSessionServiceMock.Verify(s => s.Get(sessionId));
        }
Esempio n. 2
0
        public void FormControllerIndexActionRedirectsToHome()
        {
            // Arrange
            var expectedAction = "Index";
            var expectedController = "Home";
            var formServiceMock = new Mock<IFormService>(MockBehavior.Strict);
            var fillingSessionMock = new Mock<IFillingSessionService>(MockBehavior.Strict);
            var controller = new FormController(formServiceMock.Object, fillingSessionMock.Object);

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

            // Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(expectedAction, actual.RouteValues["action"].ToString());
            Assert.AreEqual(expectedController, actual.RouteValues["controller"].ToString());
        }
Esempio n. 3
0
        public void FormControllerUnknownTemplateShouldReturnException()
        {
            // Arrange
            var session = new FillingSessionMother().GetBasicSession();
            var sessionId = session.Id;
            var templateId = Guid.NewGuid();
            var formServiceMock = new Mock<IFormService>(MockBehavior.Strict);
            Form template = null;
            formServiceMock.Setup(f => f.Get(It.IsAny<Guid>())).Returns(template);
            var fillingSessionServiceMock = new Mock<IFillingSessionService>(MockBehavior.Strict);
            fillingSessionServiceMock.Setup(s => s.Get(sessionId)).Returns(session);
            var controller = new FormController(formServiceMock.Object, fillingSessionServiceMock.Object);

            // Act
            controller.Template(templateId, sessionId);
        }