예제 #1
0
        public async Task testPostRegisterUserAlreadyExists()
        {
            DriverRegisterViewModel model = new DriverRegisterViewModel();

            model.Email     = Constants.DEFAULT_EMAIL;
            model.Password  = Constants.DEFAULT_PASSWORD;
            model.FirstName = "Matt";

            var           controller      = ControllerSupplier.getAccountController();
            var           mockUserService = new Mock <IUserService>();
            IdentityError error           = new IdentityError();

            error.Code        = "user exists";
            error.Description = "user exists";
            IdentityResult identityResult = IdentityResult.Failed(error);

            mockUserService.Setup(m => m.CreateDriverUserAsync(model)).Returns(Task.FromResult <IdentityResult>(identityResult));
            controller.userService = mockUserService.Object;
            var result = (ViewResult)await controller.Register(model);

            Assert.Equal(result.Model, model);
            Assert.True(controller.ViewData.ModelState.ErrorCount == 1);
            var allErrors = controller.ModelState.Values.SelectMany(v => v.Errors);

            Assert.True(allErrors.First().ErrorMessage.Contains(error.Description));
        }
예제 #2
0
        public async Task testPostLoginIncorrectPassword()
        {
            LoginViewModel model = new LoginViewModel();

            model.Email    = Constants.DEFAULT_EMAIL;
            model.Password = "******";
            var controller = ControllerSupplier.getAccountController();

            await populateDatabaseWithUser(controller);

            var userManager = controller.getUserManager();
            var user        = await userManager.FindByIdAsync(Constants.USER_ID);

            var code = await userManager.GenerateEmailConfirmationTokenAsync(user);

            await userManager.ConfirmEmailAsync(user, code);

            var result = (ViewResult)await controller.Login(model);

            Assert.NotEmpty(controller.ViewData.ModelState.Keys);
            var allErrors = controller.ModelState.Values.SelectMany(v => v.Errors);

            Assert.Equal(allErrors.First().ErrorMessage, "Invalid login attempt.");
            Assert.Equal(result.Model, model);
        }
예제 #3
0
        public async Task testPostLoginSuccessWhenLoginFromHomeDriverRole()
        {
            LoginViewModel model = new LoginViewModel();

            model.Email    = Constants.DEFAULT_EMAIL;
            model.Password = Constants.DEFAULT_PASSWORD;
            var controller = ControllerSupplier.getAccountController();

            await populateDatabaseWithUser(controller);

            var userManager = controller.getUserManager();
            var user        = await userManager.FindByIdAsync(Constants.USER_ID);

            var code = await userManager.GenerateEmailConfirmationTokenAsync(user);

            await userManager.ConfirmEmailAsync(user, code);

            await userManager.AddToRoleAsync(user, AppRole.DRIVER);

            var result = await controller.Login(model, "Login") as RedirectToActionResult;

            Assert.NotNull(result);
            Assert.Equal(result.ControllerName, "DriverDashboard");
            Assert.Equal(result.ActionName, "Index");
        }
예제 #4
0
        public void testGetResetPasswod()
        {
            var controller = ControllerSupplier.getAccountController();
            var result     = controller.ResetPassword("123");
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Null(viewResult.Model);
            Assert.Equal(viewResult.ViewName, "ResetPassword");
        }
예제 #5
0
        // [Fact]
        public async Task testPostRegisterSuccess()
        {
            DriverRegisterViewModel model = new DriverRegisterViewModel();

            model.Email    = "*****@*****.**";
            model.Password = "******";
            var controller = ControllerSupplier.getAccountController();
            var result     = (ViewResult)await controller.Register(model);
        }
예제 #6
0
        public void testGetLogin()
        {
            var controller = ControllerSupplier.getAccountController();
            var result     = controller.Login("return/url");
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Equal(viewResult.ViewData["ReturnUrl"], "return/url");
            Assert.Null(viewResult.Model);
            Assert.Equal(viewResult.ViewName, "Login");
        }
예제 #7
0
        public async Task testPostRegisterInvalidModel()
        {
            DriverRegisterViewModel model = new DriverRegisterViewModel();
            var controller = ControllerSupplier.getAccountController();

            controller.ViewData.ModelState.AddModelError("Key", "ErrorMessage");
            var result = (ViewResult)await controller.Register(model);

            Assert.Equal(result.Model, model);
        }
예제 #8
0
        public async Task testGetConfimEmailWithNullConfirmCode()
        {
            var controller = ControllerSupplier.getAccountController();
            var result     = await controller.ConfirmEmail(Constants.USER_ID, null);

            Assert.NotNull(result);
            var viewName = ((ViewResult)result).ViewName;

            Assert.Equal(viewName, "Error");
        }
예제 #9
0
        public async Task testResetPasswordInvalidModelState()
        {
            ForgotPasswordViewModel model = new ForgotPasswordViewModel();
            var controller = ControllerSupplier.getAccountController();

            controller.ViewData.ModelState.AddModelError("Key", "ErrorMessage");
            var result = (ViewResult)await controller.ForgotPassword(model);

            Assert.Equal(result.Model, model);
        }
예제 #10
0
        public async Task testPostResetPasswordUserIsNull()
        {
            ForgotPasswordViewModel model = new ForgotPasswordViewModel();

            model.Email = "*****@*****.**";
            var controller = ControllerSupplier.getAccountController();
            var result     = await controller.ForgotPassword(model) as ViewResult;

            Assert.Equal(result.ViewName, "ForgotPasswordConfirmation");
        }
예제 #11
0
        public async Task testPostLoginAttemptWithInvalidModel()
        {
            LoginViewModel model      = new LoginViewModel();
            var            controller = ControllerSupplier.getAccountController();

            controller.ViewData.ModelState.AddModelError("Key", "ErrorMessage");
            var result = (ViewResult)await controller.Login(model);

            Assert.Equal(result.Model, model);
        }
예제 #12
0
        public void testGetRegister()
        {
            var controller = ControllerSupplier.getAccountController();
            var result     = controller.Register("return/url");
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Equal(viewResult.ViewData["ReturnUrl"], "return/url");
            Assert.Equal(viewResult.Model.GetType(), typeof(DriverRegisterViewModel));
            Assert.Equal(viewResult.ViewName, "Register");
        }
예제 #13
0
        public async Task testGetConfimEmailWithNullUserId()
        {
            var controller = ControllerSupplier.getAccountController();
            var result     = await controller.ConfirmEmail(null, Constants.CONFIRM_CODE);

            Assert.NotNull(result);
            var viewName = ((ViewResult)result).ViewName;

            Assert.Equal(viewName, "Error");
        }
예제 #14
0
        public async Task testGetConfirmEmailForExistingUserWithWrongCode()
        {
            var controller = ControllerSupplier.getAccountController();

            await populateDatabaseWithUser(controller);

            var result = await controller.ConfirmEmail(Constants.USER_ID, "123");

            Assert.NotNull(result);
            var viewName = ((ViewResult)result).ViewName;

            Assert.Equal(viewName, "Error");
        }
예제 #15
0
        public async Task testPostLoginUnknownUser()
        {
            LoginViewModel model = new LoginViewModel();

            model.Email    = Constants.DEFAULT_EMAIL;
            model.Password = Constants.DEFAULT_PASSWORD;
            var controller = ControllerSupplier.getAccountController();
            var result     = (ViewResult)await controller.Login(model);

            Assert.NotEmpty(controller.ViewData.ModelState.Values);
            var allErrors = controller.ModelState.Values.SelectMany(v => v.Errors);

            Assert.Equal(allErrors.First().ErrorMessage, "Invalid login attempt.");
            Assert.Equal(result.Model, model);
        }
예제 #16
0
        public async Task testPostLoginEmailNotConfirmed()
        {
            LoginViewModel model = new LoginViewModel();

            model.Email    = Constants.DEFAULT_EMAIL;
            model.Password = Constants.DEFAULT_PASSWORD;
            var controller = ControllerSupplier.getAccountController();

            await populateDatabaseWithUser(controller);

            var result = (ViewResult)await controller.Login(model);

            Assert.NotEmpty(controller.ViewData.ModelState.Keys);
            var allErrors = controller.ModelState.Values.SelectMany(v => v.Errors);

            Assert.Equal(allErrors.First().ErrorMessage, "You must have a confirmed email to log in.");
            Assert.Equal(result.Model, model);
        }
예제 #17
0
        public void testGetRegisterDriver()
        {
            var    controller = ControllerSupplier.getAccountController();
            string email      = "*****@*****.**";
            string firstName  = "Alex";
            var    result     = controller.RegisterDriver(1, email, firstName, "url");
            var    viewResult = Assert.IsType <ViewResult>(result);

            Assert.Equal(viewResult.ViewData["ReturnUrl"], "url");
            Assert.Equal(viewResult.Model.GetType(), typeof(DriverRegisterViewModel));
            Assert.Equal(viewResult.ViewName, "Register");

            var model = (DriverRegisterViewModel)viewResult.Model;

            Assert.Equal(model.DriverTeamId, "1");
            Assert.Equal(model.FirstName, firstName);
            Assert.Equal(model.Email, email);
        }
예제 #18
0
        public async Task testPostLogOff()
        {
            var controller = ControllerSupplier.getAccountController();

            await populateDatabaseWithUser(controller);

            //sign in a user
            var userManager = controller.getUserManager();
            var user        = await userManager.FindByEmailAsync(Constants.DEFAULT_EMAIL);

            var signInManager = controller.getSignInManager();
            await signInManager.PasswordSignInAsync(user.Email, Constants.DEFAULT_PASSWORD, false, lockoutOnFailure : false);

            var result = await controller.LogOff() as RedirectToActionResult;

            Assert.NotNull(result);
            Assert.Equal(result.ControllerName, "Home");
            Assert.Equal(result.ActionName, "Index");
        }
예제 #19
0
        public async Task testPostRegisterUserFailureInvalidPassword()
        {
            DriverRegisterViewModel model = new DriverRegisterViewModel();

            model.Email    = "*****@*****.**";
            model.Password = "******";
            var           controller      = ControllerSupplier.getAccountController();
            var           mockUserService = new Mock <IUserService>();
            IdentityError error           = new IdentityError();

            error.Code        = "invalid password";
            error.Description = "invalid password";
            IdentityResult identityResult = IdentityResult.Failed(error);

            mockUserService.Setup(m => m.CreateDriverUserAsync(model)).Returns(Task.FromResult <IdentityResult>(identityResult));
            controller.userService = mockUserService.Object;
            var result = (ViewResult)await controller.Register(model);

            Assert.Equal(result.Model, model);
            var allErrors = controller.ModelState.Values.SelectMany(v => v.Errors);

            Assert.True(allErrors.First().ErrorMessage.Contains(error.Description));
        }
예제 #20
0
        public async Task testGetConfirmEmailForExistingUserShipperRole()
        {
            var controller = ControllerSupplier.getAccountController();

            await populateDatabaseWithUser(controller);

            var userManager = controller.getUserManager();

            var user = await userManager.FindByIdAsync(Constants.USER_ID);

            await userManager.AddToRoleAsync(user, AppRole.SHIPPER);

            var code = await userManager.GenerateEmailConfirmationTokenAsync(user);

            var result = await controller.ConfirmEmail(Constants.USER_ID, code);

            Assert.NotNull(result);
            var viewName = ((ViewResult)result).ViewName;

            Assert.Equal(viewName, "ConfirmEmail");
            var dbContext = controller.getApplicationContext();

            Assert.Equal(dbContext.Drivers.ToList <Driver>().Count, 0);
        }