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)); }
public void FillControllerIndexWithIdShouldRedirectToFillingForm() { // Arrange var expectedAction = "Template"; var expectedController = "Form"; var expectedFormId = Guid.NewGuid(); // Setup Mock Session Service var sessionServiceMock = new FillingSessionServiceMother().GetMockedService(); var session = new FillingSessionMother().GetBasicSession(); var expectedSessionId = session.Id; sessionServiceMock.Setup(s => s.StartNewSession()).Returns(session); var controller = new FillController(sessionServiceMock.Object); // Act var actual = controller.Index(expectedFormId) as RedirectToRouteResult; // Assert Assert.IsNotNull(actual); Assert.AreEqual(expectedAction, actual.RouteValues["action"].ToString()); Assert.AreEqual(expectedController, actual.RouteValues["controller"].ToString()); Assert.AreEqual(expectedFormId, actual.RouteValues["formId"]); Assert.AreEqual(expectedSessionId, actual.RouteValues["sid"]); sessionServiceMock.Verify(s => s.StartNewSession()); }
public void FillingSessionServiceGetShouldReturnSession() { var unitOfWorkMock = new Mock<IUnitOfWork>(MockBehavior.Strict); var session = new FillingSessionMother().GetBasicSession(); var sessionId = session.Id; unitOfWorkMock.Setup(u => u.Query<FillingSession>()).Returns(new[] { session }.AsQueryable()); unitOfWorkMock.Setup(u => u.Commit()); var service = new FillingSessionService(unitOfWorkMock.Object); // Act var actual = service.Get(sessionId); // Assert Assert.IsNotNull(actual); Assert.IsInstanceOfType(actual, typeof(FillingSession)); Assert.AreNotEqual(Guid.Empty, actual.Id); unitOfWorkMock.Verify(u => u.Query<FillingSession>()); }
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); }