public static T Parent <T>(IHiveManager hiveManager, ISecurityService security, HiveId childId) where T : TypedEntity { // Open a reader and pass in the scoped cache which should be per http-request using (var uow = hiveManager.OpenReader <IContentStore>(hiveManager.FrameworkContext.ScopedCache)) { // TODO: Add path of current to this // We get the relations by id here because we only want to load the parent entity, not both halves of the relation // (as of 15h Oct 2011 but this should change once UoW gets its own ScopedCache added to cater for this - APN) var firstParentFound = uow.Repositories.GetParentRelations(childId, FixedRelationTypes.DefaultRelationType) .FirstOrDefault(); if (firstParentFound != null) { var parentId = firstParentFound.SourceId.AsEnumerableOfOne(); // Filter the ancestor ids based on anonymous view permissions using (var secUow = hiveManager.OpenReader <ISecurityStore>(hiveManager.FrameworkContext.ScopedCache)) parentId = parentId.FilterAnonymousWithPermissions(security, uow, secUow, new ViewPermission().Id).ToArray(); if (!parentId.Any()) { return(null); } //var parent = uow.Repositories.Get<T>(parentId); //if (parent != null) // return hiveManager.FrameworkContext.TypeMappers.Map<T>(parent); var revision = uow.Repositories.Revisions.GetLatestRevision <TypedEntity>(parentId.FirstOrDefault(), FixedStatusTypes.Published); return(revision != null?hiveManager.FrameworkContext.TypeMappers.Map <T>(revision.Item) : null); } } return(null); }
/// <summary> /// Gets all descendant ids of the <paramref name="entity"/> regardless of publish status. /// </summary> /// <param name="entity">The content.</param> /// <returns></returns> public static IEnumerable <HiveId> AllChildIds(this TypedEntity entity, IHiveManager hiveManager) { if (entity == null) { return(Enumerable.Empty <HiveId>()); } return(hiveManager.FrameworkContext.ScopedCache.GetOrCreateTyped <IEnumerable <HiveId> >( "rvme_AllChildIds_" + entity.Id, () => { // Open a reader and pass in the scoped cache which should be per http-request using (var uow = hiveManager.OpenReader <IContentStore>(hiveManager.FrameworkContext.ScopedCache)) { var hiveIds = uow.Repositories.GetChildRelations(entity.Id, FixedRelationTypes.DefaultRelationType).Select(x => x.DestinationId).ToArray(); // Filter the ancestor ids based on anonymous view permissions //using (var secUow = appContext.Hive.OpenReader<ISecurityStore>(appContext.FrameworkContext.ScopedCache)) // hiveIds = hiveIds.FilterAnonymousWithPermissions(appContext.Security, uow, secUow, new ViewPermission().Id).ToArray(); return hiveIds; } })); return(Enumerable.Empty <HiveId>()); }
public static IQueryable <T> QueryAll <T>(IHiveManager hiveManager) { using (var uow = hiveManager.OpenReader <IContentStore>()) { return(uow.Repositories.Select(x => hiveManager.FrameworkContext.TypeMappers.Map <T>(x))); } }
public static EntityPath GetPath(this Content content, IHiveManager hiveManager) { // Open a reader and pass in the scoped cache which should be per http-request using (var uow = hiveManager.OpenReader <IContentStore>(hiveManager.FrameworkContext.ScopedCache)) { return(uow.Repositories.GetEntityPath(content.Id, FixedRelationTypes.DefaultRelationType)); } }
public static IQueryable <TResult> Query <TResult, TProviderFilter>(this IHiveManager hiveManager) where TResult : class, IReferenceByHiveId where TProviderFilter : class, IProviderTypeFilter { using (var uow = hiveManager.OpenReader <TProviderFilter>()) { return(uow.Repositories.Select(x => hiveManager.FrameworkContext.TypeMappers.Map <TResult>(x))); } }
public static T AssertSchemaPartExists <T, TProviderFilter>(IHiveManager hiveManager, HiveId id) where TProviderFilter : class, IProviderTypeFilter where T : AbstractSchemaPart { using (var uow = hiveManager.OpenReader <TProviderFilter>()) { var item = uow.Repositories.Schemas.Get <T>(id); Assert.NotNull(item); return(item); } }
public static CompositeEntitySchema GetSchemaByAlias <TProviderFilter>( this IHiveManager hiveManager, string alias) where TProviderFilter : class, IProviderTypeFilter { using (var uow = hiveManager.OpenReader <TProviderFilter>()) { var matching = uow.Repositories.Schemas.GetAll <EntitySchema>().FirstOrDefault(x => x.Alias.InvariantEquals(alias)); if (matching == null) { return(null); } return(uow.Repositories.Schemas.GetComposite(matching)); } }
public static IEnumerable <T> GetAncestors <T>(this IHiveManager hiveManager, HiveId descendentId, RelationType relationType = null, string relationAlias = null) where T : class, IRelatableEntity { // Open a reader and pass in the scoped cache which should be per http-request using (var uow = hiveManager.OpenReader <IContentStore>(hiveManager.FrameworkContext.ScopedCache)) { if (relationType != null && relationAlias.IsNullOrWhiteSpace()) { relationType = new RelationType(relationAlias); } return(uow.Repositories.GetAncestors(descendentId, relationType) .ForEach(x => hiveManager.FrameworkContext.TypeMappers.Map <T>(x))); } }
public void ComitWithUserIdSetsCreatedByAndModifiedBy() { var childOfHome = Hive.Cms().NewRevision("Child of home", "child-of-home", "textpageSchema") .SetSelectedTemplate(new HiveId("storage", "templates", new HiveIdValue("/textpageTemplate.cshtml"))) .SetParent(_homePage.Item) .SetValue("bodyText", "<p>TEST</p>") .Publish() .Commit(_homePage.Item.Id); Assert.IsTrue(childOfHome.Success); using (var uow = Hive.OpenReader <IContentStore>()) { var cRelations = uow.Repositories.GetParentRelations(childOfHome.Content.Id, FixedRelationTypes.CreatedByRelationType); Assert.AreEqual(1, cRelations.Count()); Assert.AreEqual(_homePage.Item.Id, cRelations.First().SourceId); var mRelations = uow.Repositories.GetParentRelations(childOfHome.Content.Id, FixedRelationTypes.ModifiedByRelationType); Assert.AreEqual(1, mRelations.Count()); Assert.AreEqual(_homePage.Item.Id, mRelations.First().SourceId); } }
private void DoCoreAssertions(IHiveManager hiveManager, int totalSchemaCount, int totalEntityCount, int totalAttributeTypeCount, int mediaSchemaCount, IEnumerable<Lazy<Permission, PermissionMetadata>> permissions) { //Assert using (var uow = hiveManager.OpenReader<IContentStore>()) { Assert.IsTrue(uow.Repositories.Exists<TypedEntity>(FixedHiveIds.SystemRoot)); Assert.IsTrue(uow.Repositories.Exists<TypedEntity>(FixedEntities.ContentVirtualRoot.Id)); Assert.IsTrue(uow.Repositories.Exists<TypedEntity>(FixedEntities.ContentRecycleBin.Id)); Assert.IsTrue(uow.Repositories.Exists<TypedEntity>(FixedEntities.MediaVirtualRoot.Id)); Assert.IsTrue(uow.Repositories.Exists<TypedEntity>(FixedEntities.MediaRecycleBin.Id)); Assert.IsTrue(uow.Repositories.Exists<TypedEntity>(FixedEntities.UserGroupVirtualRoot.Id)); Assert.IsTrue(uow.Repositories.Exists<TypedEntity>(FixedEntities.UserVirtualRoot.Id)); Assert.IsTrue(uow.Repositories.Schemas.Exists<EntitySchema>(FixedSchemas.ContentRootSchema.Id)); Assert.IsTrue(uow.Repositories.Schemas.Exists<EntitySchema>(FixedSchemas.MediaRootSchema.Id)); Assert.IsTrue(uow.Repositories.Schemas.Exists<EntitySchema>(FixedSchemas.User.Id)); Assert.IsTrue(uow.Repositories.Schemas.Exists<EntitySchema>(FixedSchemas.UserGroup.Id)); Assert.IsTrue(uow.Repositories.Schemas.Exists<EntitySchema>(FixedSchemas.MediaFolderSchema.Id)); Assert.IsTrue(uow.Repositories.Schemas.Exists<EntitySchema>(FixedSchemas.MediaImageSchema.Id)); var schemas = uow.Repositories.Schemas.GetAll<EntitySchema>().ToArray(); //ensure that schemas have relations on them var mediaImage = schemas.Where(x => x.Alias == "mediaImage").Single(); Assert.True(mediaImage.RelationProxies.IsConnected); Assert.AreEqual(FixedHiveIds.MediaRootSchema.Value, mediaImage.RelationProxies.Single().Item.SourceId.Value); var mediaSchemas = uow.Repositories.Schemas.GetEntityByRelationType<EntitySchema>(FixedRelationTypes.DefaultRelationType, FixedHiveIds.MediaRootSchema); Assert.AreEqual(mediaSchemaCount, mediaSchemas.Count()); //ensure that the built in attribute types are there and set correctly var attributeTypes = uow.Repositories.Schemas.GetAll<AttributeType>().ToArray(); Assert.IsTrue(attributeTypes.Any(x => x.Alias == StringAttributeType.AliasValue)); Assert.IsTrue(attributeTypes.Any(x => x.Alias == BoolAttributeType.AliasValue)); Assert.IsTrue(attributeTypes.Any(x => x.Alias == DateTimeAttributeType.AliasValue)); Assert.IsTrue(attributeTypes.Any(x => x.Alias == IntegerAttributeType.AliasValue)); Assert.IsTrue(attributeTypes.Any(x => x.Alias == TextAttributeType.AliasValue)); Assert.IsTrue(attributeTypes.Any(x => x.Alias == NodeNameAttributeType.AliasValue)); Assert.IsTrue(attributeTypes.Any(x => x.Alias == SelectedTemplateAttributeType.AliasValue)); // TODO: Add other in built attribute types //now make sure that the render types are set var inbuiltString = attributeTypes.Single(x => x.Alias == StringAttributeType.AliasValue); Assert.AreEqual(CorePluginConstants.TextBoxPropertyEditorId, inbuiltString.RenderTypeProvider); var inbuiltText = attributeTypes.Single(x => x.Alias == TextAttributeType.AliasValue); Assert.AreEqual(CorePluginConstants.TextBoxPropertyEditorId, inbuiltText.RenderTypeProvider); var inbuiltDateTime = attributeTypes.Single(x => x.Alias == DateTimeAttributeType.AliasValue); Assert.AreEqual(CorePluginConstants.DateTimePickerPropertyEditorId, inbuiltDateTime.RenderTypeProvider); var inbuiltBool = attributeTypes.Single(x => x.Alias == BoolAttributeType.AliasValue); Assert.AreEqual(CorePluginConstants.TrueFalsePropertyEditorId, inbuiltBool.RenderTypeProvider); // TODO: Add other in built attribute types // Check totals Assert.AreEqual(totalSchemaCount, schemas.Count()); var entities = uow.Repositories.GetAll<TypedEntity>().ToArray(); Assert.AreEqual(totalEntityCount, entities.Count()); //ensure they're all published foreach(var e in entities.Where(x => x.IsContent(uow) || x.IsMedia((uow)))) { var snapshot = uow.Repositories.Revisions.GetLatestSnapshot<TypedEntity>(e.Id); Assert.AreEqual(FixedStatusTypes.Published.Alias, snapshot.Revision.MetaData.StatusType.Alias); } // Admin user is not longer created as part of the data install task //var adminUser = entities.SingleOrDefault(x => x.EntitySchema.Id.Value == FixedHiveIds.UserSchema.Value); //Assert.IsNotNull(adminUser); //Assert.IsTrue(adminUser.AttributeGroups.All(x => x != null)); //Assert.IsTrue(adminUser.AttributeGroups.Any()); //Assert.IsTrue(adminUser.EntitySchema.AttributeGroups.All(x => x != null)); //Assert.IsTrue(adminUser.EntitySchema.AttributeGroups.Any()); //Assert.IsTrue(adminUser.EntitySchema.AttributeDefinitions.Select(x => x.AttributeGroup).All(x => x != null)); var distinctTypesByAlias = attributeTypes.DistinctBy(x => x.Alias).ToArray(); var actualCount = attributeTypes.Count(); var distinctCount = distinctTypesByAlias.Count(); var actualCountById = attributeTypes.DistinctBy(x => x.Id).Count(); var allWithAliasAndId = string.Join("\n", attributeTypes.OrderBy(x => x.Alias).Select(x => x.Alias + ": " + x.Id.Value)); Assert.That(actualCount, Is.EqualTo(distinctCount), "Duplicate AttributeTypes were created: {0} distinct by alias, {1} total loaded from provider, {2} distinct by id. All:{3}".InvariantFormat(distinctCount, actualCount, actualCountById, allWithAliasAndId)); Assert.AreEqual(totalAttributeTypeCount, actualCount); //ensure the default templates are set var contentRoot = new Uri("content://"); var homePage = entities.Single(x => x.Id.EqualsIgnoringProviderId(HiveId.ConvertIntToGuid(contentRoot, null, 1048))); var templateRoot = new Uri("storage://templates"); var templateProvider = "templates"; Assert.AreEqual(new HiveId(templateRoot, templateProvider, new HiveIdValue("Homepage.cshtml")).ToString(), homePage.Attributes[SelectedTemplateAttributeDefinition.AliasValue].DynamicValue.ToString()); var installingModules = entities.Single(x => x.Id.EqualsIgnoringProviderId(HiveId.ConvertIntToGuid(contentRoot, null, 1049))); Assert.AreEqual(new HiveId(templateRoot, templateProvider, new HiveIdValue("Textpage.cshtml")).ToString(), installingModules.Attributes[SelectedTemplateAttributeDefinition.AliasValue].DynamicValue.ToString()); var faq = entities.Single(x => x.Id.EqualsIgnoringProviderId(HiveId.ConvertIntToGuid(contentRoot, null, 1059))); Assert.AreEqual(new HiveId(templateRoot, templateProvider, new HiveIdValue("Faq.cshtml")).ToString(), faq.Attributes[SelectedTemplateAttributeDefinition.AliasValue].DynamicValue.ToString()); //ensure the allowed templates are set Assert.AreEqual(1, homePage.EntitySchema.GetXmlPropertyAsList<HiveId>("allowed-templates").Count()); Assert.AreEqual(new HiveId(templateRoot, templateProvider, new HiveIdValue("Homepage.cshtml")).ToString(), homePage.EntitySchema.GetXmlPropertyAsList<HiveId>("allowed-templates").Single().ToString()); Assert.AreEqual(1, installingModules.EntitySchema.GetXmlPropertyAsList<HiveId>("allowed-templates").Count()); Assert.AreEqual(new HiveId(templateRoot, templateProvider, new HiveIdValue("Textpage.cshtml")).ToString(), installingModules.EntitySchema.GetXmlPropertyAsList<HiveId>("allowed-templates").Single().ToString()); Assert.AreEqual(1, faq.EntitySchema.GetXmlPropertyAsList<HiveId>("allowed-templates").Count()); Assert.AreEqual(new HiveId(templateRoot, templateProvider, new HiveIdValue("Faq.cshtml")).ToString(), faq.EntitySchema.GetXmlPropertyAsList<HiveId>("allowed-templates").Single().ToString()); //ensure the allowed children are set var allowedChildrenOfHomepage = homePage.EntitySchema.GetXmlPropertyAsList<HiveId>("allowed-children").ToArray(); Assert.AreEqual(2, allowedChildrenOfHomepage.Count()); // Check installing-modules is an allowed child of homepage Assert.That(allowedChildrenOfHomepage.Select(x => x.Value), Has.Some.EqualTo(installingModules.EntitySchema.Id.Value)); var faqCat = entities.Single(x => x.Id.EqualsIgnoringProviderId(HiveId.ConvertIntToGuid(contentRoot, null, 1060))); Assert.AreEqual(1, faq.EntitySchema.GetXmlPropertyAsList<HiveId>("allowed-children").Count()); Assert.IsTrue(faqCat.EntitySchema.Id.EqualsIgnoringProviderId(faq.EntitySchema.GetXmlPropertyAsList<HiveId>("allowed-children").Single())); var faqQuestion = entities.Single(x => x.Id.EqualsIgnoringProviderId(HiveId.ConvertIntToGuid(contentRoot, null, 1067))); Assert.AreEqual(1, faqCat.EntitySchema.GetXmlPropertyAsList<HiveId>("allowed-children").Count()); Assert.IsTrue(faqQuestion.EntitySchema.Id.EqualsIgnoringProviderId(faqCat.EntitySchema.GetXmlPropertyAsList<HiveId>("allowed-children").Single())); var userGroups = uow.Repositories.GetAll<UserGroup>() .Where(x => x.EntitySchema.Alias == UserGroupSchema.SchemaAlias); Assert.AreEqual(CoreCmsData.RequiredCoreUserGroups(permissions).Count(), userGroups.Count()); var adminUserGroup = userGroups.First(); Assert.AreEqual(1, adminUserGroup.RelationProxies.GetChildRelations(FixedRelationTypes.PermissionRelationType).Count()); Assert.AreEqual(permissions.Count(), adminUserGroup.RelationProxies.GetChildRelations(FixedRelationTypes.PermissionRelationType).Single().Item.MetaData.Count()); } // Check same method coverage on GroupUnit<T> using (var uow = hiveManager.OpenWriter<IContentStore>()) { Assert.IsTrue(uow.Repositories.Exists<TypedEntity>(FixedHiveIds.SystemRoot)); Assert.IsTrue(uow.Repositories.Schemas.Exists<EntitySchema>(FixedSchemas.ContentRootSchema.Id)); var schemas = uow.Repositories.Schemas.GetAll<EntitySchema>().ToArray(); Assert.AreEqual(totalSchemaCount, schemas.Count()); var mediaImage = schemas.Where(x => x.Alias == "mediaImage").Single(); Assert.True(mediaImage.RelationProxies.IsConnected); Assert.AreEqual(FixedHiveIds.MediaRootSchema.Value, mediaImage.RelationProxies.Single().Item.SourceId.Value); var entities = uow.Repositories.GetAll<TypedEntity>().ToArray(); Assert.AreEqual(totalEntityCount, entities.Count()); var attributeTypes = uow.Repositories.Schemas.GetAll<AttributeType>().ToArray(); Assert.AreEqual(totalAttributeTypeCount, attributeTypes.Count()); } }
private void DoCoreAssertions(IHiveManager hiveManager, int totalSchemaCount, int totalEntityCount, int totalAttributeTypeCount, int mediaSchemaCount, IEnumerable <Lazy <Permission, PermissionMetadata> > permissions, ISecurityService securityService) { //Assert using (var uow = hiveManager.OpenReader <IContentStore>()) { Assert.IsTrue(uow.Repositories.Exists <TypedEntity>(FixedHiveIds.SystemRoot)); Assert.IsTrue(uow.Repositories.Exists <TypedEntity>(FixedEntities.ContentVirtualRoot.Id)); Assert.IsTrue(uow.Repositories.Exists <TypedEntity>(FixedEntities.ContentRecycleBin.Id)); Assert.IsTrue(uow.Repositories.Exists <TypedEntity>(FixedEntities.MediaVirtualRoot.Id)); Assert.IsTrue(uow.Repositories.Exists <TypedEntity>(FixedEntities.MediaRecycleBin.Id)); Assert.IsTrue(uow.Repositories.Exists <TypedEntity>(Framework.Security.Model.FixedEntities.UserGroupVirtualRoot.Id)); Assert.IsTrue(uow.Repositories.Exists <TypedEntity>(Framework.Security.Model.FixedEntities.UserVirtualRoot.Id)); Assert.IsTrue(uow.Repositories.Schemas.Exists <EntitySchema>(FixedSchemas.ContentRootSchema.Id)); Assert.IsTrue(uow.Repositories.Schemas.Exists <EntitySchema>(FixedSchemas.MediaRootSchema.Id)); Assert.IsTrue(uow.Repositories.Schemas.Exists <EntitySchema>(Rebel.Framework.Security.Model.FixedSchemas.MembershipUserSchema.Id)); Assert.IsTrue(uow.Repositories.Schemas.Exists <EntitySchema>(Rebel.Framework.Security.Model.FixedSchemas.UserGroup.Id)); Assert.IsTrue(uow.Repositories.Schemas.Exists <EntitySchema>(FixedSchemas.MediaFolderSchema.Id)); Assert.IsTrue(uow.Repositories.Schemas.Exists <EntitySchema>(FixedSchemas.MediaImageSchema.Id)); //MB: Removed the below as creating of Admin is no longer part of the DataInstallTask // Get the admin user and check roles //var adminMemberUser = securityService.Users.GetByUsername("admin", false); //Assert.NotNull(adminMemberUser); //Assert.True(adminMemberUser.Groups.Any()); var schemas = uow.Repositories.Schemas.GetAll <EntitySchema>().ToArray(); Assert.IsTrue(schemas.SelectMany(x => x.AttributeGroups).Any()); Assert.IsTrue(schemas.SelectMany(x => x.AttributeGroups).All(x => x != null)); //ensure that schemas have relations on them var mediaImage = schemas.Where(x => x.Alias == "mediaImage").Single(); Assert.True(mediaImage.RelationProxies.IsConnected); Assert.AreEqual(FixedHiveIds.MediaRootSchema.Value, mediaImage.RelationProxies.Single().Item.SourceId.Value); var mediaSchemas = uow.Repositories.Schemas.GetChildren <EntitySchema>(FixedRelationTypes.DefaultRelationType, FixedHiveIds.MediaRootSchema); Assert.AreEqual(mediaSchemaCount, mediaSchemas.Count()); //ensure that the built in attribute types are there and set correctly var attributeTypes = uow.Repositories.Schemas.GetAll <AttributeType>().ToArray(); Assert.IsTrue(attributeTypes.Any(x => x.Alias == StringAttributeType.AliasValue)); Assert.IsTrue(attributeTypes.Any(x => x.Alias == BoolAttributeType.AliasValue)); Assert.IsTrue(attributeTypes.Any(x => x.Alias == DateTimeAttributeType.AliasValue)); Assert.IsTrue(attributeTypes.Any(x => x.Alias == IntegerAttributeType.AliasValue)); Assert.IsTrue(attributeTypes.Any(x => x.Alias == TextAttributeType.AliasValue)); Assert.IsTrue(attributeTypes.Any(x => x.Alias == NodeNameAttributeType.AliasValue)); Assert.IsTrue(attributeTypes.Any(x => x.Alias == SelectedTemplateAttributeType.AliasValue)); // TODO: Add other in built attribute types //now make sure that the render types are set var inbuiltString = attributeTypes.Single(x => x.Alias == StringAttributeType.AliasValue); Assert.AreEqual(CorePluginConstants.TextBoxPropertyEditorId, inbuiltString.RenderTypeProvider); var inbuiltText = attributeTypes.Single(x => x.Alias == TextAttributeType.AliasValue); Assert.AreEqual(CorePluginConstants.TextBoxPropertyEditorId, inbuiltText.RenderTypeProvider); var inbuiltDateTime = attributeTypes.Single(x => x.Alias == DateTimeAttributeType.AliasValue); Assert.AreEqual(CorePluginConstants.DateTimePickerPropertyEditorId, inbuiltDateTime.RenderTypeProvider); var inbuiltBool = attributeTypes.Single(x => x.Alias == BoolAttributeType.AliasValue); Assert.AreEqual(CorePluginConstants.TrueFalsePropertyEditorId, inbuiltBool.RenderTypeProvider); // TODO: Add other in built attribute types var entities = uow.Repositories.GetAll <TypedEntity>().ToArray(); AssertItems(entities, CoreCmsData.RequiredCoreUserGroups(permissions), (x, y) => x.Name == y.Name, x => x.Name); var rootCount = entities.Count(x => x.EntitySchema.Alias == CoreCmsData.RequiredCoreRootNodes().First().EntitySchema.Alias); Assert.That(rootCount, Is.EqualTo(CoreCmsData.RequiredCoreRootNodes().Count()), "Root count different"); //var userCount = entities.Where(x => x.EntitySchema.Alias == CoreCmsData.RequiredCoreUsers().First().EntitySchema.Alias).ToList(); //Assert.That(userCount.Count, Is.EqualTo(CoreCmsData.RequiredCoreUsers().Count()), "User count different"); var userGroupCount = entities.Count(x => x.EntitySchema.Alias == CoreCmsData.RequiredCoreUserGroups(permissions).First().EntitySchema.Alias); Assert.That(userGroupCount, Is.EqualTo(CoreCmsData.RequiredCoreUserGroups(permissions).Count()), "User group count different"); //MB: Removed the below as administrator setup is no longer part of the DataInstallTask /* * var adminUser = entities.SingleOrDefault(x => x.EntitySchema.Id.Value == Framework.Security.Model.FixedHiveIds.MembershipUserSchema.Value); * Assert.IsNotNull(adminUser); * Assert.IsTrue(adminUser.AttributeGroups.All(x => x != null)); * Assert.IsTrue(adminUser.AttributeGroups.Any()); * Assert.IsTrue(adminUser.EntitySchema.AttributeGroups.All(x => x != null)); * Assert.IsTrue(adminUser.EntitySchema.AttributeGroups.Any()); * var attributeGroups = adminUser.EntitySchema.AttributeDefinitions.Select(x => new {Def = x, x.AttributeGroup}).ToArray(); * var nullGroupsMsg = attributeGroups.Where(x => x.AttributeGroup == null).Select(x => x.Def.Alias).ToArray(); * Assert.That(nullGroupsMsg.Length, Is.EqualTo(0), "Group is null for attrib defs: " + string.Join(", ", nullGroupsMsg)); */ //ensure they're all published foreach (var e in entities.Where(x => x.IsContent(uow) || x.IsMedia((uow)))) { var snapshot = uow.Repositories.Revisions.GetLatestSnapshot <TypedEntity>(e.Id); Assert.AreEqual(FixedStatusTypes.Published.Alias, snapshot.Revision.MetaData.StatusType.Alias); } // Admin user is not longer created as part of the data install task //var adminUser = entities.SingleOrDefault(x => x.EntitySchema.Id.Value == FixedHiveIds.UserSchema.Value); //Assert.IsNotNull(adminUser); //Assert.IsTrue(adminUser.AttributeGroups.All(x => x != null)); //Assert.IsTrue(adminUser.AttributeGroups.Any()); //Assert.IsTrue(adminUser.EntitySchema.AttributeGroups.All(x => x != null)); //Assert.IsTrue(adminUser.EntitySchema.AttributeGroups.Any()); //Assert.IsTrue(adminUser.EntitySchema.AttributeDefinitions.Select(x => x.AttributeGroup).All(x => x != null)); var distinctTypesByAlias = attributeTypes.DistinctBy(x => x.Alias).ToArray(); var actualCount = attributeTypes.Count(); var distinctCount = distinctTypesByAlias.Count(); var actualCountById = attributeTypes.DistinctBy(x => x.Id).Count(); var allWithAliasAndId = string.Join("\n", attributeTypes.OrderBy(x => x.Alias).Select(x => x.Alias + ": " + x.Id.Value)); Assert.That(actualCount, Is.EqualTo(distinctCount), "Duplicate AttributeTypes were created: {0} distinct by alias, {1} total loaded from provider, {2} distinct by id. All:{3}".InvariantFormat(distinctCount, actualCount, actualCountById, allWithAliasAndId)); Assert.AreEqual(totalAttributeTypeCount, actualCount); //ensure the default templates are set var contentRoot = new Uri("content://"); var homePage = entities.Single(x => x.Id.EqualsIgnoringProviderId(HiveId.ConvertIntToGuid(contentRoot, null, 1048))); var templateRoot = new Uri("storage://templates"); var templateProvider = "templates"; Assert.AreEqual(new HiveId(templateRoot, templateProvider, new HiveIdValue("Homepage.cshtml")).ToString(), homePage.Attributes[SelectedTemplateAttributeDefinition.AliasValue].DynamicValue.ToString()); var installingModules = entities.Single(x => x.Id.EqualsIgnoringProviderId(HiveId.ConvertIntToGuid(contentRoot, null, 1049))); Assert.AreEqual(new HiveId(templateRoot, templateProvider, new HiveIdValue("Textpage.cshtml")).ToString(), installingModules.Attributes[SelectedTemplateAttributeDefinition.AliasValue].DynamicValue.ToString()); var faq = entities.Single(x => x.Id.EqualsIgnoringProviderId(HiveId.ConvertIntToGuid(contentRoot, null, 1059))); Assert.AreEqual(new HiveId(templateRoot, templateProvider, new HiveIdValue("Faq.cshtml")).ToString(), faq.Attributes[SelectedTemplateAttributeDefinition.AliasValue].DynamicValue.ToString()); //ensure the allowed templates are set Assert.AreEqual(1, homePage.EntitySchema.GetXmlPropertyAsList <HiveId>("allowed-templates").Count()); Assert.AreEqual(new HiveId(templateRoot, templateProvider, new HiveIdValue("Homepage.cshtml")).ToString(), homePage.EntitySchema.GetXmlPropertyAsList <HiveId>("allowed-templates").Single().ToString()); Assert.AreEqual(1, installingModules.EntitySchema.GetXmlPropertyAsList <HiveId>("allowed-templates").Count()); Assert.AreEqual(new HiveId(templateRoot, templateProvider, new HiveIdValue("Textpage.cshtml")).ToString(), installingModules.EntitySchema.GetXmlPropertyAsList <HiveId>("allowed-templates").Single().ToString()); Assert.AreEqual(1, faq.EntitySchema.GetXmlPropertyAsList <HiveId>("allowed-templates").Count()); Assert.AreEqual(new HiveId(templateRoot, templateProvider, new HiveIdValue("Faq.cshtml")).ToString(), faq.EntitySchema.GetXmlPropertyAsList <HiveId>("allowed-templates").Single().ToString()); //ensure the allowed children are set var allowedChildrenOfHomepage = homePage.EntitySchema.GetXmlPropertyAsList <HiveId>("allowed-children").ToArray(); Assert.AreEqual(2, allowedChildrenOfHomepage.Count()); // Check installing-modules is an allowed child of homepage Assert.That(allowedChildrenOfHomepage.Select(x => x.Value), Has.Some.EqualTo(installingModules.EntitySchema.Id.Value)); var faqCat = entities.Single(x => x.Id.EqualsIgnoringProviderId(HiveId.ConvertIntToGuid(contentRoot, null, 1060))); Assert.AreEqual(1, faq.EntitySchema.GetXmlPropertyAsList <HiveId>("allowed-children").Count()); Assert.IsTrue(faqCat.EntitySchema.Id.EqualsIgnoringProviderId(faq.EntitySchema.GetXmlPropertyAsList <HiveId>("allowed-children").Single())); var faqQuestion = entities.Single(x => x.Id.EqualsIgnoringProviderId(HiveId.ConvertIntToGuid(contentRoot, null, 1067))); Assert.AreEqual(1, faqCat.EntitySchema.GetXmlPropertyAsList <HiveId>("allowed-children").Count()); Assert.IsTrue(faqQuestion.EntitySchema.Id.EqualsIgnoringProviderId(faqCat.EntitySchema.GetXmlPropertyAsList <HiveId>("allowed-children").Single())); var userGroups = uow.Repositories.GetAll <UserGroup>() .Where(x => x.EntitySchema.Alias == UserGroupSchema.SchemaAlias); Assert.AreEqual(CoreCmsData.RequiredCoreUserGroups(permissions).Count(), userGroups.Count()); var adminUserGroup = userGroups.First(); Assert.AreEqual(1, adminUserGroup.RelationProxies.GetChildRelations(FixedRelationTypes.PermissionRelationType).Count()); Assert.AreEqual(permissions.Count(), adminUserGroup.RelationProxies.GetChildRelations(FixedRelationTypes.PermissionRelationType).Single().Item.MetaData.Count()); } // Check same method coverage on GroupUnit<T> using (var uow = hiveManager.OpenWriter <IContentStore>()) { Assert.IsTrue(uow.Repositories.Exists <TypedEntity>(FixedHiveIds.SystemRoot)); Assert.IsTrue(uow.Repositories.Schemas.Exists <EntitySchema>(FixedSchemas.ContentRootSchema.Id)); var schemas = uow.Repositories.Schemas.GetAll <EntitySchema>().ToArray(); Assert.AreEqual(totalSchemaCount, schemas.Count()); var mediaImage = schemas.Where(x => x.Alias == "mediaImage").Single(); Assert.True(mediaImage.RelationProxies.IsConnected); Assert.AreEqual(FixedHiveIds.MediaRootSchema.Value, mediaImage.RelationProxies.Single().Item.SourceId.Value); var entities = uow.Repositories.GetAll <TypedEntity>().ToArray(); Assert.AreEqual(totalEntityCount, entities.Count()); var attributeTypes = uow.Repositories.Schemas.GetAll <AttributeType>().ToArray(); Assert.AreEqual(totalAttributeTypeCount, attributeTypes.Count()); } }