public static WriterResult <TFilter> AutoCommitTo <TFilter>(this IHiveManager manager, Action <IGroupUnit <TFilter> > repository) where TFilter : class, IProviderTypeFilter { using (var unit = manager.OpenWriter <TFilter>()) { try { repository.Invoke(unit); unit.Complete(); return(new WriterResult <TFilter>(true, false)); } catch (Exception outerException) { try { unit.Abandon(); return(new WriterResult <TFilter>(false, true, outerException)); } catch (Exception innerException) { return(new WriterResult <TFilter>(false, false, outerException, innerException)); } } } }
public void ImportTypedEntity_WhereAttributeGroupExistsWithOtherId() { // Arrange //Create entity with system General Group TypedEntity entity = HiveModelCreationHelper.MockTypedEntity(true); var definition = new NodeNameAttributeDefinition(FixedGroupDefinitions.GeneralGroup); entity.EntitySchema.AttributeDefinitions.Add(definition); //Create new entity with same group, but different Id TypedEntity entityToImport = HiveModelCreationHelper.MockTypedEntity(true); var definition2 = new NodeNameAttributeDefinition(FixedGroupDefinitions.GeneralGroup); definition2.AttributeGroup.Id = new HiveId(Guid.NewGuid()); entityToImport.EntitySchema.AttributeDefinitions.Add(definition2); //Serialize and deserialize IStreamedResult result = SerializationService.ToStream(entityToImport); object obj = SerializationService.FromStream(result.ResultStream, typeof(TypedEntity)); TypedEntity typedEntity = obj as TypedEntity; // Act //Save entity with NodeNameAttributeDefinition to repository //Id for Group should be set 'automatically' using (var uow = Hive.OpenWriter <IContentStore>()) { uow.Repositories.AddOrUpdate(entity); uow.Complete(); } //Try to save/import deserialized entity using (var uow = Hive.OpenWriter <IContentStore>()) { uow.Repositories.AddOrUpdate(typedEntity); uow.Complete(); } // Assert Assert.That(entity.AttributeGroups.Any(x => x.Alias == "rebel-internal-general-properties"), Is.True); Assert.That(typedEntity.AttributeGroups.Any(x => x.Alias == "rebel-internal-general-properties"), Is.True); Assert.That(entity.AttributeGroups.Any(x => x.Id == HiveId.Empty), Is.False); Assert.That(typedEntity.AttributeGroups.Any(x => x.Id == HiveId.Empty), Is.False); }
/// <summary> /// TEMPORARY method to install all data required for dev data set excluding all of the core data /// </summary> /// <param name="manager"></param> /// <param name="framework"></param> internal void InstallDevDataset(IHiveManager manager, IFrameworkContext framework) { //LogHelper.Error<PugpigInstallTask>( // string.Format("Inside the dataset class"), new Exception()); //a list of all the schemas we've added var schemas = new List<EntitySchema>(); using (var writer = manager.OpenWriter<IContentStore>()) { //create all of the document type's and their associated tabs first //foreach (var d in _devDataSet.ContentData.Select(x => x.DocumentType).DistinctBy(x => x.Id)) foreach (var d in DocTypes) { var schema = new EntitySchema(d.Alias, d.Name); schema.Id = d.Id; schema.AttributeGroups.AddRange( framework.TypeMappers.Map<IEnumerable<Tab>, IEnumerable<AttributeGroup>>( d.DefinedTabs)); writer.Repositories.Schemas.AddOrUpdate(schema); schemas.Add(schema); foreach (var parentId in d.InheritFrom.Where(x => x.Selected).Select(x => HiveId.Parse(x.Value))) writer.Repositories.AddRelation(new Relation(FixedRelationTypes.DefaultRelationType, parentId, d.Id)); } writer.Complete(); } using (var writer = manager.OpenWriter<IContentStore>()) { //now we can hopefully just map the schema and re-save it so it maps all properties //foreach (var d in _devDataSet.ContentData.Select(x => x.DocumentType).DistinctBy(x => x.Id)) IEnumerable<TypedEntity> typedEntities = writer.Repositories.GetAll<TypedEntity>(); foreach (var d in DocTypes) { var schema = framework.TypeMappers.Map<DocumentTypeEditorModel, EntitySchema>(d); writer.Repositories.Schemas.AddOrUpdate(schema); } writer.Complete(); } using (var writer = manager.OpenWriter<IContentStore>()) { //now just map the entire content entities and persist them, since the attribution definitions and attribution //groups are created these should just map up to the entities in the database. var mappedCollection = framework .TypeMappers.Map<IEnumerable<ContentEditorModel>, IEnumerable<Revision<TypedEntity>>>(ContentData) .ToArray(); mappedCollection.ForEach(x => x.MetaData.StatusType = FixedStatusTypes.Published); //var allAttribTypes = AllAttribTypes(mappedCollection); writer.Repositories.Revisions.AddOrUpdate(mappedCollection); writer.Complete(); } ////now that the data is in there, we need to setup some structure... probably a nicer way to do this but whatevs... its just for testing //using (var writer = mappingGroup.CreateReadWriteUnitOfWork()) //{ // var homeSchema = writer.ReadWriteRepository.GetEntity<EntitySchema>(HiveId.ConvertIntToGuid(1045)); // var contentSchema = writer.ReadWriteRepository.GetEntity<EntitySchema>(HiveId.ConvertIntToGuid(1045)); // var faqContainerSchema = writer.ReadWriteRepository.GetEntity<EntitySchema>(HiveId.ConvertIntToGuid(1055)); // var faqCatSchema = writer.ReadWriteRepository.GetEntity<EntitySchema>(HiveId.ConvertIntToGuid(1056)); // var faqSchema = writer.ReadWriteRepository.GetEntity<EntitySchema>(HiveId.ConvertIntToGuid(1057)); //} }
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()); } }
/// <summary> /// TEMPORARY method to install all data required for dev data set excluding all of the core data /// </summary> /// <param name="manager"></param> /// <param name="framework"></param> internal void InstallDevDataset(IHiveManager manager, IFrameworkContext framework) { //a list of all the schemas we've added var schemas = new List <EntitySchema>(); using (var writer = manager.OpenWriter <IContentStore>()) { //create all of the document type's and their associated tabs first //foreach (var d in _devDataSet.ContentData.Select(x => x.DocumentType).DistinctBy(x => x.Id)) foreach (var d in DocTypes) { var schema = new EntitySchema(d.Alias, d.Name); schema.Id = d.Id; schema.AttributeGroups.AddRange( framework.TypeMappers.Map <IEnumerable <Tab>, IEnumerable <AttributeGroup> >( d.DefinedTabs)); writer.Repositories.Schemas.AddOrUpdate(schema); schemas.Add(schema); foreach (var parentId in d.InheritFrom.Where(x => x.Selected).Select(x => HiveId.Parse(x.Value))) { writer.Repositories.AddRelation(new Relation(FixedRelationTypes.DefaultRelationType, parentId, d.Id)); } } writer.Complete(); } using (var writer = manager.OpenWriter <IContentStore>()) { //now we can hopefully just map the schema and re-save it so it maps all properties //foreach (var d in _devDataSet.ContentData.Select(x => x.DocumentType).DistinctBy(x => x.Id)) foreach (var d in DocTypes) { var schema = framework.TypeMappers.Map <DocumentTypeEditorModel, EntitySchema>(d); writer.Repositories.Schemas.AddOrUpdate(schema); } writer.Complete(); } using (var writer = manager.OpenWriter <IContentStore>()) { //now just map the entire content entities and persist them, since the attribution definitions and attribution //groups are created these should just map up to the entities in the database. var mappedCollection = framework .TypeMappers.Map <IEnumerable <ContentEditorModel>, IEnumerable <Revision <TypedEntity> > >(ContentData) .ToArray(); mappedCollection.ForEach(x => x.MetaData.StatusType = FixedStatusTypes.Published); //var allAttribTypes = AllAttribTypes(mappedCollection); writer.Repositories.Revisions.AddOrUpdate(mappedCollection); writer.Complete(); } ////now that the data is in there, we need to setup some structure... probably a nicer way to do this but whatevs... its just for testing //using (var writer = mappingGroup.CreateReadWriteUnitOfWork()) //{ // var homeSchema = writer.ReadWriteRepository.GetEntity<EntitySchema>(HiveId.ConvertIntToGuid(1045)); // var contentSchema = writer.ReadWriteRepository.GetEntity<EntitySchema>(HiveId.ConvertIntToGuid(1045)); // var faqContainerSchema = writer.ReadWriteRepository.GetEntity<EntitySchema>(HiveId.ConvertIntToGuid(1055)); // var faqCatSchema = writer.ReadWriteRepository.GetEntity<EntitySchema>(HiveId.ConvertIntToGuid(1056)); // var faqSchema = writer.ReadWriteRepository.GetEntity<EntitySchema>(HiveId.ConvertIntToGuid(1057)); //} }
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()); } }