[Ignore] // TODO: fix tests
        public void CanLoginWithValidCredentials()
        {
            var authService = new Mock <IAuthenticationService>();
            var userService = new Mock <IUserService>();
            var logger      = new Mock <ILogger>();

            var viewModel = new LoginInput
            {
                Email      = "*****@*****.**",
                Password   = "******",
                RememberMe = false
            };

            var controller = new SessionsController(authService.Object, logger.Object);

            authService.Setup(s => s.Login(It.IsAny <Organization>(),
                                           "*****@*****.**", "secret", false)).Returns(true);
            userService.Setup(s => s.IsValidLogin(It.IsAny <Organization>(),
                                                  "*****@*****.**", "secret")).Returns(new User());

            var result = controller.Create(viewModel, "/admin");

            Assert.IsInstanceOfType(result, typeof(RedirectResult));
            Assert.AreEqual("/admin", ((RedirectResult)result).Url);
        }
        public async Task Should_Return_200_Status_Code_With_Valid_ViewModel()
        {
            // Arrange
            var data = new LoginViewModel()
            {
                Email    = "*****@*****.**",
                Password = "******"
            };

            var session = new SessionViewModel()
            {
                Id        = 1,
                Email     = "*****@*****.**",
                Token     = "JWTToken",
                ValidFrom = DateTime.Now,
                ValidTo   = DateTime.Today.AddDays(1),
            };

            adminAuthentication.Setup(obj => obj.AuthenticateAdmin(data))
            .ReturnsAsync(session);

            mapper.Setup(x => x.Map <SessionViewModel>(session))
            .Returns(new SessionViewModel()
            {
                Id        = session.Id,
                Email     = session.Email,
                Token     = session.Token,
                ValidFrom = session.ValidFrom,
                ValidTo   = session.ValidTo
            });

            var sessionsController = new SessionsController(
                adminAuthentication.Object,
                mapper.Object
                );

            // Act
            var response = await sessionsController.Create(data);

            // Assert
            Assert.NotNull(response);
            Assert.IsType <OkObjectResult>(response.Result);
        }
        public async Task Should_Throw_Exception_With_Invalid_ViewModel()
        {
            // Arrange
            var data = new LoginViewModel()
            {
                Email    = null,
                Password = null
            };

            var sessionsController = new SessionsController(
                adminAuthentication.Object,
                mapper.Object
                );

            // Act
            var response = await sessionsController.Create(data);

            // Assert
            Assert.NotNull(response);
            Assert.IsType <BadRequestObjectResult>(response.Result);
        }
        [Ignore] // TODO: fix tests
        public void CannotLoginWithInvalidCredentials()
        {
            var authService = new Mock <IAuthenticationService>();
            var logger      = new Mock <ILogger>();

            authService.Setup(s => s.Login(It.IsAny <Organization>(),
                                           "*****@*****.**", "badpw", false)).Returns(false);

            var viewModel = new LoginInput
            {
                Email      = "*****@*****.**",
                Password   = "******",
                RememberMe = false
            };

            var controller = new SessionsController(authService.Object, logger.Object);

            var result = controller.Create(viewModel, "/admin");

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.IsFalse(((ViewResult)result).ViewData.ModelState.IsValid);
        }