public void IndexReturnsARedirectToIndexHomeWhenIdIsNull()
        {
            var controller = new SessionController(sessionRepository:null);

            var result = Assert.IsType<RedirectToActionResult>(controller.Index(null));
            Assert.Equal("Home", result.ControllerName);
            Assert.Equal("Index", result.ActionName);
        }
        public void IndexReturnsContentWithSessionNotFoundWhenSessionNotFound()
        {
            var mockRepo = new Mock<IBrainstormSessionRepository>();
            int testSessionId = 1;
            mockRepo.Setup(r => r.GetById(testSessionId))
                .Returns((BrainstormSession)null);
            var controller = new SessionController(mockRepo.Object);

            var result = Assert.IsType<ContentResult>(controller.Index(testSessionId));
            Assert.Equal("Session not found.", result.Content);
        }
Exemple #3
0
        public async Task IndexReturnsARedirectToIndexHomeWhenIdIsNull()
        {
            // Arrange
            var controller = new SessionController(sessionRepository: null);

            // Act
            var result = await controller.Index(id: null);

            // Arrange
            var redirectToActionResult = Assert.IsType<RedirectToActionResult>(result);
            Assert.Equal("Home", redirectToActionResult.ControllerName);
            Assert.Equal("Index", redirectToActionResult.ActionName);
        }
        public void IndexReturnsViewResultWithStormSessionViewModel()
        {
            var mockRepo = new Mock<IBrainstormSessionRepository>();
            int testSessionId = 1;
            mockRepo.Setup(r => r.GetById(testSessionId))
                .Returns(GetTestSessions().FirstOrDefault(s => s.Id == testSessionId));
            var controller = new SessionController(mockRepo.Object);

            var result = Assert.IsType<ViewResult>(controller.Index(testSessionId));
            var model = Assert.IsType<StormSessionViewModel>(result.ViewData.Model);

            Assert.Equal("Test One", model.Name);
            Assert.Equal(2, model.DateCreated.Day);
            Assert.Equal(testSessionId, model.Id);
        }
Exemple #5
0
        public async Task IndexReturnsContentWithSessionNotFoundWhenSessionNotFound()
        {
            // Arrange
            int testSessionId = 1;
            var mockRepo = new Mock<IBrainstormSessionRepository>();
            mockRepo.Setup(repo => repo.GetByIdAsync(testSessionId))
                .Returns(Task.FromResult((BrainstormSession)null));
            var controller = new SessionController(mockRepo.Object);

            // Act
            var result = await controller.Index(testSessionId);

            // Assert
            var contentResult = Assert.IsType<ContentResult>(result);
            Assert.Equal("Session not found.", contentResult.Content);
        }
Exemple #6
0
        public async Task IndexReturnsViewResultWithStormSessionViewModel()
        {
            // Arrange
            int testSessionId = 1;
            var mockRepo = new Mock<IBrainstormSessionRepository>();
            mockRepo.Setup(repo => repo.GetByIdAsync(testSessionId))
                .Returns(Task.FromResult(GetTestSessions().FirstOrDefault(s => s.Id == testSessionId)));
            var controller = new SessionController(mockRepo.Object);

            // Act
            var result = await controller.Index(testSessionId);

            // Assert
            var viewResult = Assert.IsType<ViewResult>(result);
            var model = Assert.IsType<StormSessionViewModel>(viewResult.ViewData.Model);
            Assert.Equal("Test One", model.Name);
            Assert.Equal(2, model.DateCreated.Day);
            Assert.Equal(testSessionId, model.Id);
        }