private Account CreateAccountWithPermissionFor(String area, String controller, String action, Boolean isLocked = false) { using (TestingContext context = new TestingContext()) { RolePermission rolePermission = ObjectFactory.CreateRolePermission(); Account account = ObjectFactory.CreateAccount(); account.RoleId = rolePermission.RoleId; account.IsLocked = isLocked; rolePermission.Permission.Controller = controller; rolePermission.Permission.Action = action; rolePermission.Permission.Area = area; context.Add(rolePermission.Permission); context.Add(rolePermission); context.Add(account.Role); context.Add(account); context.SaveChanges(); } provider.Refresh(); return(ObjectFactory.CreateAccount()); }
private void SetUpData() { account = ObjectFactory.CreateAccount(); context.Add(account.Role); context.Add(account); context.SaveChanges(); }
public void GetAs_ReturnsModelAsDestinationModelById() { context.Add(model); context.SaveChanges(); TestView expected = Mapper.Map <TestView>(model); TestView actual = unitOfWork.GetAs <TestModel, TestView>(model.Id) !; Assert.Equal(expected.CreationDate, actual.CreationDate); Assert.Equal(expected.Title, actual.Title); Assert.Equal(expected.Id, actual.Id); }
public void CanEdit_UsedUsername_ReturnsFalse() { Account takenAccount = ObjectFactory.CreateAccount(2); context.Add(takenAccount); context.SaveChanges(); ProfileEditView view = ObjectFactory.CreateProfileEditView(); view.Username = takenAccount.Username.ToLower(); Boolean canEdit = validator.CanEdit(view); Assert.False(canEdit); Assert.Single(validator.ModelState); Assert.Equal(Validations.UniqueUsername, validator.ModelState["Username"].Errors.Single().ErrorMessage); }
public void CanEdit_Profile_UsedUsername_ReturnsFalse() { Account usedAccount = ObjectsFactory.CreateAccount(2); 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[nameof(ProfileEditView.Username)].Errors.Single().ErrorMessage); }
public RoleValidatorTests() { context = new TestingContext(); validator = new RoleValidator(new UnitOfWork(context)); context.Add(role = ObjectsFactory.CreateRole()); context.SaveChanges(); }
public QueryTests() { context = new TestingContext(); select = new Query <TestModel>(context.Set <TestModel>()); context.RemoveRange(context.Set <TestModel>()); context.Add(ObjectsFactory.CreateTestModel()); context.SaveChanges(); }
public AuditLoggerTests() { context = new TestingContext(); logger = new AuditLogger(context, 1); TestingContext dataContext = new TestingContext(); TestModel model = ObjectsFactory.CreateTestModel(); entry = dataContext.Entry <BaseModel>(dataContext.Add(model).Entity); dataContext.SaveChanges(); }
public LoggableEntityTests() { using (context = new TestingContext()) { context.Add(model = ObjectsFactory.CreateTestModel()); context.SaveChanges(); } context = new TestingContext(context); entry = context.Entry <BaseModel>(model); }
public void Edit_RolePermissions() { Permission permission = ObjectsFactory.CreatePermission(); context.Add(permission); context.SaveChanges(); RoleView view = ObjectsFactory.CreateRoleView(role.Id); view.Permissions = CreatePermissions(); view.Permissions.SelectedIds.Remove(view.Permissions.SelectedIds.First()); view.Permissions.SelectedIds.Add(permission.Id); service.Edit(view); IEnumerable <Int32> actual = context.Set <RolePermission>().AsNoTracking().Select(rolePermission => rolePermission.PermissionId).OrderBy(permissionId => permissionId); IEnumerable <Int32> expected = view.Permissions.SelectedIds.OrderBy(permissionId => permissionId); Assert.Equal(expected, actual); }
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 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; }
private Int32 CreateAccountWithPermissionFor(String?area, String controller, String action, Boolean isLocked = false) { RolePermission rolePermission = ObjectsFactory.CreateRolePermission(); rolePermission.Permission.Controller = controller; rolePermission.Permission.Action = action; rolePermission.Permission.Area = area; Account account = ObjectsFactory.CreateAccount(); account.Role = rolePermission.Role; account.IsLocked = isLocked; context.Add(rolePermission); context.Add(account); context.SaveChanges(); authorization.Refresh(); return(account.Id); }
public void GetAs_ReturnsModelAsDestinationModelById() { context.Add(model); context.SaveChanges(); RoleView expected = Mapper.Map <RoleView>(context.Set <Role>().AsNoTracking().Single()); RoleView actual = unitOfWork.GetAs <Role, RoleView>(model.Id); Assert.Equal(expected.CreationDate, actual.CreationDate); Assert.Equal(expected.Title, actual.Title); Assert.Equal(expected.Id, actual.Id); }
public void Seed_RemovesUnusedPermissions() { Role role = ObjectsFactory.CreateRole(); role.Permissions.Add(new RolePermission { Permission = new Permission { Area = "Test", Controller = "Test", Action = "Test" } }); context.Add(role); context.SaveChanges(); configuration.Seed(); Assert.Empty(role.Permissions); Assert.Empty(context.Set <Permission>().Where(permission => permission.Controller == "Test" && permission.Action == "Test" && permission.Area == "Test")); }
private Int32 CreateAccountWithPermissionFor(String area, String controller, String action, Boolean isLocked = false) { using (TestingContext testingContext = new TestingContext(context.DatabaseName)) { RolePermission rolePermission = ObjectFactory.CreateRolePermission(); Account account = ObjectFactory.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); } }
private void SetUpData() { context.Add(ObjectFactory.CreateRole()); context.SaveChanges(); }