示例#1
0
    private IRelation CreateAndSaveRelation(string name, string alias)
    {
        var rs = RelationService;
        var rt = new RelationType(name, alias, false, null, null);

        rs.Save(rt);

        var ct = ContentTypeBuilder.CreateBasicContentType();

        ContentTypeService.Save(ct);

        var mt = MediaTypeBuilder.CreateImageMediaType("img");

        MediaTypeService.Save(mt);

        var c1 = ContentBuilder.CreateBasicContent(ct);
        var c2 = MediaBuilder.CreateMediaImage(mt, -1);

        ContentService.Save(c1);
        MediaService.Save(c2);

        var r = new Relation(c1.Id, c2.Id, rt);

        RelationService.Save(r);

        return(r);
    }
示例#2
0
    /// <summary>
    ///     Creates a bunch of content/media items return relation objects for them (unsaved)
    /// </summary>
    /// <param name="count"></param>
    /// <returns></returns>
    private IEnumerable <IRelation> CreateRelations(int count)
    {
        var rs     = RelationService;
        var rtName = Guid.NewGuid().ToString();
        var rt     = new RelationType(rtName, rtName, false, null, null);

        rs.Save(rt);

        var ct = ContentTypeBuilder.CreateBasicContentType();

        ContentTypeService.Save(ct);

        var mt = MediaTypeBuilder.CreateImageMediaType("img");

        MediaTypeService.Save(mt);

        return(Enumerable.Range(1, count).Select(index =>
        {
            var c1 = ContentBuilder.CreateBasicContent(ct);
            var c2 = MediaBuilder.CreateMediaImage(mt, -1);
            ContentService.Save(c1);
            MediaService.Save(c2);

            return new Relation(c1.Id, c2.Id, rt);
        }).ToList());
    }
    public void Can_Copy_MediaType_By_Performing_Clone()
    {
        // Arrange
        var mediaType = MediaTypeBuilder.CreateImageMediaType("Image2") as IMediaType;

        MediaTypeService.Save(mediaType);

        // Act
        var sut = mediaType.DeepCloneWithResetIdentities("Image2_2");

        Assert.IsNotNull(sut);
        MediaTypeService.Save(sut);

        // Assert
        Assert.That(sut.HasIdentity, Is.True);
        Assert.AreEqual(mediaType.ParentId, sut.ParentId);
        Assert.AreEqual(mediaType.Level, sut.Level);
        Assert.AreEqual(mediaType.PropertyTypes.Count(), sut.PropertyTypes.Count());
        Assert.AreNotEqual(mediaType.Id, sut.Id);
        Assert.AreNotEqual(mediaType.Key, sut.Key);
        Assert.AreNotEqual(mediaType.Path, sut.Path);
        Assert.AreNotEqual(mediaType.SortOrder, sut.SortOrder);
        Assert.AreNotEqual(mediaType.PropertyTypes.First(x => x.Alias.Equals("umbracoFile")).Id,
                           sut.PropertyTypes.First(x => x.Alias.Equals("umbracoFile")).Id);
        Assert.AreNotEqual(mediaType.PropertyGroups.First(x => x.Name.Equals("Media")).Id,
                           sut.PropertyGroups.First(x => x.Name.Equals("Media")).Id);
    }
示例#4
0
        public void Get_Paged_Parent_Child_Entities_With_Same_Entity_Relation()
        {
            // Create a media item and create a relationship between itself (parent -> child)
            MediaType imageType = MediaTypeBuilder.CreateImageMediaType("myImage");

            MediaTypeService.Save(imageType);
            Media media = MediaBuilder.CreateMediaImage(imageType, -1);

            MediaService.Save(media);
            IRelationType relType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias);

            RelationService.Relate(media.Id, media.Id, relType);

            using (IScope scope = ScopeProvider.CreateScope())
            {
                RelationRepository repository = CreateRepository(ScopeProvider, out RelationTypeRepository relationTypeRepository);

                // Get parent entities for child id
                var parents = repository.GetPagedParentEntitiesByChildId(media.Id, 0, 10, out long totalRecords).ToList();
                Assert.AreEqual(1, totalRecords);
                Assert.AreEqual(1, parents.Count);

                // Get child entities for parent id
                var children = repository.GetPagedChildEntitiesByParentId(media.Id, 0, 10, out totalRecords).ToList();
                Assert.AreEqual(1, totalRecords);
                Assert.AreEqual(1, children.Count);
            }
        }
示例#5
0
        public void Export_Zip()
        {
            var mt = MediaTypeBuilder.CreateImageMediaType("testImage");

            MediaTypeService.Save(mt);
            var m1 = MediaBuilder.CreateMediaFile(mt, -1);

            MediaService.Save(m1);

            //Ensure a file exist
            var fullPath = HostingEnvironment.MapPathWebRoot(m1.Properties[Constants.Conventions.Media.File].GetValue().ToString());

            using (StreamWriter file1 = File.CreateText(fullPath))
            {
                file1.WriteLine("hello");
            }

            var def = new PackageDefinition
            {
                Name      = "test",
                MediaUdis = new List <GuidUdi>()
                {
                    m1.GetUdi()
                }
            };

            bool result = PackageBuilder.SavePackage(def);

            Assert.IsTrue(result);
            Assert.IsTrue(def.PackagePath.IsNullOrWhiteSpace());

            string packageXmlPath = PackageBuilder.ExportPackage(def);

            def = PackageBuilder.GetById(def.Id); // re-get
            Assert.IsNotNull(def.PackagePath);

            using (FileStream packageZipStream = File.OpenRead(packageXmlPath))
                using (ZipArchive zipArchive = PackageMigrationResource.GetPackageDataManifest(packageZipStream, out XDocument packageXml))
                {
                    string test = "test-file.txt";
                    Assert.Multiple(() =>
                    {
                        var mediaEntry = zipArchive.GetEntry("media/media/test-file.txt");
                        Assert.AreEqual("umbPackage", packageXml.Root.Name.ToString());
                        Assert.IsNotNull(mediaEntry);
                        Assert.AreEqual(test, mediaEntry.Name);
                        Assert.IsNotNull(zipArchive.GetEntry("package.xml"));
                        Assert.AreEqual(
                            $"<MediaItems><MediaSet><testImage id=\"{m1.Id}\" key=\"{m1.Key}\" parentID=\"-1\" level=\"1\" creatorID=\"-1\" sortOrder=\"0\" createDate=\"{m1.CreateDate.ToString("s")}\" updateDate=\"{m1.UpdateDate.ToString("s")}\" nodeName=\"Test File\" urlName=\"test-file\" path=\"{m1.Path}\" isDoc=\"\" nodeType=\"{mt.Id}\" nodeTypeAlias=\"testImage\" writerName=\"\" writerID=\"0\" udi=\"{m1.GetUdi()}\" mediaFilePath=\"/media/test-file.txt\"><umbracoFile><![CDATA[/media/test-file.txt]]></umbracoFile><umbracoBytes><![CDATA[100]]></umbracoBytes><umbracoExtension><![CDATA[png]]></umbracoExtension></testImage></MediaSet></MediaItems>",
                            packageXml.Element("umbPackage").Element("MediaItems").ToString(SaveOptions.DisableFormatting));
                        Assert.AreEqual(2, zipArchive.Entries.Count());
                        Assert.AreEqual(ZipArchiveMode.Read, zipArchive.Mode);
                        Assert.IsNull(packageXml.DocumentType);
                        Assert.IsNull(packageXml.NextNode);
                        Assert.IsNull(packageXml.Parent);
                        Assert.IsNull(packageXml.PreviousNode);
                    });
                }
        }
示例#6
0
        private void CreateTestDataForPagingTests(out List <IContent> createdContent, out List <IMember> createdMembers, out List <IMedia> createdMedia)
        {
            // Create content
            createdContent = new List <IContent>();
            ContentType contentType = ContentTypeBuilder.CreateBasicContentType("blah");

            ContentTypeService.Save(contentType);
            for (int i = 0; i < 3; i++)
            {
                Content c1 = ContentBuilder.CreateBasicContent(contentType);
                ContentService.Save(c1);
                createdContent.Add(c1);
            }

            // Create media
            createdMedia = new List <IMedia>();
            MediaType imageType = MediaTypeBuilder.CreateImageMediaType("myImage");

            MediaTypeService.Save(imageType);
            for (int i = 0; i < 3; i++)
            {
                Media c1 = MediaBuilder.CreateMediaImage(imageType, -1);
                MediaService.Save(c1);
                createdMedia.Add(c1);
            }

            // Create members
            MemberType memberType = MemberTypeBuilder.CreateSimpleMemberType("simple");

            MemberTypeService.Save(memberType);
            createdMembers = MemberBuilder.CreateSimpleMembers(memberType, 3).ToList();
            GetMemberService().Save(createdMembers);

            IRelationType relType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias);

            // Relate content to media
            foreach (IContent content in createdContent)
            {
                foreach (IMedia media in createdMedia)
                {
                    RelationService.Relate(content.Id, media.Id, relType);
                }
            }

            // Relate members to media
            foreach (IMember member in createdMembers)
            {
                foreach (IMedia media in createdMedia)
                {
                    RelationService.Relate(member.Id, media.Id, relType);
                }
            }
        }
示例#7
0
    public void Get_Paged_Relations_By_Relation_Type()
    {
        // Create content
        var createdContent = new List <IContent>();
        var contentType    = ContentTypeBuilder.CreateBasicContentType("blah");

        ContentTypeService.Save(contentType);
        for (var i = 0; i < 3; i++)
        {
            var c1 = ContentBuilder.CreateBasicContent(contentType);
            ContentService.Save(c1);
            createdContent.Add(c1);
        }

        // Create media
        var createdMedia = new List <IMedia>();
        var imageType    = MediaTypeBuilder.CreateImageMediaType("myImage");

        MediaTypeService.Save(imageType);
        for (var i = 0; i < 3; i++)
        {
            var c1 = MediaBuilder.CreateMediaImage(imageType, -1);
            MediaService.Save(c1);
            createdMedia.Add(c1);
        }

        var relType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias);

        // Relate content to media
        foreach (var content in createdContent)
        {
            foreach (var media in createdMedia)
            {
                RelationService.Relate(content.Id, media.Id, relType);
            }
        }

        var paged = RelationService.GetPagedByRelationTypeId(relType.Id, 0, 4, out var totalRecs).ToList();

        Assert.AreEqual(9, totalRecs);
        Assert.AreEqual(4, paged.Count);

        // next page
        paged.AddRange(RelationService.GetPagedByRelationTypeId(relType.Id, 1, 4, out totalRecs));

        Assert.AreEqual(9, totalRecs);
        Assert.AreEqual(8, paged.Count);

        Assert.IsTrue(createdContent.Select(x => x.Id).ContainsAll(paged.Select(x => x.ParentId)));
        Assert.IsTrue(createdMedia.Select(x => x.Id).ContainsAll(paged.Select(x => x.ChildId)));
    }
        public void Can_Get_Media_By_Path()
        {
            MediaType mediaType = MediaTypeBuilder.CreateImageMediaType("Image2");

            MediaTypeService.Save(mediaType);

            Media media = MediaBuilder.CreateMediaImage(mediaType, -1);

            MediaService.Save(media);

            string mediaPath     = "/media/test-image.png";
            IMedia resolvedMedia = MediaService.GetMediaByPath(mediaPath);

            Assert.IsNotNull(resolvedMedia);
            Assert.That(resolvedMedia.GetValue(Constants.Conventions.Media.File).ToString() == mediaPath);
        }
    public void Can_Copy_MediaType_To_New_Parent_By_Performing_Clone()
    {
        // Arrange
        var parentMediaType1 = MediaTypeBuilder.CreateSimpleMediaType("parent1", "Parent1");

        MediaTypeService.Save(parentMediaType1);
        var parentMediaType2 = MediaTypeBuilder.CreateSimpleMediaType("parent2", "Parent2", null, true);

        MediaTypeService.Save(parentMediaType2);
        var mediaType = MediaTypeBuilder.CreateImageMediaType("Image2") as IMediaType;

        MediaTypeService.Save(mediaType);

        // Act
        var clone = mediaType.DeepCloneWithResetIdentities("newcategory");

        Assert.IsNotNull(clone);
        clone.RemoveContentType("parent1");
        clone.AddContentType(parentMediaType2);
        clone.ParentId = parentMediaType2.Id;
        MediaTypeService.Save(clone);

        // Assert
        Assert.That(clone.HasIdentity, Is.True);

        var clonedMediaType   = MediaTypeService.Get(clone.Id);
        var originalMediaType = MediaTypeService.Get(mediaType.Id);

        Assert.That(clonedMediaType.CompositionAliases().Any(x => x.Equals("parent2")), Is.True);
        Assert.That(clonedMediaType.CompositionAliases().Any(x => x.Equals("parent1")), Is.False);

        Assert.AreEqual(clonedMediaType.Path, "-1," + parentMediaType2.Id + "," + clonedMediaType.Id);
        Assert.AreEqual(clonedMediaType.PropertyTypes.Count(), originalMediaType.PropertyTypes.Count());

        Assert.AreNotEqual(clonedMediaType.ParentId, originalMediaType.ParentId);
        Assert.AreEqual(clonedMediaType.ParentId, parentMediaType2.Id);

        Assert.AreNotEqual(clonedMediaType.Id, originalMediaType.Id);
        Assert.AreNotEqual(clonedMediaType.Key, originalMediaType.Key);
        Assert.AreNotEqual(clonedMediaType.Path, originalMediaType.Path);

        Assert.AreNotEqual(clonedMediaType.PropertyTypes.First(x => x.Alias.StartsWith("umbracoFile")).Id,
                           originalMediaType.PropertyTypes.First(x => x.Alias.StartsWith("umbracoFile")).Id);
        Assert.AreNotEqual(clonedMediaType.PropertyGroups.First(x => x.Name.StartsWith("Media")).Id,
                           originalMediaType.PropertyGroups.First(x => x.Name.StartsWith("Media")).Id);
    }
示例#10
0
    public void Can_Get_Paged_Children_Dont_Get_Descendants()
    {
        var mediaType = MediaTypeBuilder.CreateImageMediaType("Image2");

        MediaTypeService.Save(mediaType);

        // Only add 9 as we also add a folder with children.
        for (var i = 0; i < 9; i++)
        {
            var m1 = MediaBuilder.CreateMediaImage(mediaType, -1);
            MediaService.Save(m1);
        }

        var mediaTypeForFolder = MediaTypeBuilder.CreateImageMediaType("Folder2");

        MediaTypeService.Save(mediaTypeForFolder);
        var mediaFolder = MediaBuilder.CreateMediaFolder(mediaTypeForFolder, -1);

        MediaService.Save(mediaFolder);
        for (var i = 0; i < 10; i++)
        {
            var m1 = MediaBuilder.CreateMediaImage(mediaType, mediaFolder.Id);
            MediaService.Save(m1);
        }

        var service = MediaService;

        // Children in root including the folder - not the descendants in the folder.
        var entities = service.GetPagedChildren(-1, 0, 6, out var total).ToArray();

        Assert.That(entities.Length, Is.EqualTo(6));
        Assert.That(total, Is.EqualTo(10));
        entities = service.GetPagedChildren(-1, 1, 6, out total).ToArray();
        Assert.That(entities.Length, Is.EqualTo(4));
        Assert.That(total, Is.EqualTo(10));

        // Children in folder.
        entities = service.GetPagedChildren(mediaFolder.Id, 0, 6, out total).ToArray();
        Assert.That(entities.Length, Is.EqualTo(6));
        Assert.That(total, Is.EqualTo(10));
        entities = service.GetPagedChildren(mediaFolder.Id, 1, 6, out total).ToArray();
        Assert.That(entities.Length, Is.EqualTo(4));
        Assert.That(total, Is.EqualTo(10));
    }
示例#11
0
        public void Get_Paged_Children_With_Media_Type_Filter()
        {
            MediaType mediaType1 = MediaTypeBuilder.CreateImageMediaType("Image2");

            MediaTypeService.Save(mediaType1);
            MediaType mediaType2 = MediaTypeBuilder.CreateImageMediaType("Image3");

            MediaTypeService.Save(mediaType2);

            for (int i = 0; i < 10; i++)
            {
                Media m1 = MediaBuilder.CreateMediaImage(mediaType1, -1);
                MediaService.Save(m1);
                Media m2 = MediaBuilder.CreateMediaImage(mediaType2, -1);
                MediaService.Save(m2);
            }

            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                IEnumerable <IMedia> result = MediaService.GetPagedChildren(
                    -1,
                    0,
                    11,
                    out long total,
                    provider.SqlContext.Query <IMedia>()
                    .Where(x => new[] { mediaType1.Id, mediaType2.Id }.Contains(x.ContentTypeId)),
                    Ordering.By("SortOrder", Direction.Ascending));
                Assert.AreEqual(11, result.Count());
                Assert.AreEqual(20, total);

                result = MediaService.GetPagedChildren(
                    -1,
                    1,
                    11,
                    out total,
                    provider.SqlContext.Query <IMedia>()
                    .Where(x => new[] { mediaType1.Id, mediaType2.Id }.Contains(x.ContentTypeId)),
                    Ordering.By("SortOrder", Direction.Ascending));
                Assert.AreEqual(9, result.Count());
                Assert.AreEqual(20, total);
            }
        }
示例#12
0
    public void Get_Paged_Children_With_Media_Type_Filter()
    {
        var mediaType1 = MediaTypeBuilder.CreateImageMediaType("Image2");

        MediaTypeService.Save(mediaType1);
        var mediaType2 = MediaTypeBuilder.CreateImageMediaType("Image3");

        MediaTypeService.Save(mediaType2);

        for (var i = 0; i < 10; i++)
        {
            var m1 = MediaBuilder.CreateMediaImage(mediaType1, -1);
            MediaService.Save(m1);
            var m2 = MediaBuilder.CreateMediaImage(mediaType2, -1);
            MediaService.Save(m2);
        }

        var provider = ScopeProvider;

        using (provider.CreateScope())
        {
            var result = MediaService.GetPagedChildren(
                -1,
                0,
                11,
                out var total,
                provider.CreateQuery <IMedia>()
                .Where(x => new[] { mediaType1.Id, mediaType2.Id }.Contains(x.ContentTypeId)),
                Ordering.By("SortOrder"));
            Assert.AreEqual(11, result.Count());
            Assert.AreEqual(20, total);

            result = MediaService.GetPagedChildren(
                -1,
                1,
                11,
                out total,
                provider.CreateQuery <IMedia>()
                .Where(x => new[] { mediaType1.Id, mediaType2.Id }.Contains(x.ContentTypeId)),
                Ordering.By("SortOrder"));
            Assert.AreEqual(9, result.Count());
            Assert.AreEqual(20, total);
        }
    }
    public void IMediaType_To_MediaTypeDisplay()
    {
        // Arrange
        var mediaType = MediaTypeBuilder.CreateImageMediaType();

        MediaTypeBuilder.EnsureAllIds(mediaType, 8888);

        // Act
        var result = _sut.Map <MediaTypeDisplay>(mediaType);

        // Assert
        Assert.AreEqual(mediaType.Alias, result.Alias);
        Assert.AreEqual(mediaType.Description, result.Description);
        Assert.AreEqual(mediaType.Icon, result.Icon);
        Assert.AreEqual(mediaType.Id, result.Id);
        Assert.AreEqual(mediaType.Name, result.Name);
        Assert.AreEqual(mediaType.ParentId, result.ParentId);
        Assert.AreEqual(mediaType.Path, result.Path);
        Assert.AreEqual(mediaType.Thumbnail, result.Thumbnail);
        Assert.AreEqual(mediaType.IsContainer, result.IsContainer);
        Assert.AreEqual(mediaType.CreateDate, result.CreateDate);
        Assert.AreEqual(mediaType.UpdateDate, result.UpdateDate);

        Assert.AreEqual(mediaType.PropertyGroups.Count(), result.Groups.Count());
        for (var i = 0; i < mediaType.PropertyGroups.Count(); i++)
        {
            Assert.AreEqual(mediaType.PropertyGroups.ElementAt(i).Id, result.Groups.ElementAt(i).Id);
            Assert.AreEqual(mediaType.PropertyGroups.ElementAt(i).Name, result.Groups.ElementAt(i).Name);
            var propTypes = mediaType.PropertyGroups.ElementAt(i).PropertyTypes;

            Assert.AreEqual(propTypes.Count(), result.Groups.ElementAt(i).Properties.Count());
            for (var j = 0; j < propTypes.Count(); j++)
            {
                Assert.AreEqual(propTypes.ElementAt(j).Id, result.Groups.ElementAt(i).Properties.ElementAt(j).Id);
                Assert.AreEqual(propTypes.ElementAt(j).DataTypeId, result.Groups.ElementAt(i).Properties.ElementAt(j).DataTypeId);
            }
        }

        Assert.AreEqual(mediaType.AllowedContentTypes.Count(), result.AllowedContentTypes.Count());
        for (var i = 0; i < mediaType.AllowedContentTypes.Count(); i++)
        {
            Assert.AreEqual(mediaType.AllowedContentTypes.ElementAt(i).Id.Value, result.AllowedContentTypes.ElementAt(i));
        }
    }
示例#14
0
        public void Can_Get_Paged_Children()
        {
            MediaType mediaType = MediaTypeBuilder.CreateImageMediaType("Image2");

            MediaTypeService.Save(mediaType);
            for (int i = 0; i < 10; i++)
            {
                Media c1 = MediaBuilder.CreateMediaImage(mediaType, -1);
                MediaService.Save(c1);
            }

            IMediaService service = MediaService;

            IMedia[] entities = service.GetPagedChildren(-1, 0, 6, out long total).ToArray();
            Assert.That(entities.Length, Is.EqualTo(6));
            Assert.That(total, Is.EqualTo(10));
            entities = service.GetPagedChildren(-1, 1, 6, out total).ToArray();
            Assert.That(entities.Length, Is.EqualTo(4));
            Assert.That(total, Is.EqualTo(10));
        }
        public void GivenSuppressedNotifications_WhenDisposed_ThenNotificationsExecute()
        {
            int asserted = 0;

            using (IScope scope = ScopeProvider.CreateScope(autoComplete: true))
            {
                using IDisposable suppressed = scope.Notifications.Suppress();

                MediaType mediaType = MediaTypeBuilder.CreateImageMediaType("test");
                MediaTypeService.Save(mediaType);

                suppressed.Dispose();

                asserted = TestContext.CurrentContext.AssertCount;
                Media media = MediaBuilder.CreateMediaImage(mediaType, -1);
                MediaService.Save(media);
            }

            Assert.AreEqual(asserted + 1, TestContext.CurrentContext.AssertCount);
        }
示例#16
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());
            }
        }
示例#17
0
        public void Can_Generate_Xml_Representation_Of_Media()
        {
            // Arrange
            var mediaType = MediaTypeBuilder.CreateImageMediaType("image2");

            MediaTypeService.Save(mediaType);

            // reference, so static ctor runs, so event handlers register
            // and then, this will reset the width, height... because the file does not exist, of course ;-(
            var loggerFactory   = NullLoggerFactory.Instance;
            var scheme          = Mock.Of <IMediaPathScheme>();
            var contentSettings = new ContentSettings();

            var mediaFileManager = new MediaFileManager(
                Mock.Of <IFileSystem>(),
                scheme,
                loggerFactory.CreateLogger <MediaFileManager>(),
                ShortStringHelper,
                Services,
                Options.Create(new ContentSettings()));

            var ignored = new FileUploadPropertyEditor(
                DataValueEditorFactory,
                mediaFileManager,
                Options.Create(contentSettings),
                TextService,
                Services.GetRequiredService <UploadAutoFillProperties>(),
                ContentService,
                IOHelper);

            var media = MediaBuilder.CreateMediaImage(mediaType, -1);

            media.WriterId = -1; // else it's zero and that's not a user and it breaks the tests
            MediaService.Save(media, Constants.Security.SuperUserId);

            // so we have to force-reset these values because the property editor has cleared them
            media.SetValue(Constants.Conventions.Media.Width, "200");
            media.SetValue(Constants.Conventions.Media.Height, "200");
            media.SetValue(Constants.Conventions.Media.Bytes, "100");
            media.SetValue(Constants.Conventions.Media.Extension, "png");

            var nodeName = media.ContentType.Alias.ToSafeAlias(ShortStringHelper);
            var urlName  = media.GetUrlSegment(ShortStringHelper, new[] { new DefaultUrlSegmentProvider(ShortStringHelper) });

            // Act
            XElement element = media.ToXml(Serializer);

            // Assert
            Assert.That(element, Is.Not.Null);
            Assert.That(element.Name.LocalName, Is.EqualTo(nodeName));
            Assert.AreEqual(media.Id.ToString(), (string)element.Attribute("id"));
            Assert.AreEqual(media.ParentId.ToString(), (string)element.Attribute("parentID"));
            Assert.AreEqual(media.Level.ToString(), (string)element.Attribute("level"));
            Assert.AreEqual(media.SortOrder.ToString(), (string)element.Attribute("sortOrder"));
            Assert.AreEqual(media.CreateDate.ToString("s"), (string)element.Attribute("createDate"));
            Assert.AreEqual(media.UpdateDate.ToString("s"), (string)element.Attribute("updateDate"));
            Assert.AreEqual(media.Name, (string)element.Attribute("nodeName"));
            Assert.AreEqual(urlName, (string)element.Attribute("urlName"));
            Assert.AreEqual(media.Path, (string)element.Attribute("path"));
            Assert.AreEqual("", (string)element.Attribute("isDoc"));
            Assert.AreEqual(media.ContentType.Id.ToString(), (string)element.Attribute("nodeType"));
            Assert.AreEqual(media.GetCreatorProfile(UserService).Name, (string)element.Attribute("writerName"));
            Assert.AreEqual(media.CreatorId.ToString(), (string)element.Attribute("writerID"));
            Assert.IsNull(element.Attribute("template"));

            Assert.AreEqual(media.Properties[Constants.Conventions.Media.File].GetValue().ToString(), element.Elements(Constants.Conventions.Media.File).Single().Value);
            Assert.AreEqual(media.Properties[Constants.Conventions.Media.Width].GetValue().ToString(), element.Elements(Constants.Conventions.Media.Width).Single().Value);
            Assert.AreEqual(media.Properties[Constants.Conventions.Media.Height].GetValue().ToString(), element.Elements(Constants.Conventions.Media.Height).Single().Value);
            Assert.AreEqual(media.Properties[Constants.Conventions.Media.Bytes].GetValue().ToString(), element.Elements(Constants.Conventions.Media.Bytes).Single().Value);
            Assert.AreEqual(media.Properties[Constants.Conventions.Media.Extension].GetValue().ToString(), element.Elements(Constants.Conventions.Media.Extension).Single().Value);
        }
示例#18
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);
            }
        }
示例#19
0
        public void Get_Paged_Mixed_Entities_By_Ids()
        {
            // Create content
            IContentService     contentService     = GetRequiredService <IContentService>();
            IContentTypeService contentTypeService = GetRequiredService <IContentTypeService>();
            var         createdContent             = new List <IContent>();
            ContentType contentType = ContentTypeBuilder.CreateBasicContentType("blah");

            contentTypeService.Save(contentType);
            for (int i = 0; i < 10; i++)
            {
                Content c1 = ContentBuilder.CreateBasicContent(contentType);
                contentService.Save(c1);
                createdContent.Add(c1);
            }

            // Create media
            IMediaService     mediaService     = GetRequiredService <IMediaService>();
            IMediaTypeService mediaTypeService = GetRequiredService <IMediaTypeService>();
            var       createdMedia             = new List <IMedia>();
            MediaType imageType = MediaTypeBuilder.CreateImageMediaType("myImage");

            mediaTypeService.Save(imageType);
            for (int i = 0; i < 10; i++)
            {
                Media c1 = MediaBuilder.CreateMediaImage(imageType, -1);
                mediaService.Save(c1);
                createdMedia.Add(c1);
            }

            // Create members
            IMemberService     memberService     = GetRequiredService <IMemberService>();
            IMemberTypeService memberTypeService = GetRequiredService <IMemberTypeService>();
            MemberType         memberType        = MemberTypeBuilder.CreateSimpleMemberType("simple");

            memberTypeService.Save(memberType);
            var createdMembers = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10).ToList();

            memberService.Save(createdMembers);

            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                EntityRepository repo = CreateRepository((IScopeAccessor)provider);

                IEnumerable <int> ids = createdContent.Select(x => x.Id).Concat(createdMedia.Select(x => x.Id)).Concat(createdMembers.Select(x => x.Id));

                System.Guid[] objectTypes = new[] { Constants.ObjectTypes.Document, Constants.ObjectTypes.Media, Constants.ObjectTypes.Member };

                IQuery <IUmbracoEntity> query = provider.CreateQuery <IUmbracoEntity>()
                                                .WhereIn(e => e.Id, ids);

                var entities = repo.GetPagedResultsByQuery(query, objectTypes, 0, 20, out long totalRecords, null, null).ToList();

                Assert.AreEqual(20, entities.Count);
                Assert.AreEqual(30, totalRecords);

                // add the next page
                entities.AddRange(repo.GetPagedResultsByQuery(query, objectTypes, 1, 20, out totalRecords, null, null));

                Assert.AreEqual(30, entities.Count);
                Assert.AreEqual(30, totalRecords);

                var contentEntities = entities.OfType <IDocumentEntitySlim>().ToList();
                var mediaEntities   = entities.OfType <IMediaEntitySlim>().ToList();
                var memberEntities  = entities.OfType <IMemberEntitySlim>().ToList();

                Assert.AreEqual(10, contentEntities.Count);
                Assert.AreEqual(10, mediaEntities.Count);
                Assert.AreEqual(10, memberEntities.Count);
            }
        }
示例#20
0
        private void CreateTestDataForPagingTests(out List <IContent> createdContent, out List <IMember> createdMembers, out List <IMedia> createdMedia)
        {
            // Create content
            createdContent = new List <IContent>();
            ContentType contentType = ContentTypeBuilder.CreateBasicContentType("blah");

            ContentTypeService.Save(contentType);
            for (int i = 0; i < 3; i++)
            {
                Content c1 = ContentBuilder.CreateBasicContent(contentType);
                ContentService.Save(c1);
                createdContent.Add(c1);
            }

            // Create related content
            var relatedContent = new List <IContent>();

            for (int i = 0; i < 3; i++)
            {
                Content c1 = ContentBuilder.CreateBasicContent(contentType);
                ContentService.Save(c1);
                relatedContent.Add(c1);
            }

            // Create media
            createdMedia = new List <IMedia>();
            MediaType imageType = MediaTypeBuilder.CreateImageMediaType("myImage");

            MediaTypeService.Save(imageType);
            for (int i = 0; i < 3; i++)
            {
                Media c1 = MediaBuilder.CreateMediaImage(imageType, -1);
                MediaService.Save(c1);
                createdMedia.Add(c1);
            }

            // Create members
            MemberType memberType = MemberTypeBuilder.CreateSimpleMemberType("simple");

            MemberTypeService.Save(memberType);
            createdMembers = MemberBuilder.CreateSimpleMembers(memberType, 3).ToList();
            GetMemberService().Save(createdMembers);

            IRelationType relatedMediaRelType   = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias);
            IRelationType relatedContentRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedDocumentAlias);

            // Relate content to media
            foreach (IContent content in createdContent)
            {
                foreach (IMedia media in createdMedia)
                {
                    RelationService.Relate(content.Id, media.Id, relatedMediaRelType);
                }
            }

            // Relate content to content
            foreach (IContent relContent in relatedContent)
            {
                foreach (IContent content in createdContent)
                {
                    RelationService.Relate(relContent.Id, content.Id, relatedContentRelType);
                }
            }

            // Relate members to media
            foreach (IMember member in createdMembers)
            {
                foreach (IMedia media in createdMedia)
                {
                    RelationService.Relate(member.Id, media.Id, relatedMediaRelType);
                }
            }

            // Create copied content
            var copiedContent = new List <IContent>();

            for (int i = 0; i < 3; i++)
            {
                Content c1 = ContentBuilder.CreateBasicContent(contentType);
                ContentService.Save(c1);
                copiedContent.Add(c1);
            }

            IRelationType copiedContentRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias);

            // Relate content to content (mimics copy)
            foreach (IContent content in createdContent)
            {
                foreach (IContent cpContent in copiedContent)
                {
                    RelationService.Relate(content.Id, cpContent.Id, copiedContentRelType);
                }
            }

            // Create trashed content
            var trashedContent = new List <IContent>();

            for (int i = 0; i < 3; i++)
            {
                Content c1 = ContentBuilder.CreateBasicContent(contentType);
                ContentService.Save(c1);
                trashedContent.Add(c1);
            }

            IRelationType trashedRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias);

            // Relate to trashed content
            foreach (IContent trContent in trashedContent)
            {
                foreach (IContent content in createdContent)
                {
                    RelationService.Relate(trContent.Id, content.Id, trashedRelType);
                }
            }

            // Create trashed media
            var trashedMedia = new List <IMedia>();

            for (int i = 0; i < 3; i++)
            {
                Media m1 = MediaBuilder.CreateMediaImage(imageType, -1);
                MediaService.Save(m1);
                trashedMedia.Add(m1);
            }

            IRelationType trashedMediaRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteAlias);

            // Relate to trashed media
            foreach (IMedia trMedia in trashedMedia)
            {
                foreach (IMedia media in createdMedia)
                {
                    RelationService.Relate(trMedia.Id, media.Id, trashedMediaRelType);
                }
            }
        }