Exemple #1
0
        public void CanRegister_CanNotRegisterWithAlreadyUsedEmail()
        {
            AccountRegisterView view = ObjectFactory.CreateAccountRegisterView();

            view.Id += "DifferentValue";

            Assert.False(validator.CanRegister(view));
        }
Exemple #2
0
        public void CanRegister_CanNotRegisterWithAlreadyTakenUsername()
        {
            AccountRegisterView view = ObjectFactory.CreateAccountRegisterView();

            view.Username = view.Username.ToLower();
            view.Id      += "DifferentValue";

            Assert.False(validator.CanRegister(view));
        }
Exemple #3
0
        public void CanRegister_UsedEmail_ReturnsFalse()
        {
            AccountRegisterView view = ObjectFactory.CreateAccountRegisterView(2);

            view.Email = account.Email;

            Boolean canRegister = validator.CanRegister(view);

            Assert.False(canRegister);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validations.UniqueEmail, validator.ModelState["Email"].Errors.Single().ErrorMessage);
        }
Exemple #4
0
        public void CanRegister_UsedUsername_ReturnsFalse()
        {
            AccountRegisterView view = ObjectFactory.CreateAccountRegisterView(2);

            view.Username = account.Username.ToLower();

            Boolean canRegister = validator.CanRegister(view);

            Assert.False(canRegister);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validations.UniqueUsername, validator.ModelState["Username"].Errors.Single().ErrorMessage);
        }
Exemple #5
0
        public void CanRegister_AddsErrorMessageThenCanNotRegisterWithAlreadyUsedEmail()
        {
            AccountRegisterView view = ObjectFactory.CreateAccountRegisterView();

            view.Id += "DifferentValue";

            validator.CanRegister(view);

            String actual   = validator.ModelState["Email"].Errors[0].ErrorMessage;
            String expected = Validations.EmailIsAlreadyUsed;

            Assert.Equal(expected, actual);
        }
Exemple #6
0
        public void CanRegister_AddsErorrMessageThenCanNotRegisterWithAlreadyTakenUsername()
        {
            AccountRegisterView view = ObjectFactory.CreateAccountRegisterView();

            view.Username = view.Username.ToLower();
            view.Id      += "DifferentValue";

            validator.CanRegister(view);

            String actual   = validator.ModelState["Username"].Errors[0].ErrorMessage;
            String expected = Validations.UsernameIsAlreadyTaken;

            Assert.Equal(expected, actual);
        }
Exemple #7
0
        public void MapAccounts_MapsAccountRegisterViewToAccount()
        {
            AccountRegisterView expected = ObjectFactory.CreateAccountRegisterView();
            Account             actual   = Mapper.Map <Account>(expected);

            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.Equal(expected.Username, actual.Username);
            Assert.Null(actual.RecoveryTokenExpirationDate);
            Assert.Equal(expected.Email, actual.Email);
            Assert.Equal(expected.Id, actual.Id);
            Assert.Null(actual.RecoveryToken);
            Assert.False(actual.IsLocked);
            Assert.Null(actual.Passhash);
            Assert.Null(actual.RoleId);
            Assert.Null(actual.Role);
        }
Exemple #8
0
        public AuthControllerTests()
        {
            mailClient = Substitute.For <IMailClient>();
            service    = Substitute.For <IAccountService>();
            validator  = Substitute.For <IAccountValidator>();
            controller = Substitute.ForPartsOf <AuthController>(validator, service, mailClient);
            controller.ControllerContext.HttpContext = Substitute.For <HttpContext>();
            controller.TempData = Substitute.For <ITempDataDictionary>();
            controller.ControllerContext.RouteData = new RouteData();
            controller.Url = Substitute.For <IUrlHelper>();

            accountRegister = ObjectFactory.CreateAccountRegisterView();
            accountRecovery = ObjectFactory.CreateAccountRecoveryView();
            accountReset    = ObjectFactory.CreateAccountResetView();
            accountLogin    = ObjectFactory.CreateAccountLoginView();
        }
        public AuthControllerTests()
        {
            mailClient = Substitute.For <IMailClient>();
            service    = Substitute.For <IAccountService>();
            validator  = Substitute.For <IAccountValidator>();
            controller = Substitute.ForPartsOf <AuthController>(validator, service, mailClient);

            accountRegister = ObjectFactory.CreateAccountRegisterView();
            accountRecovery = ObjectFactory.CreateAccountRecoveryView();
            accountReset    = ObjectFactory.CreateAccountResetView();
            accountLogin    = ObjectFactory.CreateAccountLoginView();

            HttpContextBase httpContext = HttpContextFactory.CreateHttpContextBase();

            controller.Url = new UrlHelper(httpContext.Request.RequestContext);
            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = httpContext;
        }
Exemple #10
0
        public void Register_Account()
        {
            AccountRegisterView view = ObjectFactory.CreateAccountRegisterView(2);

            view.Email = view.Email.ToUpper();

            service.Register(view);

            Account             actual   = context.Set <Account>().AsNoTracking().Single(model => model.Id != account.Id);
            AccountRegisterView expected = view;

            Assert.Equal(hasher.HashPassword(expected.Password), actual.Passhash);
            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.Equal(expected.Email.ToLower(), actual.Email);
            Assert.Equal(expected.Username, actual.Username);
            Assert.Null(actual.RecoveryTokenExpirationDate);
            Assert.Null(actual.RecoveryToken);
            Assert.False(actual.IsLocked);
            Assert.Null(actual.RoleId);
            Assert.Null(actual.Role);
        }
Exemple #11
0
 public void CanRegister_ValidAccount()
 {
     Assert.True(validator.CanRegister(ObjectFactory.CreateAccountRegisterView(2)));
 }
Exemple #12
0
        public void CanRegister_InvalidState_ReturnsFalse()
        {
            validator.ModelState.AddModelError("Test", "Test");

            Assert.False(validator.CanRegister(ObjectFactory.CreateAccountRegisterView()));
        }
Exemple #13
0
        public void CanRegister_CanNotRegisterWithInvalidModelState()
        {
            validator.ModelState.AddModelError("Key", "Error");

            Assert.False(validator.CanRegister(ObjectFactory.CreateAccountRegisterView()));
        }