Beispiel #1
0
        ///// <summary>
        ///// Helper method to create a brand new test EntitySchema with the property editor passed in for each schema definition
        ///// </summary>
        ///// <param name="propEditor"></param>
        ///// <param name="name"></param>
        ///// <param name="alias"></param>
        ///// <param name="beforeCommit"></param>
        ///// <returns></returns>
        //protected EntitySchema CreateNewEntitySchema(dynamic propEditor, string name, string alias, Action<EntitySchema> beforeCommit)
        //{
        //    var docType = DevDataset.DocTypes.First();

        //    docType.Name = name;
        //    docType.Alias = alias;

        //    var schema = UmbracoApplicationContext.FrameworkContext.TypeMappers.Map<DocumentTypeEditorModel, EntitySchema>(docType);
        //    foreach (var a in schema.AttributeDefinitions.Where(x => !x.Alias.StartsWith("system-")))
        //    {
        //        a.AttributeType.RenderTypeProvider = propEditor.Id.ToString();
        //    }

        //    //next commit the new doc type
        //    using (var writer = UmbracoApplicationContext.Hive.OpenWriter<IContentStore>())
        //    {
        //        if (beforeCommit != null)
        //        {
        //            beforeCommit(schema);
        //        }
        //        writer.Repositories.Schemas.AddOrUpdate(schema);
        //        writer.Complete();
        //    }

        //    return schema;

        //}

        /// <summary>
        /// Puts all of the data types into the repo from CoreCmsData
        /// </summary>
        protected void AddRequiredDataToRepository()
        {
            // Create in-built attribute type definitions
            using (var writer = UmbracoApplicationContext.Hive.OpenWriter <IContentStore>())
            {
                writer.Repositories.Schemas.AddOrUpdate(CoreCmsData.RequiredCoreSystemAttributeTypes());
                writer.Complete();
            }

            //create user attribute type defs
            using (var writer = UmbracoApplicationContext.Hive.OpenWriter <IContentStore>())
            {
                writer.Repositories.Schemas.AddOrUpdate(CoreCmsData.RequiredCoreUserAttributeTypes());
                writer.Complete();
            }

            //create the core schemas
            using (var writer = UmbracoApplicationContext.Hive.OpenWriter <IContentStore>())
            {
                writer.Repositories.Schemas.AddOrUpdate(CoreCmsData.RequiredCoreSchemas());
                writer.Complete();
            }

            //create the core root nodes
            using (var writer = UmbracoApplicationContext.Hive.OpenWriter <IContentStore>())
            {
                foreach (var e in CoreCmsData.RequiredCoreRootNodes())
                {
                    writer.Repositories.AddOrUpdate(e);
                }
                writer.Complete();
            }
        }
        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);
        }
        public override void InstallOrUpgrade()
        {
            //insert core components first
            using (var uow = CoreManager.OpenWriter <IContentStore>())
            {
                CoreCmsData.RequiredCoreRootNodes()
                .ForEach(x => uow.Repositories.AddOrUpdate(x));

                CoreCmsData.RequiredCoreSchemas()
                .ForEach(x => uow.Repositories.Schemas.AddOrUpdate(x));

                //user types
                CoreCmsData.RequiredCoreUserGroups(_permissions)
                .ForEach(x => uow.Repositories.AddOrUpdate(x));

                //attribute types, this also sets the RenderTypeProvider on the previously submitted attribute types
                CoreCmsData.RequiredCoreSystemAttributeTypes()
                .ForEach(x => uow.Repositories.Schemas.AddOrUpdate(x));
                CoreCmsData.RequiredCoreUserAttributeTypes()
                .ForEach(x => uow.Repositories.Schemas.AddOrUpdate(x));

                uow.Complete();
            }

            // We not longer add users as part of the ensure data task
            // instead the user is created as part of the installer (MB 2012/01/26)
            //using (var uow = CoreManager.OpenWriter<IContentStore>())
            //{
            //    // users
            //    CoreCmsData.RequiredCoreUsers()
            //        .ForEach(x =>
            //        {

            //            //find user group with same name as user
            //            var userGroup =
            //                uow.Repositories.GetEntityByRelationType<UserGroup>(
            //                    FixedRelationTypes.DefaultRelationType, FixedHiveIds.UserGroupVirtualRoot)
            //                    .Where(y => y.Name == x.Name)
            //                    .FirstOrDefault();

            //            if(userGroup != null)
            //                x.RelationProxies.EnlistParent(userGroup, FixedRelationTypes.UserGroupRelationType);

            //            uow.Repositories.AddOrUpdate(x);

            //        });

            //    uow.Complete();
            //}
        }
        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);
        }
Beispiel #5
0
        public override void InstallOrUpgrade()
        {
            //insert core components first
            using (var uow = CoreManager.OpenWriter <IContentStore>())
            {
                CoreCmsData.RequiredCoreRootNodes()
                .ForEach(x => uow.Repositories.AddOrUpdate(x));

                CoreCmsData.RequiredCoreSchemas()
                .ForEach(x => uow.Repositories.Schemas.AddOrUpdate(x));

                //user groups
                CoreCmsData.RequiredCoreUserGroups(_permissions).ForEach(
                    x =>
                {
                    var existing = uow.Repositories.Query <UserGroup>().Any(y => y.Name == x.Name);

                    if (!existing)
                    {
                        x.RelationProxies.EnlistParentById(FixedHiveIds.UserGroupVirtualRoot, FixedRelationTypes.DefaultRelationType);
                        uow.Repositories.AddOrUpdate(x);
                    }
                });

                //member groups
                //CoreCmsData.RequiredCoreMemberGroups(_permissions).ForEach(
                //    x =>
                //    {
                //        var existing = uow.Repositories.Query<UserGroup>().Any(y => y.Name == x.Name);

                //        if (!existing)
                //        {
                //            x.RelationProxies.EnlistParentById(FixedHiveIds.MemberGroupVirtualRoot, FixedRelationTypes.DefaultRelationType);
                //            uow.Repositories.AddOrUpdate(x);
                //        }
                //    });

                //attribute types, this also sets the RenderTypeProvider on the previously submitted attribute types
                CoreCmsData.RequiredCoreSystemAttributeTypes()
                .ForEach(x => uow.Repositories.Schemas.AddOrUpdate(x));
                CoreCmsData.RequiredCoreUserAttributeTypes()
                .ForEach(x => uow.Repositories.Schemas.AddOrUpdate(x));

                uow.Complete();
            }

            // We not longer add users as part of the ensure data task
            // instead the user is created as part of the installer (MB 2012/01/26)
            //using (var uow = CoreManager.OpenWriter<IContentStore>())
            //{
            //    // users
            //    CoreCmsData.RequiredCoreUsers()
            //        .ForEach(x =>
            //        {
            //            //find user group with same name as user
            //            var userGroup =
            //                uow.Repositories.GetEntityByRelationType<UserGroup>(
            //                    FixedRelationTypes.DefaultRelationType, FixedHiveIds.UserGroupVirtualRoot)
            //                    .Where(y => y.Name == x.Name)
            //                    .FirstOrDefault();

            //            if (userGroup != null)
            //                x.RelationProxies.EnlistParent(userGroup, FixedRelationTypes.UserGroupRelationType);

            //            uow.Repositories.AddOrUpdate(x);

            //            _securityService.UsersMembershipService.CreateUser(x, out status);

            //            if (status != MembershipCreateStatus.Success)
            //                LogHelper.Error<EnsureCoreDataTask>(string.Format("Error creating user {0}", x.Username),
            //                    new ApplicationException(status.ToString()));

            //        });

            //    uow.Complete();
            //}
        }