protected virtual void Init() { var attributeTypeRegistry = new CmsAttributeTypeRegistry(); AttributeTypeRegistry.SetCurrent(attributeTypeRegistry); FrameworkContext = new FakeFrameworkContext(); var hive = CreateHiveManager(); RebelApplicationContext = CreateApplicationContext(hive); var resolverContext = new MockedMapResolverContext(FrameworkContext, hive, new MockedPropertyEditorFactory(RebelApplicationContext), new MockedParameterEditorFactory()); var webmModelMapper = new CmsModelMapper(resolverContext); FrameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { webmModelMapper, new FrameworkModelMapper(FrameworkContext) })); DevDataset = DemoDataHelper.GetDemoData(RebelApplicationContext, attributeTypeRegistry); FixedPropertyEditors = new FixedPropertyEditors(RebelApplicationContext); //ensure model binders ModelBinders.Binders.Remove(typeof(HiveId)); ModelBinders.Binders.Add(typeof(HiveId), new HiveIdModelBinder()); ModelBinders.Binders.Remove(typeof(DocumentTypeEditorModel)); ModelBinders.Binders.Add(typeof(DocumentTypeEditorModel), new DocumentTypeModelBinder()); ModelBinders.Binders.Remove(typeof(SizeModelBinder)); ModelBinders.Binders.Add(typeof(SizeModelBinder), new SizeModelBinder()); //set the model meta data provider ModelMetadataProviders.Current = new RebelModelMetadataProvider(); }
private void RunTest( HiveManager hiveManager, FakeFrameworkContext frameworkContext, Action installCallback = null) { var attributeTypeRegistry = new CmsAttributeTypeRegistry(); AttributeTypeRegistry.SetCurrent(attributeTypeRegistry); var appContext = new FakeUmbracoApplicationContext(hiveManager, false); var mockedPropertyEditorFactory = new MockedPropertyEditorFactory(appContext); var resolverContext = new MockedMapResolverContext(frameworkContext, hiveManager, mockedPropertyEditorFactory, new MockedParameterEditorFactory()); var webmModelMapper = new CmsModelMapper(resolverContext); frameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { webmModelMapper, new FrameworkModelMapper(frameworkContext) })); var devDataset = DemoDataHelper.GetDemoData(appContext, attributeTypeRegistry); //Seup permissions var permissions = new Permission[] { new SavePermission(), new PublishPermission(), new HostnamesPermission(), new CopyPermission(), new MovePermission() } .Select(x => new Lazy <Permission, PermissionMetadata>(() => x, new PermissionMetadata(new Dictionary <string, object> { { "Id", x.Id }, { "Name", x.Name }, { "Type", x.Type } }))).ToArray(); var coreDataInstallTask = new EnsureCoreDataTask(frameworkContext, hiveManager, permissions); var devDatasetInstallTask = new DevDatasetInstallTask(frameworkContext, mockedPropertyEditorFactory, hiveManager, attributeTypeRegistry); //Act coreDataInstallTask.InstallOrUpgrade(); if (installCallback != null) { installCallback(); } devDatasetInstallTask.InstallOrUpgrade(); if (installCallback != null) { installCallback(); } //Assert var totalSchemaCount = CoreCmsData.RequiredCoreSchemas().Count() + devDataset.DocTypes.Count() + 1; // +1 for SystemRoot schema var totalEntityCount = CoreCmsData.RequiredCoreUserGroups(permissions).Count() + CoreCmsData.RequiredCoreRootNodes().Count() + devDataset.ContentData.Count(); var totalAttributeTypeCount = CoreCmsData.RequiredCoreSystemAttributeTypes().Count() + CoreCmsData.RequiredCoreUserAttributeTypes().Count(); DoCoreAssertions(hiveManager, totalSchemaCount, totalEntityCount, totalAttributeTypeCount, 2, permissions); }
private void RunTest( HiveManager hiveManager, FakeFrameworkContext frameworkContext, Action installCallback = null) { var attributeTypeRegistry = new CmsAttributeTypeRegistry(); AttributeTypeRegistry.SetCurrent(attributeTypeRegistry); var appContext = new FakeRebelApplicationContext(hiveManager, false); var mockedPropertyEditorFactory = new MockedPropertyEditorFactory(appContext); var resolverContext = new MockedMapResolverContext(frameworkContext, hiveManager, mockedPropertyEditorFactory, new MockedParameterEditorFactory()); var webmModelMapper = new CmsModelMapper(resolverContext); frameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { webmModelMapper, new FrameworkModelMapper(frameworkContext) })); var devDataset = DemoDataHelper.GetDemoData(appContext, attributeTypeRegistry); //Setup permissions var permissions = new Permission[] { new SavePermission(), new PublishPermission(), new HostnamesPermission(), new CopyPermission(), new MovePermission() } .Select(x => new Lazy <Permission, PermissionMetadata>(() => x, new PermissionMetadata(new Dictionary <string, object> { { "Id", x.Id }, { "Name", x.Name }, { "Type", x.Type }, { "UserType", x.UserType } }))).ToArray(); //Setup security service var usersMembershipProvider = new UsersMembershipProvider { AppContext = appContext }; usersMembershipProvider.Initialize("UsersMembershipProvider", new NameValueCollection()); var usersMembershipService = new MembershipService <User, UserProfile>(frameworkContext, hiveManager, "security://user-profiles", "security://user-groups", Framework.Security.Model.FixedHiveIds.UserProfileVirtualRoot, usersMembershipProvider, Enumerable.Empty <MembershipProviderElement>()); ResetMembershipProvider(usersMembershipService.MembershipProvider); var membersMembershipProvider = new MembersMembershipProvider { AppContext = appContext }; membersMembershipProvider.Initialize("MembersMembershipProvider", new NameValueCollection()); var membersMembershipService = new MembershipService <Member, MemberProfile>(frameworkContext, hiveManager, "security://member-profiles", "security://member-groups", Framework.Security.Model.FixedHiveIds.MemberProfileVirtualRoot, membersMembershipProvider, Enumerable.Empty <MembershipProviderElement>()); ResetMembershipProvider(membersMembershipService.MembershipProvider); var permissionService = new PermissionsService(hiveManager, permissions, usersMembershipService); var publicAccessService = new PublicAccessService(hiveManager, membersMembershipService, appContext.FrameworkContext); var securityService = new SecurityService(usersMembershipService, membersMembershipService, permissionService, publicAccessService); var coreDataInstallTask = new EnsureCoreDataTask(frameworkContext, hiveManager, permissions, securityService); //var devDatasetInstallTask = new DevDatasetInstallTask(frameworkContext, mockedPropertyEditorFactory, hiveManager, attributeTypeRegistry); //Act coreDataInstallTask.InstallOrUpgrade(); if (installCallback != null) { installCallback(); } //devDatasetInstallTask.InstallOrUpgrade(); //if (installCallback != null) installCallback(); //Assert var totalSchemaCount = CoreCmsData.RequiredCoreSchemas().Count() + devDataset.DocTypes.Count() + 1; // +1 for SystemRoot schema var totalEntityCount = CoreCmsData.RequiredCoreUserGroups(permissions).Count() + CoreCmsData.RequiredCoreRootNodes().Count() + devDataset.ContentData.Count(); var totalAttributeTypeCount = CoreCmsData.RequiredCoreSystemAttributeTypes().Count() + CoreCmsData.RequiredCoreUserAttributeTypes().Count(); DoCoreAssertions(hiveManager, totalSchemaCount, totalEntityCount, totalAttributeTypeCount, 2, permissions, securityService); //CoreCmsData.RequiredCoreUsers().ForEach( // x => // { // securityService.UsersMembershipService.DeleteUser(x.Username, true); // securityService.MembersMembershipService.DeleteUser(x.Username, true); // }); ResetMembershipProvider(securityService.Users.MembershipProvider); ResetMembershipProvider(securityService.Members.MembershipProvider); }