Пример #1
0
        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);
        }
Пример #2
0
        public void BeforeTest()
        {
            _nhibernateTestSetup = new NhibernateTestSetupHelper(useNhProf: true);

            var storageProvider = new IoHiveTestSetupHelper(_nhibernateTestSetup.FakeFrameworkContext);


            Hive =
                new HiveManager(
                    new[]
            {
                new ProviderMappingGroup(
                    "test1",
                    new WildcardUriMatch("content://"),
                    _nhibernateTestSetup.ReadonlyProviderSetup,
                    _nhibernateTestSetup.ProviderSetup,
                    _nhibernateTestSetup.FakeFrameworkContext),

                new ProviderMappingGroup(
                    "test2",
                    new WildcardUriMatch("security://members"),
                    _nhibernateTestSetup.ReadonlyProviderSetup,
                    _nhibernateTestSetup.ProviderSetup,
                    _nhibernateTestSetup.FakeFrameworkContext),
                storageProvider.CreateGroup("uploader", "storage://")
            },
                    _nhibernateTestSetup.FakeFrameworkContext);

            var appContext = new FakeRebelApplicationContext(Hive, true);

            AttributeTypeRegistry.SetCurrent(new CmsAttributeTypeRegistry());

            var task = new EnsureCoreDataTask(Hive.FrameworkContext,
                                              Hive,
                                              Enumerable.Empty <Lazy <Permission, PermissionMetadata> >(),
                                              null);

            task.InstallOrUpgrade();

            Provider = new MembersMembershipProvider(Hive, appContext);
            Provider.Initialize("MembersMembershipProvider", new NameValueCollection());
        }
        public void BeforeTest()
        {
            _nhibernateTestSetup = new NhibernateTestSetupHelper(useNhProf:true);

            var storageProvider = new IoHiveTestSetupHelper(_nhibernateTestSetup.FakeFrameworkContext);


            Hive =
                new HiveManager(
                    new[]
                        {
                            new ProviderMappingGroup(
                                "test1",
                                new WildcardUriMatch("content://"),
                                _nhibernateTestSetup.ReadonlyProviderSetup,
                                _nhibernateTestSetup.ProviderSetup,
                                _nhibernateTestSetup.FakeFrameworkContext),

                            new ProviderMappingGroup(
                                "test2",
                                new WildcardUriMatch("security://members"),
                                _nhibernateTestSetup.ReadonlyProviderSetup,
                                _nhibernateTestSetup.ProviderSetup,
                                _nhibernateTestSetup.FakeFrameworkContext),
                                storageProvider.CreateGroup("uploader", "storage://")
                        },
                    _nhibernateTestSetup.FakeFrameworkContext);

            var appContext = new FakeRebelApplicationContext(Hive, true);

            AttributeTypeRegistry.SetCurrent(new CmsAttributeTypeRegistry());

            var task = new EnsureCoreDataTask(Hive.FrameworkContext,
                                              Hive,
                                              Enumerable.Empty<Lazy<Permission, PermissionMetadata>>(),
                                              null);
            task.InstallOrUpgrade();

            Provider = new MembersMembershipProvider(Hive, appContext);
            Provider.Initialize("MembersMembershipProvider", new NameValueCollection());
        }
Пример #4
0
        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);
        }