public void CreateHttpGet_PassesAllFormulasToView()
        {
            var result   = _sessionController.Create() as ViewResult;
            var formulas = result?.ViewData["formulas"] as SelectList;

            Assert.Equal(_dummyContext.Formulas.Count(), formulas.Count());
        }
        public void GivenAnInvalidEMail_WhenILogin_ThenIGetRedirectedToTheRegistrationPage()
        {
            _sessionController.ModelState.AddModelError("error", "message");

            var result = _sessionController.Create(new LoginUserViewModel(), string.Empty) as ViewResult;

            result.Should().NotBeNull();
            result.ViewName.Should().Be("New");
        }
Beispiel #3
0
        public void Create()
        {
            var data = new SessionCreateVM();

            var mockSetFilm = new Mock <DbSet <Film> >().SetupData(new List <Film>()
            {
                new Film()
                {
                    ID   = 1,
                    Name = "test"
                }
            });

            var mockSet = new Mock <DbSet <Session> >();
            var context = new Mock <EFContext>();

            context.Setup(x => x.SaveChanges()).Returns(() => 1);
            context.Setup(m => m.Sessions).Returns(mockSet.Object);
            context.Setup(m => m.Films).Returns(mockSetFilm.Object);
            var controller = new SessionController(context.Object);

            controller.ValidateRequest = true;

            //empty model
            var result = controller.Create(data) as ViewResult;

            Assert.AreEqual(null, result.ViewBag.SuccessResult);

            //invalid film & starting date yesterday
            controller.ModelState.Clear();
            data.FilmID       = 20;
            data.StartingDate = DateTime.Now.AddDays(-1);

            result = controller.Create(data) as ViewResult;
            Assert.AreEqual(null, result.ViewBag.SuccessResult);

            //success
            controller.ModelState.Clear();
            data.FilmID       = 1;
            data.StartingDate = DateTime.Now;
            result            = controller.Create(data) as ViewResult;

            Assert.AreNotEqual(null, result.ViewBag.SuccessResult);
        }
Beispiel #4
0
        public void GivenAMatchingPassword_WhenILogin_ThenIGetRedirectedToTheAdminPage()
        {
            string password = "******";

            _userDomain.Setup(u => u.GetUser("*****@*****.**")).Returns(new User {
                Password = password
            });
            var result =
                _sessionController.Create(new LoginUserViewModel {
                Email = "*****@*****.**", Password = password
            }) as
                RedirectToRouteResult;

            Assert.That(result, Is.Not.Null);
            Assert.That(result.RouteValues["controller"], Is.EqualTo("Dashboard").IgnoreCase);
            Assert.That(result.RouteValues["action"], Is.EqualTo("Index"));
        }
Beispiel #5
0
        public async Task Create_given_dto_creates_session()
        {
            var output      = new SessionDTO();
            var sessionRepo = new Mock <ISessionRepository>();

            sessionRepo.Setup(s => s.CreateAsync(It.IsAny <SessionCreateUpdateDTO>())).ReturnsAsync(output);
            var controller = new SessionController(sessionRepo.Object, null, null);
            var input      = new SessionCreateUpdateDTO();
            await controller.Create(input);

            sessionRepo.Verify(s => s.CreateAsync(input));
        }
Beispiel #6
0
            public void WhenTheSessionIsCreated_ThenTheUserIsRegistered()
            {
                const string userName = "******";
                const string password = "******";

                var controller = new SessionController(_userService.Object, _configurationManager.Object, _logger.Object);

                SetControllerContext(controller);

                controller.Create(new LogonViewModel { Email = userName, Password = password });
                _userService.Verify(u => u.Logon(userName, password), Times.Once());
            }
Beispiel #7
0
            public void WhenTheSessionIsCreated_ThenTheUserIsNotAuthenticated()
            {
                const string userName = "******";
                const string password = "******";

                var controller = new SessionController(_userService.Object, _configurationManager.Object, _logger.Object);

                SetControllerContext(controller);

                var view = (JsonResult)controller.Create(new LogonViewModel { Email = userName, Password = password });
                var model = (UserViewModel)view.Data;
                model.IsAuthenticated.Should().BeFalse();
            }
Beispiel #8
0
        public async Task Create_given_dto_returns_CreatedAtActionResult()
        {
            var input  = new SessionCreateUpdateDTO();
            var output = new SessionDTO {
                Id = 42, SessionKey = "ABC1234"
            };
            var sessionRepo = new Mock <ISessionRepository>();

            sessionRepo.Setup(s => s.CreateAsync(input)).ReturnsAsync(output);
            var controller = new SessionController(sessionRepo.Object, null, null);
            var post       = await controller.Create(input);

            var result = post.Value;

            Assert.Equal("ABC1234", result.SessionKey);
            Assert.Equal(42, result.Id);
        }
Beispiel #9
0
        public void Create_ValidSession_RedirectsToSessionIndex()
        {
            int day = ((int)DateTime.Now.DayOfWeek == 0) ? 7 : (int)DateTime.Now.DayOfWeek;

            _formulaRepository.Setup(m => m.GetByWeekDay(day)).Returns(_dummyContext.Formulas);
            _sessionRepository.Setup(m => m.GetLatest()).Returns(_dummyContext.SessionLastWeek);

            RedirectToActionResult action = _controller.Create() as RedirectToActionResult;

            Assert.Equal("Index", action?.ActionName);
            Assert.Equal("Session", action?.ControllerName);
        }