private void SetUpData() { Account account = ObjectFactory.CreateAccount(); role = ObjectFactory.CreateRole(); account.RoleId = role.Id; context.Set <Account>().Add(account); role.RolePrivileges = new List <RolePrivilege>(); Int32 privilegeNumber = 1; IEnumerable <String> controllers = new[] { "Accounts", "Roles" }; IEnumerable <String> actions = new[] { "Index", "Create", "Details", "Edit", "Delete" }; foreach (String controller in controllers) { foreach (String action in actions) { RolePrivilege rolePrivilege = ObjectFactory.CreateRolePrivilege(privilegeNumber++); rolePrivilege.Privilege = new Privilege { Area = "Administration", Controller = controller, Action = action }; rolePrivilege.Privilege.Id = rolePrivilege.Id; rolePrivilege.PrivilegeId = rolePrivilege.Id; rolePrivilege.RoleId = role.Id; rolePrivilege.Role = role; role.RolePrivileges.Add(rolePrivilege); } } context.Set <Role>().Add(role); context.SaveChanges(); }
private Account CreateAccountWithPrivilegeFor(String area, String controller, String action) { Account account = ObjectFactory.CreateAccount(); Role role = ObjectFactory.CreateRole(); account.RoleId = role.Id; context.Set <Account>().Add(account); role.RolePrivileges = new List <RolePrivilege>(); RolePrivilege rolePrivilege = ObjectFactory.CreateRolePrivilege(); Privilege privilege = ObjectFactory.CreatePrivilege(); rolePrivilege.PrivilegeId = privilege.Id; rolePrivilege.Privilege = privilege; rolePrivilege.RoleId = role.Id; rolePrivilege.Role = role; privilege.Area = area; privilege.Controller = controller; privilege.Action = action; role.RolePrivileges.Add(rolePrivilege); context.Set <Role>().Add(role); context.SaveChanges(); provider.Refresh(); return(account); }
public void IsActive_ReturnsAccountState(Boolean isLocked, Boolean expected) { account.IsLocked = isLocked; context.SaveChanges(); Boolean actual = service.IsActive(account.Id); Assert.Equal(expected, actual); }
public ActionResult Create(TestDB testdb) { if (ModelState.IsValid) { db.TestDBs.Add(testdb); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(testdb)); }
private void SetUpData() { Account account = ObjectFactory.CreateAccount(); account.Role = ObjectFactory.CreateRole(); account.RoleId = account.Role.Id; accountId = account.Id; context.Set <Account>().Add(account); context.SaveChanges(); }
public void CanReset_ExpiredToken_ReturnsFalse() { account.RecoveryTokenExpirationDate = DateTime.Now.AddMinutes(-5); context.Update(account); context.SaveChanges(); Boolean canReset = validator.CanReset(ObjectsFactory.CreateAccountResetView()); Alert alert = validator.Alerts.Single(); Assert.False(canReset); Assert.Equal(0, alert.Timeout); Assert.Empty(validator.ModelState); Assert.Equal(AlertType.Danger, alert.Type); Assert.Equal(Validation.For <AccountView>("ExpiredToken"), alert.Message); }
private void SetUpData() { country = ObjectFactory.CreateCountry(); context.Set <Country>().Add(country); context.SaveChanges(); }
private void SetUpData() { city = ObjectFactory.CreateCity(); context.Set <City>().Add(city); context.SaveChanges(); }
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()); }
public void AddPersonsSuccessTest() { var Input = new { persons = GeneratePeople(30).OrderBy(p => p.Id).ToList(), options = this.GenerateOptions("AddPersonsSuccessTest") }; using (var context = new TestingContext(Input.options)) { var repo = new PersonRepository(context); foreach (var person in Input.persons) { repo.Insert(person); } context.SaveChanges(); } List <Context.DataModels.Person> Actual; using (var context = new TestingContext(Input.options)) { var Target = new PersonRepository(context); Actual = Target.Get(null, null).OrderBy(p => p.Id).ToList(); } Actual.Should().BeEquivalentTo(Input.persons, op => op.Excluding(p => p.Address.Person) .Excluding(p => p.Company.Person), "the data had been saved and received from the database"); }
public void AddPersonSuccessTest() { var Input = new { person = GeneratePeople(1).First(), options = this.GenerateOptions("AddPersonSuccessTest") }; using (var context = new TestingContext(Input.options)) { var repo = new PersonRepository(context); repo.Insert(Input.person); context.SaveChanges(); } Context.DataModels.Person Actual; using (var context = new TestingContext(Input.options)) { var Target = new PersonRepository(context); Actual = Target.GetFullPersonById(Input.person.Id); } Actual.Should().BeEquivalentTo(Input.person, op => op.Excluding(p => p.Address.Person) .Excluding(p => p.Company.Person), "the data should have been saved and received from the database"); }
private void SetUpData() { state = ObjectFactory.CreateState(); context.Set <State>().Add(state); context.SaveChanges(); }
private Account CreateAccountWithPrivilegeFor(String area, String controller, String action, Boolean isLocked = false) { using (TestingContext context = new TestingContext()) { Account account = ObjectFactory.CreateAccount(); Role role = ObjectFactory.CreateRole(); account.IsLocked = isLocked; account.RoleId = role.Id; account.Role = role; role.RolePrivileges = new List <RolePrivilege>(); RolePrivilege rolePrivilege = ObjectFactory.CreateRolePrivilege(); Privilege privilege = ObjectFactory.CreatePrivilege(); rolePrivilege.PrivilegeId = privilege.Id; rolePrivilege.Privilege = privilege; rolePrivilege.RoleId = role.Id; rolePrivilege.Role = role; privilege.Controller = controller; privilege.Action = action; privilege.Area = area; role.RolePrivileges.Add(rolePrivilege); context.Set <Account>().Add(account); context.SaveChanges(); SetUpDependencyResolver(); provider.Refresh(); return(account); } }
public void CanReset_CanNotResetAccountWithExpiredToken() { Account account = context.Set <Account>().Single(); account.RecoveryTokenExpirationDate = DateTime.Now.AddMinutes(-5); context.SaveChanges(); Assert.IsFalse(validator.CanReset(ObjectFactory.CreateAccountResetView())); }
public RoleValidatorTests() { context = new TestingContext(); validator = new RoleValidator(new UnitOfWork(context)); context.Add(role = ObjectsFactory.CreateRole()); context.SaveChanges(); }
public LoggerTests() { context = new TestingContext(); logger = new Logger(context); context.Set <Log>().RemoveRange(context.Set <Log>()); context.SaveChanges(); }
public UnitOfWorkTests() { context = new TestingContext(); logger = Substitute.For <IAuditLogger>(); unitOfWork = new UnitOfWork(context, logger); context.Set <TestModel>().RemoveRange(context.Set <TestModel>()); context.SaveChanges(); }
public SelectTests() { context = new TestingContext(); select = new Select <TestModel>(context.Set <TestModel>()); context.Set <TestModel>().RemoveRange(context.Set <TestModel>()); context.Set <TestModel>().Add(ObjectFactory.CreateTestModel()); 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(); }
private void TearDownData() { using (TestingContext context = new TestingContext()) { context.Set <Privilege>().RemoveRange(context.Set <Privilege>()); context.Set <Account>().RemoveRange(context.Set <Account>()); context.Set <Role>().RemoveRange(context.Set <Role>()); context.SaveChanges(); } }
public RoleValidatorTests() { context = new TestingContext(); validator = new RoleValidator(new UnitOfWork(context)); context.DropData(); role = ObjectFactory.CreateRole(); context.Set <Role>().Add(role); context.SaveChanges(); }
private void SetUpData() { city = ObjectFactory.CreateCity(); using (TestingContext context = new TestingContext()) { context.Set <City>().Add(city); 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 void Edit_EditsAccount() { Role role = ObjectFactory.CreateRole(2); context.Set <Role>().Add(role); context.SaveChanges(); AccountEditView expected = service.GetView <AccountEditView>(accountId); expected.RoleId = role.Id; service.Edit(expected); Account actual = context.Set <Account>().SingleOrDefault(); Assert.AreEqual(expected.EntityDate, actual.EntityDate); Assert.AreEqual(expected.Username, actual.Username); Assert.AreEqual(expected.RoleId, actual.RoleId); Assert.AreEqual(expected.Id, actual.Id); }
private void SetUpData() { account = ObjectFactory.CreateAccount(); using (TestingContext testingContext = new TestingContext()) { testingContext.Set <Account>().Add(account); testingContext.SaveChanges(); } }
private void SetUpData() { state = ObjectFactory.CreateState(); using (TestingContext context = new TestingContext()) { context.Set <State>().Add(state); context.SaveChanges(); } }
public IEnumerable <DAL.Person> Initialize() { // Look for data if (context.Persons.Any()) { return(new List <DAL.Person>()); // Db has been initialized } var persons = new DAL.Person[] { Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person()), Mapper.Map <DAL.Person>(new Bogus.Person("fr_CA")), Mapper.Map <DAL.Person>(new Bogus.Person("fr_CA")), Mapper.Map <DAL.Person>(new Bogus.Person("fr_CA")), Mapper.Map <DAL.Person>(new Bogus.Person("fr_CA")), Mapper.Map <DAL.Person>(new Bogus.Person("fr_CA")), Mapper.Map <DAL.Person>(new Bogus.Person("fr_CA")), Mapper.Map <DAL.Person>(new Bogus.Person("fr_CA")), Mapper.Map <DAL.Person>(new Bogus.Person("fr_CA")), Mapper.Map <DAL.Person>(new Bogus.Person("fr_CA")), Mapper.Map <DAL.Person>(new Bogus.Person("fr_CA")), Mapper.Map <DAL.Person>(new Bogus.Person("fr_CA")), Mapper.Map <DAL.Person>(new Bogus.Person("fr_CA")), Mapper.Map <DAL.Person>(new Bogus.Person("fr_CA")), Mapper.Map <DAL.Person>(new Bogus.Person("fr_CA")), }; context.Persons.AddRange(persons); context.SaveChanges(); loadedPeople = persons; return(persons); }
public void Edit_RolePermissions() { Permission permission = ObjectFactory.CreatePermission(); context.Set <Permission>().Add(permission); context.SaveChanges(); RoleView view = ObjectFactory.CreateRoleView(role.Id); view.Permissions = CreatePermissions(); view.Permissions.SelectedIds.Add(permission.Id); view.Permissions.SelectedIds.RemoveAt(0); 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 LoggableEntityTests() { using (context = new TestingContext()) { context.Add(model = ObjectsFactory.CreateTestModel()); context.SaveChanges(); } context = new TestingContext(context); entry = context.Entry <BaseModel>(model); }
public AuditLoggerTests() { context = new TestingContext(); dataContext = new TestingContext(); TestModel model = ObjectFactory.CreateTestModel(); logger = Substitute.ForPartsOf <AuditLogger>(context); entry = dataContext.Entry <BaseModel>(dataContext.Set <TestModel>().Add(model)); dataContext.Set <TestModel>().RemoveRange(dataContext.Set <TestModel>()); dataContext.SaveChanges(); }