Exemple #1
0
        public void CanEdit_Profile_InvalidState_ReturnsFalse()
        {
            validator.ModelState.AddModelError("Test", "Test");

            Assert.False(validator.CanEdit(ObjectsFactory.CreateProfileEditView(account.Id + 1)));
            Assert.Single(validator.ModelState);
        }
        public void CanEdit_Profile_ToSameEmail()
        {
            ProfileEditView view = ObjectsFactory.CreateProfileEditView(account.Id + 1);

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

            Assert.True(validator.CanEdit(view));
        }
Exemple #3
0
        public void CanEdit_Profile_ToSameUsername()
        {
            ProfileEditView view = ObjectsFactory.CreateProfileEditView();

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

            Assert.True(validator.CanEdit(view));
        }
Exemple #4
0
        public void CanEdit_Profile_IncorrectPassword_ReturnsFalse()
        {
            ProfileEditView view = ObjectsFactory.CreateProfileEditView();

            hasher.VerifyPassword(view.Password, Arg.Any <String>()).Returns(false);

            Boolean canEdit = validator.CanEdit(view);

            Assert.False(canEdit);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validation.For <AccountView>("IncorrectPassword"), validator.ModelState[nameof(ProfileEditView.Password)].Errors.Single().ErrorMessage);
        }
Exemple #5
0
        public ProfileTests()
        {
            service       = Substitute.For <IAccountService>();
            validator     = Substitute.For <IAccountValidator>();
            profileEdit   = ObjectsFactory.CreateProfileEditView(0);
            profileDelete = ObjectsFactory.CreateProfileDeleteView(0);
            controller    = Substitute.ForPartsOf <Profile>(validator, service);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            controller.Authorization.Returns(Substitute.For <IAuthorization>());
            controller.ControllerContext.RouteData = new RouteData();
        }
        public void Edit_NullOrEmptyNewPassword_DoesNotEditPassword(String newPassword)
        {
            ProfileEditView view = ObjectsFactory.CreateProfileEditView();

            view.NewPassword = newPassword;

            service.Edit(httpContext.User, view);

            String actual   = context.Set <Account>().AsNoTracking().Single().Passhash;
            String expected = account.Passhash;

            Assert.Equal(expected, actual);
        }
        public ProfileControllerTests()
        {
            validator = Substitute.For <IAccountValidator>();
            service   = Substitute.For <IAccountService>();

            profileDelete = ObjectsFactory.CreateProfileDeleteView();
            profileEdit   = ObjectsFactory.CreateProfileEditView();

            controller = Substitute.ForPartsOf <ProfileController>(validator, service);
            controller.ControllerContext.HttpContext = Substitute.For <HttpContext>();
            controller.TempData = Substitute.For <ITempDataDictionary>();
            controller.ControllerContext.RouteData = new RouteData();
            controller.Url = Substitute.For <IUrlHelper>();
            ReturnCurrentAccountId(controller, 1);
        }
Exemple #8
0
        public void CanEdit_Profile_UsedEmail_ReturnsFalse()
        {
            Account usedAccount = ObjectsFactory.CreateAccount(2);

            context.Add(usedAccount);
            context.SaveChanges();

            ProfileEditView view = ObjectsFactory.CreateProfileEditView();

            view.Email = usedAccount.Email;

            Boolean canEdit = validator.CanEdit(view);

            Assert.False(canEdit);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validation.For <AccountView>("UniqueEmail"), validator.ModelState[nameof(ProfileEditView.Email)].Errors.Single().ErrorMessage);
        }
        public void CanEdit_Profile_UsedUsername_ReturnsFalse()
        {
            Account usedAccount = ObjectsFactory.CreateAccount(1);

            context.Add(usedAccount);
            context.SaveChanges();

            ProfileEditView view = ObjectsFactory.CreateProfileEditView();

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

            Boolean canEdit = validator.CanEdit(view);

            Assert.False(canEdit);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validation.For <AccountView>("UniqueUsername"), validator.ModelState["Username"].Errors.Single().ErrorMessage);
        }
        public void Edit_UpdatesClaims()
        {
            httpContext.User.AddIdentity(new ClaimsIdentity(new[]
            {
                new Claim(ClaimTypes.Email, "*****@*****.**"),
                new Claim(ClaimTypes.Name, "TestName")
            }));

            ProfileEditView view = ObjectsFactory.CreateProfileEditView();

            view.Username = account.Username += "Test";
            view.Email    = account.Email += "Test";

            service.Edit(httpContext.User, view);

            Account         expected = account;
            ClaimsPrincipal actual   = httpContext.User;

            Assert.Equal(expected.Username, actual.FindFirst(ClaimTypes.Name).Value);
            Assert.Equal(expected.Email.ToLower(), actual.FindFirst(ClaimTypes.Email).Value);
        }
        public void Edit_Profile()
        {
            ProfileEditView view = ObjectsFactory.CreateProfileEditView();

            account.Passhash = hasher.HashPassword(view.NewPassword !);
            view.Username    = account.Username += "Test";
            view.Email       = account.Email += "Test";

            service.Edit(httpContext.User, view);

            Account actual   = context.Set <Account>().AsNoTracking().Single();
            Account expected = account;

            Assert.Equal(expected.RecoveryTokenExpirationDate, actual.RecoveryTokenExpirationDate);
            Assert.Equal(expected.RecoveryToken, actual.RecoveryToken);
            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.Equal(expected.Email.ToLower(), actual.Email);
            Assert.Equal(expected.IsLocked, actual.IsLocked);
            Assert.Equal(expected.Username, actual.Username);
            Assert.Equal(expected.Passhash, actual.Passhash);
            Assert.Equal(expected.RoleId, actual.RoleId);
            Assert.Equal(expected.Id, actual.Id);
        }
 public void CanEdit_ValidProfile()
 {
     Assert.True(validator.CanEdit(ObjectsFactory.CreateProfileEditView(account.Id + 1)));
     Assert.Empty(validator.ModelState);
     Assert.Empty(validator.Alerts);
 }