public AuthorizationProviderTests() { IServiceProvider services = Substitute.For<IServiceProvider>(); services.GetService(typeof(IUnitOfWork)).Returns(info => new UnitOfWork(new TestingContext())); using (TestingContext context = new TestingContext()) context.DropData(); authorization = new AuthorizationProvider(Assembly.GetExecutingAssembly(), services); }
public void AuditLogger_AccountId_DisablesChangesDetection() { TestingContext context = new TestingContext(); context.Configuration.AutoDetectChangesEnabled = true; using (new AuditLogger(context, 1)) Assert.False(context.Configuration.AutoDetectChangesEnabled); }
public UnitOfWorkTests() { context = new TestingContext(); model = ObjectFactory.CreateRole(); unitOfWork = new UnitOfWork(context); context.DropData(); }
public SelectTests() { context = new TestingContext(); select = new Select<Role>(context.Set<Role>()); context.Set<Role>().Add(ObjectFactory.CreateRole()); context.DropData(); }
public BaseDatalistTests() { HttpContext.Current = HttpContextFactory.CreateHttpContext(); urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); datalist = new BaseDatalistProxy<Role, RoleView>(urlHelper); using (TestingContext context = new TestingContext()) context.DropData(); }
public SelectTests() { context = new TestingContext(); select = new Select<Role>(context.Set<Role>()); context.DropData(); SetUpData(); }
public LoggerTests() { context = new TestingContext(); logger = new Logger(context); context.Set<Log>().RemoveRange(context.Set<Log>()); context.SaveChanges(); }
public RoleServiceTests() { context = new TestingContext(); Authorization.Provider = Substitute.For<IAuthorizationProvider>(); service = Substitute.ForPartsOf<RoleService>(new UnitOfWork(context)); context.DropData(); }
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 RoleValidatorTests() { context = new TestingContext(); validator = new RoleValidator(new UnitOfWork(context)); validator.ModelState = new ModelStateDictionary(); TearDownData(); SetUpData(); }
public UnitOfWorkTests() { context = new TestingContext(); model = ObjectFactory.CreateRole(); logger = Substitute.For<IAuditLogger>(); unitOfWork = new UnitOfWork(context, logger); context.DropData(); }
public RoleValidatorTests() { context = new TestingContext(); validator = new RoleValidator(new UnitOfWork(context)); context.DropData(); role = ObjectFactory.CreateRole(); context.Set<Role>().Add(role); context.SaveChanges(); }
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(); }
public AuditLoggerTests() { context = new TestingContext(); logger = new AuditLogger(context, 1); Role model = ObjectFactory.CreateRole(); TestingContext dataContext = new TestingContext(); entry = dataContext.Entry<BaseModel>(dataContext.Set<Role>().Add(model)); dataContext.Set<AuditLog>().RemoveRange(dataContext.Set<AuditLog>()); dataContext.DropData(); }
public AccountValidatorTests() { context = new TestingContext(); hasher = Substitute.For<IHasher>(); hasher.VerifyPassword(Arg.Any<String>(), Arg.Any<String>()).Returns(true); context.DropData(); SetUpData(); validator = new AccountValidator(new UnitOfWork(context), hasher); validator.CurrentAccountId = account.Id; }
public LoggablePropertyTests() { using (TestingContext context = new TestingContext()) { Role model = ObjectFactory.CreateRole(); context.Set<Role>().Add(model); context.Entry(model).State = EntityState.Modified; textProperty = context.Entry(model).Property(prop => prop.Title); dateProperty = context.Entry(model).Property(prop => prop.CreationDate); } }
public AccountValidatorTests() { context = new TestingContext(); hasher = Substitute.For<IHasher>(); hasher.VerifyPassword(Arg.Any<String>(), Arg.Any<String>()).Returns(true); validator = new AccountValidator(new UnitOfWork(context), hasher); validator.ModelState = new ModelStateDictionary(); TearDownData(); SetUpData(); }
public LoggableEntityTests() { using (context = new TestingContext()) { context.DropData(); SetUpData(); } context = new TestingContext(); model = context.Set<Role>().Single(); entry = context.Entry<BaseModel>(model); }
public AccountServiceTests() { context = new TestingContext(); hasher = Substitute.For<IHasher>(); hasher.HashPassword(Arg.Any<String>()).Returns(info => info.Arg<String>() + "Hashed"); context.DropData(); SetUpData(); Authorization.Provider = Substitute.For<IAuthorizationProvider>(); service = new AccountService(new UnitOfWork(context), hasher); service.CurrentAccountId = account.Id; }
public void LoggableEntity_CreatesPropertiesForAttachedEntity() { context.Dispose(); String title = model.Title; context = new TestingContext(); context.Set<Role>().Attach(model); entry = context.Entry<BaseModel>(model); entry.OriginalValues["Title"] = "Role"; entry.CurrentValues["Title"] = "Role"; entry.State = EntityState.Modified; IEnumerator<LoggableProperty> expected = new List<LoggableProperty> { new LoggableProperty(entry.Property("Title"), title) }.GetEnumerator(); IEnumerator<LoggableProperty> actual = new LoggableEntity(entry).Properties.GetEnumerator(); while (expected.MoveNext() | actual.MoveNext()) { Assert.Equal(expected.Current.IsModified, actual.Current.IsModified); Assert.Equal(expected.Current.ToString(), actual.Current.ToString()); } }
public AuthorizationProviderTests() { provider = new AuthorizationProvider(Assembly.GetExecutingAssembly()); using (TestingContext context = new TestingContext()) context.DropData(); }
public void IsAuthorizedFor_CachesAccountPermissions() { Account account = CreateAccountWithPermissionFor(null, "Authorized", "Action"); using (TestingContext context = new TestingContext()) context.DropData(); Assert.True(provider.IsAuthorizedFor(account.Id, null, "Authorized", "Action")); }
public void Refresh_Permissions() { Account account = CreateAccountWithPermissionFor("Area", "Authorized", "Action"); Assert.True(provider.IsAuthorizedFor(account.Id, "Area", "Authorized", "Action")); using (TestingContext context = new TestingContext()) context.DropData(); SetUpDependencyResolver(); provider.Refresh(); Assert.False(provider.IsAuthorizedFor(account.Id, "Area", "Authorized", "Action")); }
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; account.Role = null; rolePermission.Permission.Controller = controller; rolePermission.Permission.Action = action; rolePermission.Permission.Area = area; context.Set<RolePermission>().Add(rolePermission); context.Set<Account>().Add(account); context.SaveChanges(); SetUpDependencyResolver(); provider.Refresh(); return account; } }
public void FilterById_FromCurrentFilter() { TestingContext context = new TestingContext(); Role role = ObjectFactory.CreateRole(); context.Set<Role>().Add(role); context.SaveChanges(); IUnitOfWork unitOfWork = new UnitOfWork(context); datalist = new BaseDatalistProxy<Role, RoleView>(unitOfWork); datalist.CurrentFilter.Id = role.Id; RoleView expected = unitOfWork.Select<Role>().To<RoleView>().Single(); RoleView actual = datalist.BaseFilterById(null).Single(); Assert.Equal(expected.CreationDate, actual.CreationDate); Assert.Equal(expected.Title, actual.Title); Assert.Equal(expected.Id, actual.Id); }
static TestingContext() { using (TestingContext context = new TestingContext()) context.Database.Migrate(); }
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.Role.Permissions.Add(rolePermission); rolePermission.Role = account.Role; account.IsLocked = isLocked; rolePermission.Permission.Controller = controller; rolePermission.Permission.Action = action; rolePermission.Permission.Area = area; context.Add(account); context.SaveChanges(); authorization.Refresh(); return account; } }
public void Refresh_Permissions() { Account account = CreateAccountWithPermissionFor("Area", "Authorized", "Action"); Assert.True(authorization.IsAuthorizedFor(account.Id, "Area", "Authorized", "Action")); using (TestingContext context = new TestingContext()) context.DropData(); authorization.Refresh(); Assert.False(authorization.IsAuthorizedFor(account.Id, "Area", "Authorized", "Action")); }