public AccountValidatorTests() { context = TestingContext.Create(); hasher = Substitute.For <IHasher>(); hasher.VerifyPassword(Arg.Any <String>(), Arg.Any <String>()).Returns(true); validator = new AccountValidator(new UnitOfWork(TestingContext.Create(), TestingContext.Mapper), hasher); context.Drop().Add(account = ObjectsFactory.CreateAccount(0)); context.SaveChanges(); }
public AccountServiceTests() { context = TestingContext.Create(); hasher = Substitute.For <IHasher>(); httpContext = new DefaultHttpContext(); service = new AccountService(new UnitOfWork(TestingContext.Create(), TestingContext.Mapper), hasher); hasher.HashPassword(Arg.Any <String>()).Returns(info => $"{info.Arg<String>()}Hashed"); context.Drop().Add(account = ObjectsFactory.CreateAccount(0)); context.SaveChanges(); }
public AccountValidatorTests() { context = new TestingContext(); hasher = Substitute.For <IHasher>(); hasher.VerifyPassword(Arg.Any <String>(), Arg.Any <String>()).Returns(true); validator = new AccountValidator(new UnitOfWork(new TestingContext(context)), hasher); context.Add(account = ObjectsFactory.CreateAccount()); context.SaveChanges(); validator.CurrentAccountId = account.Id; }
public AccountServiceTests() { context = new TestingContext(); hasher = Substitute.For <IHasher>(); service = new AccountService(new UnitOfWork(context), hasher); hasher.HashPassword(Arg.Any <String>()).Returns(info => info.Arg <String>() + "Hashed"); context.Add(account = ObjectsFactory.CreateAccount()); context.SaveChanges(); service.CurrentAccountId = account.Id; }
public void Delete_NullsAccountRoles() { Account account = ObjectsFactory.CreateAccount(0); account.RoleId = role.Id; account.Role = null; context.Add(account); context.SaveChanges(); service.Delete(role.Id); Assert.Contains(context.Set <Account>().AsNoTracking(), model => model.Id == account.Id && model.RoleId == null); }
public void Delete_NullsAccountRoles() { Account account = ObjectsFactory.CreateAccount(); account.RoleId = role.Id; account.Role = null; context.Add(account); context.SaveChanges(); service.Delete(role.Id); Assert.NotEmpty(context.Set <Account>().Where(model => model.Id == account.Id && model.RoleId == null)); }
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); }
private Int64 CreateAccountWithPermissionFor(String area, String controller, String action, Boolean isLocked = false) { RolePermission rolePermission = ObjectsFactory.CreateRolePermission(0); rolePermission.Permission.Controller = controller; rolePermission.Permission.Action = action; rolePermission.Permission.Area = area; Account account = ObjectsFactory.CreateAccount(0); account.Role = rolePermission.Role; account.IsLocked = isLocked; context.Drop().Add(rolePermission); context.Add(account); context.SaveChanges(); authorization.Refresh(services); return(account.Id); }
private Int32 CreateAccountWithPermissionFor(String area, String controller, String action, Boolean isLocked = false) { using (TestingContext testingContext = new TestingContext(context.DatabaseName)) { RolePermission rolePermission = ObjectsFactory.CreateRolePermission(); Account account = ObjectsFactory.CreateAccount(); account.Role.Permissions.Add(rolePermission); rolePermission.Role = account.Role; account.IsLocked = isLocked; rolePermission.Permission.Controller = controller; rolePermission.Permission.Action = action; rolePermission.Permission.Area = area; testingContext.Add(account); testingContext.SaveChanges(); authorization.Refresh(); return(account.Id); } }