コード例 #1
0
        public void Can_Get_Tags_For_Property_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);

                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(
                    content1.Id,
                    contentType.PropertyTypes.Last().Id,
                    tags2,
                    false);

                ITag[] result1 = repository.GetTagsForProperty(content1.Key, contentType.PropertyTypes.First().Alias).ToArray();
                ITag[] result2 = repository.GetTagsForProperty(content1.Key, contentType.PropertyTypes.Last().Alias).ToArray();
                Assert.AreEqual(4, result1.Length);
                Assert.AreEqual(2, result2.Length);
            }
        }
コード例 #2
0
        public void Can_Merge_Tag_Relations()
        {
            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 content = ContentBuilder.CreateSimpleContent(contentType);
                DocumentRepository.Save(content);

                TagRepository repository = CreateRepository(provider);
                Tag[]         tags       = new[]
                {
                    new Tag {
                        Text = "tag1", Group = "test"
                    },
                    new Tag {
                        Text = "tag2", Group = "test"
                    },
                };
                repository.Assign(
                    content.Id,
                    contentType.PropertyTypes.First().Id,
                    tags,
                    false);

                Tag[] tags2 = new[]
                {
                    new Tag {
                        Text = "tag2", Group = "test"
                    },
                    new Tag {
                        Text = "tag3", Group = "test"
                    },
                };
                repository.Assign(
                    content.Id,
                    contentType.PropertyTypes.First().Id,
                    tags2,
                    false);

                IEnumerable <ITag> result = repository.GetTagsForEntity(content.Id);
                Assert.AreEqual(3, result.Count());
            }
        }
コード例 #3
0
        public void Can_Remove_Specific_Tags_From_Property()
        {
            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 content = ContentBuilder.CreateSimpleContent(contentType);
                DocumentRepository.Save(content);

                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(
                    content.Id,
                    contentType.PropertyTypes.First().Id,
                    tags,
                    false);

                Tag[] tagsToRemove = new[]
                {
                    new Tag {
                        Text = "tag2", Group = "test"
                    },
                    new Tag {
                        Text = "tag3", Group = "test"
                    }
                };
                repository.Remove(
                    content.Id,
                    contentType.PropertyTypes.First().Id,
                    tagsToRemove);

                ITag[] result = repository.GetTagsForEntity(content.Id).ToArray();
                Assert.AreEqual(2, result.Length);
                Assert.AreEqual("tag1", result[0].Text);
                Assert.AreEqual("tag4", result[1].Text);
            }
        }
コード例 #4
0
        public void Can_Get_All_With_Ids()
        {
            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);

                // TODO: This would be nice to be able to map the ids back but unfortunately we are not doing this
                // var result = repository.GetAll(new[] {tags[0].Id, tags[1].Id, tags[2].Id});
                ITag[] all = repository.GetMany().ToArray();

                IEnumerable <ITag> result = repository.GetMany(all[0].Id, all[1].Id, all[2].Id);
                Assert.AreEqual(3, result.Count());
            }
        }
コード例 #5
0
        public void Cascade_Deletes_Tag_Relations()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = 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);

                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);

                DocumentRepository.Delete(content1);

                Assert.AreEqual(0, ScopeAccessor.AmbientScope.Database.ExecuteScalar <int>(
                                    "SELECT COUNT(*) FROM cmsTagRelationship WHERE nodeId=@nodeId AND propertyTypeId=@propTypeId",
                                    new { nodeId = content1.Id, propTypeId = contentType.PropertyTypes.First().Id }));
            }
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        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());
            }
        }