public void TagsCanBeVariant() { var languageService = LocalizationService; var language = new LanguageBuilder() .WithCultureInfo("fr-FR") .Build(); LocalizationService.Save(language); // en-US is already there var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); var contentType = ContentTypeBuilder.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", mandatoryProperties: true, defaultTemplateId: template.Id); CreateAndAddTagsPropertyType(contentType, ContentVariation.Culture); ContentTypeService.Save(contentType); IContent content1 = ContentBuilder.CreateSimpleContent(contentType, "Tagged content 1"); content1.SetCultureName("name-fr", "fr-FR"); content1.SetCultureName("name-en", "en-US"); content1.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", new[] { "hello", "world", "some", "tags", "plus" }, culture: "fr-FR"); content1.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", new[] { "hello", "world", "another", "one" }, culture: "en-US"); ContentService.SaveAndPublish(content1); content1 = ContentService.GetById(content1.Id); var frTags = content1.Properties["tags"] .GetTagsValue(PropertyEditorCollection, DataTypeService, Serializer, "fr-FR").ToArray(); Assert.AreEqual(5, frTags.Length); Assert.Contains("plus", frTags); Assert.AreEqual(-1, frTags.IndexOf("one")); var enTags = content1.Properties["tags"] .GetTagsValue(PropertyEditorCollection, DataTypeService, Serializer, "en-US").ToArray(); Assert.AreEqual(4, enTags.Length); Assert.Contains("one", enTags); Assert.AreEqual(-1, enTags.IndexOf("plus")); var tagGroups = TagService.GetAllTags(culture: "*").GroupBy(x => x.LanguageId); foreach (var tag in TagService.GetAllTags()) { Console.WriteLine($"{tag.Group}:{tag.Text} {tag.LanguageId}"); } Assert.AreEqual(2, tagGroups.Count()); var frTagGroup = tagGroups.FirstOrDefault(x => x.Key == 2); Assert.IsNotNull(frTagGroup); Assert.AreEqual(5, frTagGroup.Count()); Assert.IsTrue(frTagGroup.Any(x => x.Text == "plus")); Assert.IsFalse(frTagGroup.Any(x => x.Text == "one")); var enTagGroup = tagGroups.FirstOrDefault(x => x.Key == 1); Assert.IsNotNull(enTagGroup); Assert.AreEqual(4, enTagGroup.Count()); Assert.IsTrue(enTagGroup.Any(x => x.Text == "one")); Assert.IsFalse(enTagGroup.Any(x => x.Text == "plus")); }
public void IContentTypeComposition_To_ContentTypeDisplay() { // Arrange var ctMain = ContentTypeBuilder.CreateSimpleContentType(); // not assigned to tab ctMain.AddPropertyType( new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) { Alias = "umbracoUrlName", Name = "Slug", Description = string.Empty, Mandatory = false, SortOrder = 1, DataTypeId = -88 }); ContentTypeBuilder.EnsureAllIds(ctMain, 8888); var ctChild1 = ContentTypeBuilder.CreateSimpleContentType("child1", "Child 1", ctMain, randomizeAliases: true); ctChild1.AddPropertyType( new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) { Alias = "someProperty", Name = "Some Property", Description = string.Empty, Mandatory = false, SortOrder = 1, DataTypeId = -88 }, "anotherTab", "Another tab"); ContentTypeBuilder.EnsureAllIds(ctChild1, 7777); var contentType = ContentTypeBuilder.CreateSimpleContentType("child2", "Child 2", ctChild1, randomizeAliases: true, propertyGroupAlias: "customGroup", propertyGroupName: "CustomGroup"); // not assigned to tab contentType.AddPropertyType( new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) { Alias = "umbracoUrlAlias", Name = "AltUrl", Description = string.Empty, Mandatory = false, SortOrder = 1, DataTypeId = -88 }); ContentTypeBuilder.EnsureAllIds(contentType, 6666); // Act var result = _sut.Map <DocumentTypeDisplay>(contentType); // Assert Assert.AreEqual(contentType.Alias, result.Alias); Assert.AreEqual(contentType.Description, result.Description); Assert.AreEqual(contentType.Icon, result.Icon); Assert.AreEqual(contentType.Id, result.Id); Assert.AreEqual(contentType.Name, result.Name); Assert.AreEqual(contentType.ParentId, result.ParentId); Assert.AreEqual(contentType.Path, result.Path); Assert.AreEqual(contentType.Thumbnail, result.Thumbnail); Assert.AreEqual(contentType.IsContainer, result.IsContainer); Assert.AreEqual(contentType.CreateDate, result.CreateDate); Assert.AreEqual(contentType.UpdateDate, result.UpdateDate); Assert.AreEqual(contentType.DefaultTemplate.Alias, result.DefaultTemplate.Alias); Assert.AreEqual(contentType.CompositionPropertyGroups.Select(x => x.Name).Distinct().Count(), result.Groups.Count(x => x.IsGenericProperties == false)); Assert.AreEqual(1, result.Groups.Count(x => x.IsGenericProperties)); Assert.AreEqual(contentType.PropertyGroups.Count(), result.Groups.Count(x => x.Inherited == false && x.IsGenericProperties == false)); var allPropertiesMapped = result.Groups.SelectMany(x => x.Properties).ToArray(); var allPropertyIdsMapped = allPropertiesMapped.Select(x => x.Id).ToArray(); var allSourcePropertyIds = contentType.CompositionPropertyTypes.Select(x => x.Id).ToArray(); Assert.AreEqual(contentType.PropertyTypes.Count(), allPropertiesMapped.Count(x => x.Inherited == false)); Assert.AreEqual(allPropertyIdsMapped.Count(), allSourcePropertyIds.Count()); Assert.IsTrue(allPropertyIdsMapped.ContainsAll(allSourcePropertyIds)); Assert.AreEqual(2, result.Groups.Count(x => x.ParentTabContentTypes.Any())); Assert.IsTrue( result.Groups.SelectMany(x => x.ParentTabContentTypes).ContainsAll(new[] { ctMain.Id, ctChild1.Id })); Assert.AreEqual(contentType.AllowedTemplates.Count(), result.AllowedTemplates.Count()); for (var i = 0; i < contentType.AllowedTemplates.Count(); i++) { Assert.AreEqual(contentType.AllowedTemplates.ElementAt(i).Id, result.AllowedTemplates.ElementAt(i).Id); } Assert.AreEqual(contentType.AllowedContentTypes.Count(), result.AllowedContentTypes.Count()); for (var i = 0; i < contentType.AllowedContentTypes.Count(); i++) { Assert.AreEqual(contentType.AllowedContentTypes.ElementAt(i).Id.Value, result.AllowedContentTypes.ElementAt(i)); } }
public void TagsAreUpdatedWhenContentIsTrashedAndUnTrashed_Tree() { var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); var contentType = ContentTypeBuilder.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", mandatoryProperties: true, defaultTemplateId: template.Id); CreateAndAddTagsPropertyType(contentType); ContentTypeService.Save(contentType); var content1 = ContentBuilder.CreateSimpleContent(contentType, "Tagged content 1"); content1.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", new[] { "hello", "world", "some", "tags", "plus" }); ContentService.SaveAndPublish(content1); var content2 = ContentBuilder.CreateSimpleContent(contentType, "Tagged content 2", content1.Id); content2.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", new[] { "hello", "world", "some", "tags" }); ContentService.SaveAndPublish(content2); // verify var tags = TagService.GetTagsForEntity(content1.Id); Assert.AreEqual(5, tags.Count()); var allTags = TagService.GetAllContentTags(); Assert.AreEqual(5, allTags.Count()); ContentService.MoveToRecycleBin(content1); // no more tags tags = TagService.GetTagsForEntity(content1.Id); Assert.AreEqual(0, tags.Count()); tags = TagService.GetTagsForEntity(content2.Id); Assert.AreEqual(0, tags.Count()); // no more tags allTags = TagService.GetAllContentTags(); Assert.AreEqual(0, allTags.Count()); ContentService.Move(content1, -1); Assert.IsFalse(content1.Published); // no more tags tags = TagService.GetTagsForEntity(content1.Id); Assert.AreEqual(0, tags.Count()); tags = TagService.GetTagsForEntity(content2.Id); Assert.AreEqual(0, tags.Count()); // no more tags allTags = TagService.GetAllContentTags(); Assert.AreEqual(0, allTags.Count()); content1.PublishCulture(CultureImpact.Invariant); ContentService.SaveAndPublish(content1); Assert.IsTrue(content1.Published); // tags are back tags = TagService.GetTagsForEntity(content1.Id); Assert.AreEqual(5, tags.Count()); // FIXME: tag & tree issue // when we publish, we 'just' publish the top one and not the ones below = fails // what we should do is... NOT clear tags when unpublishing or trashing or... // and just update the tag service to NOT return anything related to trashed or // unpublished entities (since trashed is set on ALL entities in the trashed branch) tags = TagService.GetTagsForEntity(content2.Id); // including that one! Assert.AreEqual(4, tags.Count()); // tags are back allTags = TagService.GetAllContentTags(); Assert.AreEqual(5, allTags.Count()); }
public void Create_Tag_Data_Bulk_Publish_Operation() { // Arrange // set configuration var dataType = DataTypeService.GetDataType(1041); dataType.Configuration = new TagConfiguration { Group = "test", StorageType = TagsStorageType.Csv }; var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); var contentType = ContentTypeBuilder.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", mandatoryProperties: true, defaultTemplateId: template.Id); CreateAndAddTagsPropertyType(contentType); ContentTypeService.Save(contentType); contentType.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy <int>(() => contentType.Id), 0, contentType.Alias) }; var content = ContentBuilder.CreateSimpleContent(contentType, "Tagged content"); content.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", new[] { "hello", "world", "some", "tags" }); ContentService.Save(content); var child1 = ContentBuilder.CreateSimpleContent(contentType, "child 1 content", content.Id); child1.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", new[] { "hello1", "world1", "some1" }); ContentService.Save(child1); var child2 = ContentBuilder.CreateSimpleContent(contentType, "child 2 content", content.Id); child2.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", new[] { "hello2", "world2" }); ContentService.Save(child2); // Act ContentService.SaveAndPublishBranch(content, true); // Assert var propertyTypeId = contentType.PropertyTypes.Single(x => x.Alias == "tags").Id; using (var scope = ScopeProvider.CreateScope()) { Assert.AreEqual(4, ScopeAccessor.AmbientScope.Database.ExecuteScalar <int>( "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId", new { nodeId = content.Id, propTypeId = propertyTypeId })); Assert.AreEqual(3, ScopeAccessor.AmbientScope.Database.ExecuteScalar <int>( "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId", new { nodeId = child1.Id, propTypeId = propertyTypeId })); Assert.AreEqual(2, ScopeAccessor.AmbientScope.Database.ExecuteScalar <int>( "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId", new { nodeId = child2.Id, propTypeId = propertyTypeId })); scope.Complete(); } }
public void TagsCanBecomeVariant() { var enId = LocalizationService.GetLanguageIdByIsoCode("en-US").Value; var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); var contentType = ContentTypeBuilder.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", mandatoryProperties: true, defaultTemplateId: template.Id); var propertyType = CreateAndAddTagsPropertyType(contentType); ContentTypeService.Save(contentType); IContent content1 = ContentBuilder.CreateSimpleContent(contentType, "Tagged content 1"); content1.AssignTags(PropertyEditorCollection, DataTypeService, Serializer, "tags", new[] { "hello", "world", "another", "one" }); ContentService.SaveAndPublish(content1); contentType.Variations = ContentVariation.Culture; ContentTypeService.Save(contentType); // no changes content1 = ContentService.GetById(content1.Id); var tags = content1.Properties["tags"].GetTagsValue(PropertyEditorCollection, DataTypeService, Serializer) .ToArray(); Assert.AreEqual(4, tags.Length); Assert.Contains("one", tags); Assert.AreEqual(-1, tags.IndexOf("plus")); var tagGroups = TagService.GetAllTags().GroupBy(x => x.LanguageId); foreach (var tag in TagService.GetAllTags()) { Console.WriteLine($"{tag.Group}:{tag.Text} {tag.LanguageId}"); } Assert.AreEqual(1, tagGroups.Count()); var enTagGroup = tagGroups.FirstOrDefault(x => x.Key == null); Assert.IsNotNull(enTagGroup); Assert.AreEqual(4, enTagGroup.Count()); Assert.IsTrue(enTagGroup.Any(x => x.Text == "one")); Assert.IsFalse(enTagGroup.Any(x => x.Text == "plus")); propertyType.Variations = ContentVariation.Culture; ContentTypeService.Save(contentType); // changes content1 = ContentService.GetById(content1.Id); // property value has been moved from invariant to en-US tags = content1.Properties["tags"].GetTagsValue(PropertyEditorCollection, DataTypeService, Serializer) .ToArray(); Assert.IsEmpty(tags); tags = content1.Properties["tags"].GetTagsValue(PropertyEditorCollection, DataTypeService, Serializer, "en-US") .ToArray(); Assert.AreEqual(4, tags.Length); Assert.Contains("one", tags); Assert.AreEqual(-1, tags.IndexOf("plus")); // tags have been copied from invariant to en-US tagGroups = TagService.GetAllTags(culture: "*").GroupBy(x => x.LanguageId); foreach (var tag in TagService.GetAllTags("*")) { Console.WriteLine($"{tag.Group}:{tag.Text} {tag.LanguageId}"); } Assert.AreEqual(1, tagGroups.Count()); enTagGroup = tagGroups.FirstOrDefault(x => x.Key == enId); Assert.IsNotNull(enTagGroup); Assert.AreEqual(4, enTagGroup.Count()); Assert.IsTrue(enTagGroup.Any(x => x.Text == "one")); Assert.IsFalse(enTagGroup.Any(x => x.Text == "plus")); }
public void Get_All_User_Permissions_For_All_Nodes_With_Explicit_Permission() { // Arrange UserGroup userGroup1 = CreateTestUserGroup(); UserGroup userGroup2 = CreateTestUserGroup("test2", "Test 2"); UserGroup userGroup3 = CreateTestUserGroup("test3", "Test 3"); IUser user = UserService.CreateUserWithIdentity("John Doe", "*****@*****.**"); int defaultPermissionCount = userGroup3.Permissions.Count(); user.AddGroup(userGroup1); user.AddGroup(userGroup2); user.AddGroup(userGroup3); UserService.Save(user); Template template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); ContentType contentType = ContentTypeBuilder.CreateSimpleContentType(defaultTemplateId: template.Id); ContentTypeService.Save(contentType); Content[] content = new[] { ContentBuilder.CreateSimpleContent(contentType), ContentBuilder.CreateSimpleContent(contentType), ContentBuilder.CreateSimpleContent(contentType) }; ContentService.Save(content); // assign permissions - we aren't assigning anything explicit for group3 and nothing explicit for content[2] /w group2 ContentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup1.Id }); ContentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup1.Id }); ContentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup2.Id }); ContentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup1.Id }); ContentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup2.Id }); ContentService.SetPermission(content[2], ActionDelete.ActionLetter, new int[] { userGroup1.Id }); // Act // we don't pass in any nodes so it will return all of them EntityPermission[] result = UserService.GetPermissions(user).ToArray(); var permissions = result .GroupBy(x => x.EntityId) .ToDictionary(x => x.Key, x => x.GroupBy(a => a.UserGroupId).ToDictionary(a => a.Key, a => a.ToArray())); // Assert // there will be 3 since that is how many content items there are Assert.AreEqual(3, permissions.Count); // test permissions contains content[0] Assert.IsTrue(permissions.ContainsKey(content[0].Id)); // test that this permissions set contains permissions for all groups Assert.IsTrue(permissions[content[0].Id].ContainsKey(userGroup1.Id)); Assert.IsTrue(permissions[content[0].Id].ContainsKey(userGroup2.Id)); Assert.IsTrue(permissions[content[0].Id].ContainsKey(userGroup3.Id)); // test that the correct number of permissions are returned for each group Assert.AreEqual(2, permissions[content[0].Id][userGroup1.Id].SelectMany(x => x.AssignedPermissions).Count()); Assert.AreEqual(1, permissions[content[0].Id][userGroup2.Id].SelectMany(x => x.AssignedPermissions).Count()); Assert.AreEqual(defaultPermissionCount, permissions[content[0].Id][userGroup3.Id].SelectMany(x => x.AssignedPermissions).Count()); // test permissions contains content[1] Assert.IsTrue(permissions.ContainsKey(content[1].Id)); // test that this permissions set contains permissions for all groups Assert.IsTrue(permissions[content[1].Id].ContainsKey(userGroup1.Id)); Assert.IsTrue(permissions[content[1].Id].ContainsKey(userGroup2.Id)); Assert.IsTrue(permissions[content[1].Id].ContainsKey(userGroup3.Id)); // test that the correct number of permissions are returned for each group Assert.AreEqual(1, permissions[content[1].Id][userGroup1.Id].SelectMany(x => x.AssignedPermissions).Count()); Assert.AreEqual(1, permissions[content[1].Id][userGroup2.Id].SelectMany(x => x.AssignedPermissions).Count()); Assert.AreEqual(defaultPermissionCount, permissions[content[1].Id][userGroup3.Id].SelectMany(x => x.AssignedPermissions).Count()); // test permissions contains content[2] Assert.IsTrue(permissions.ContainsKey(content[2].Id)); // test that this permissions set contains permissions for all groups Assert.IsTrue(permissions[content[2].Id].ContainsKey(userGroup1.Id)); Assert.IsTrue(permissions[content[2].Id].ContainsKey(userGroup2.Id)); Assert.IsTrue(permissions[content[2].Id].ContainsKey(userGroup3.Id)); // test that the correct number of permissions are returned for each group Assert.AreEqual(1, permissions[content[2].Id][userGroup1.Id].SelectMany(x => x.AssignedPermissions).Count()); Assert.AreEqual(defaultPermissionCount, permissions[content[2].Id][userGroup2.Id].SelectMany(x => x.AssignedPermissions).Count()); Assert.AreEqual(defaultPermissionCount, permissions[content[2].Id][userGroup3.Id].SelectMany(x => x.AssignedPermissions).Count()); }
public void Can_Get_Tags_For_Entity_Type_For_Group() { IScopeProvider provider = ScopeProvider; using (ScopeProvider.CreateScope()) { // create data to relate to // We have to create and save a template, otherwise we get an FK violation on contentType. Template template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); ContentType contentType = ContentTypeBuilder.CreateSimpleContentType("test", "Test", defaultTemplateId: template.Id); ContentTypeRepository.Save(contentType); Content content1 = ContentBuilder.CreateSimpleContent(contentType); DocumentRepository.Save(content1); MediaType mediaType = MediaTypeBuilder.CreateImageMediaType("image2"); MediaTypeRepository.Save(mediaType); Media media1 = MediaBuilder.CreateMediaImage(mediaType, -1); MediaRepository.Save(media1); TagRepository repository = CreateRepository(provider); Tag[] tags = new[] { new Tag { Text = "tag1", Group = "test" }, new Tag { Text = "tag2", Group = "test1" }, new Tag { Text = "tag3", Group = "test" }, new Tag { Text = "tag4", Group = "test1" } }; repository.Assign( content1.Id, contentType.PropertyTypes.First().Id, tags, false); Tag[] tags2 = new[] { new Tag { Text = "tag1", Group = "test" }, new Tag { Text = "tag2", Group = "test1" } }; repository.Assign( media1.Id, mediaType.PropertyTypes.Last().Id, tags2, false); ITag[] result1 = repository.GetTagsForEntityType(TaggableObjectTypes.Content, "test1").ToArray(); ITag[] result2 = repository.GetTagsForEntityType(TaggableObjectTypes.Media, "test1").ToArray(); Assert.AreEqual(2, result1.Length); Assert.AreEqual(1, result2.Length); } }
public void Can_Get_Tags_For_Content_By_Key() { IScopeProvider provider = ScopeProvider; using (ScopeProvider.CreateScope()) { // create data to relate to // We have to create and save a template, otherwise we get an FK violation on contentType. Template template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); ContentType contentType = ContentTypeBuilder.CreateSimpleContentType("test", "Test", defaultTemplateId: template.Id); ContentTypeRepository.Save(contentType); Content content1 = ContentBuilder.CreateSimpleContent(contentType); DocumentRepository.Save(content1); Content content2 = ContentBuilder.CreateSimpleContent(contentType); DocumentRepository.Save(content2); TagRepository repository = CreateRepository(provider); Tag[] tags = new[] { new Tag { Text = "tag1", Group = "test" }, new Tag { Text = "tag2", Group = "test" }, new Tag { Text = "tag3", Group = "test" }, new Tag { Text = "tag4", Group = "test" } }; repository.Assign( content1.Id, contentType.PropertyTypes.First().Id, tags, false); Tag[] tags2 = new[] { new Tag { Text = "tag1", Group = "test" }, new Tag { Text = "tag2", Group = "test" } }; repository.Assign( content2.Id, contentType.PropertyTypes.First().Id, tags2, false); // get by key IEnumerable <ITag> result = repository.GetTagsForEntity(content2.Key); Assert.AreEqual(2, result.Count()); } }
public void Can_Get_Tagged_Entities_For_Tag() { IScopeProvider provider = ScopeProvider; using (ScopeProvider.CreateScope()) { // create data to relate to // We have to create and save a template, otherwise we get an FK violation on contentType. Template template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); ContentType contentType = ContentTypeBuilder.CreateSimpleContentType("test", "Test", defaultTemplateId: template.Id); ContentTypeRepository.Save(contentType); Content content1 = ContentBuilder.CreateSimpleContent(contentType); DocumentRepository.Save(content1); Content content2 = ContentBuilder.CreateSimpleContent(contentType); DocumentRepository.Save(content2); MediaType mediaType = MediaTypeBuilder.CreateImageMediaType("image2"); MediaTypeRepository.Save(mediaType); Media media1 = MediaBuilder.CreateMediaImage(mediaType, -1); MediaRepository.Save(media1); TagRepository repository = CreateRepository(provider); Tag[] tags = new[] { new Tag { Text = "tag1", Group = "test" }, new Tag { Text = "tag2", Group = "test1" }, new Tag { Text = "tag3", Group = "test" } }; repository.Assign( content1.Id, contentType.PropertyTypes.First().Id, tags, false); Tag[] tags2 = new[] { new Tag { Text = "tag1", Group = "test" }, new Tag { Text = "tag2", Group = "test1" }, }; repository.Assign( content2.Id, contentType.PropertyTypes.Last().Id, tags2, false); Tag[] tags3 = new[] { new Tag { Text = "tag1", Group = "test" }, new Tag { Text = "tag2", Group = "test1" } }; repository.Assign( media1.Id, mediaType.PropertyTypes.Last().Id, tags3, false); TaggedEntity[] contentTestIds = repository.GetTaggedEntitiesByTag(TaggableObjectTypes.Content, "tag1").ToArray(); // there are two content items tagged against the 'tag1' tag Assert.AreEqual(2, contentTestIds.Length); // there are a total of two property types tagged against the 'tag1' tag Assert.AreEqual(2, contentTestIds.SelectMany(x => x.TaggedProperties).Count()); // there are a total of 1 tags since we're only looking against one tag Assert.AreEqual(1, contentTestIds.SelectMany(x => x.TaggedProperties).SelectMany(x => x.Tags).Select(x => x.Id).Distinct().Count()); TaggedEntity[] contentTest1Ids = repository.GetTaggedEntitiesByTag(TaggableObjectTypes.Content, "tag3").ToArray(); // there are 1 content items tagged against the 'tag3' tag Assert.AreEqual(1, contentTest1Ids.Length); // there are a total of two property types tagged against the 'tag3' tag Assert.AreEqual(1, contentTest1Ids.SelectMany(x => x.TaggedProperties).Count()); // there are a total of 1 tags since we're only looking against one tag Assert.AreEqual(1, contentTest1Ids.SelectMany(x => x.TaggedProperties).SelectMany(x => x.Tags).Select(x => x.Id).Distinct().Count()); IEnumerable <TaggedEntity> mediaTestIds = repository.GetTaggedEntitiesByTag(TaggableObjectTypes.Media, "tag1"); Assert.AreEqual(1, mediaTestIds.Count()); } }