Beispiel #1
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     = ServiceContext.RelationService;
            var rtName = Guid.NewGuid().ToString();
            var rt     = new RelationType(rtName, rtName, false, null, null);

            rs.Save(rt);

            var ct = MockedContentTypes.CreateBasicContentType();

            ServiceContext.ContentTypeService.Save(ct);

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

            ServiceContext.MediaTypeService.Save(mt);

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

                return new Relation(c1.Id, c2.Id, rt);
            }).ToList());
        }
Beispiel #2
0
        private IRelation CreateAndSaveRelation(string name, string alias)
        {
            var rs = ServiceContext.RelationService;
            var rt = new RelationType(name, alias, false, null, null);

            rs.Save(rt);

            var ct = MockedContentTypes.CreateBasicContentType();

            ServiceContext.ContentTypeService.Save(ct);

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

            ServiceContext.MediaTypeService.Save(mt);

            var c1 = MockedContent.CreateBasicContent(ct);
            var c2 = MockedMedia.CreateMediaImage(mt, -1);

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

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

            ServiceContext.RelationService.Save(r);

            return(r);
        }
Beispiel #3
0
        public void Get_Paged_Children_With_Media_Type_Filter()
        {
            var mediaService = ServiceContext.MediaService;
            var mediaType1   = MockedContentTypes.CreateImageMediaType("Image2");

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

            ServiceContext.MediaTypeService.Save(mediaType2);

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

            long total;
            var  result = ServiceContext.MediaService.GetPagedChildren(-1, 0, 11, out total,
                                                                       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 = ServiceContext.MediaService.GetPagedChildren(-1, 1, 11, out total,
                                                                  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);
        }
Beispiel #4
0
        public void Get_Property_Value_Uses_Converter()
        {
            var mType = MockedContentTypes.CreateImageMediaType("image2");

            //lets add an RTE to this
            mType.PropertyGroups.First().PropertyTypes.Add(
                new PropertyType("test", ValueStorageType.Nvarchar, "content")
            {
                Name       = "Rich Text",
                DataTypeId = -87         //tiny mce
            });
            ServiceContext.MediaTypeService.Save(mType);
            var media = MockedMedia.CreateMediaImage(mType, -1);

            media.Properties["content"].SetValue("<div>This is some content</div>");
            ServiceContext.MediaService.Save(media);

            var publishedMedia = GetNode(media.Id);

            var propVal = publishedMedia.Value("content");

            Assert.IsInstanceOf <IHtmlString>(propVal);
            Assert.AreEqual("<div>This is some content</div>", propVal.ToString());

            var propVal2 = publishedMedia.Value <IHtmlString>("content");

            Assert.IsInstanceOf <IHtmlString>(propVal2);
            Assert.AreEqual("<div>This is some content</div>", propVal2.ToString());

            var propVal3 = publishedMedia.Value("Content");

            Assert.IsInstanceOf <IHtmlString>(propVal3);
            Assert.AreEqual("<div>This is some content</div>", propVal3.ToString());
        }
Beispiel #5
0
        public void Can_Serialize_Media_Type_Without_Error()
        {
            var ss = new SerializationService(new JsonNetSerializer());

            // Arrange
            var contentType = MockedContentTypes.CreateImageMediaType();

            contentType.Id = 99;

            var i = 200;

            foreach (var propertyType in contentType.PropertyTypes)
            {
                propertyType.Id = ++i;
            }
            contentType.Id          = 10;
            contentType.CreateDate  = DateTime.Now;
            contentType.CreatorId   = 22;
            contentType.Description = "test";
            contentType.Icon        = "icon";
            contentType.IsContainer = true;
            contentType.Thumbnail   = "thumb";
            contentType.Key         = Guid.NewGuid();
            contentType.Level       = 3;
            contentType.Path        = "-1,4,10";
            contentType.SortOrder   = 5;
            contentType.Trashed     = false;
            contentType.UpdateDate  = DateTime.Now;

            var result = ss.ToStream(contentType);
            var json   = result.ResultStream.ToJsonString();

            Debug.Print(json);
        }
Beispiel #6
0
        public void Can_Serialize_Media_Type_Without_Error()
        {
            // Arrange
            var contentType = MockedContentTypes.CreateImageMediaType();

            contentType.Id = 99;

            var i = 200;

            foreach (var propertyType in contentType.PropertyTypes)
            {
                propertyType.Id = ++i;
            }
            contentType.Id          = 10;
            contentType.CreateDate  = DateTime.Now;
            contentType.CreatorId   = 22;
            contentType.Description = "test";
            contentType.Icon        = "icon";
            contentType.IsContainer = true;
            contentType.Thumbnail   = "thumb";
            contentType.Key         = Guid.NewGuid();
            contentType.Level       = 3;
            contentType.Path        = "-1,4,10";
            contentType.SortOrder   = 5;
            contentType.Trashed     = false;
            contentType.UpdateDate  = DateTime.Now;

            var json = JsonConvert.SerializeObject(contentType);

            Debug.Print(json);
        }
        public void Get_Paged_Parent_Child_Entities_With_Same_Entity_Relation()
        {
            //Create a media item and create a relationship between itself (parent -> child)
            var imageType = MockedContentTypes.CreateImageMediaType("myImage");

            ServiceContext.MediaTypeService.Save(imageType);
            var media = MockedMedia.CreateMediaImage(imageType, -1);

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

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

            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                var repository = CreateRepository(provider, out var relationTypeRepository);

                // Get parent entities for child id
                var parents = repository.GetPagedParentEntitiesByChildId(media.Id, 0, 10, out var 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);
            }
        }
Beispiel #8
0
        public void Can_Copy_MediaType_By_Performing_Clone()
        {
            // Arrange
            var mediaType = MockedContentTypes.CreateImageMediaType("Image2") as IMediaType;

            ServiceContext.MediaTypeService.Save(mediaType);

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

            Assert.IsNotNull(sut);
            ServiceContext.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);
        }
Beispiel #9
0
        public void Get_Property_Value_Uses_Converter()
        {
            var mType = MockedContentTypes.CreateImageMediaType();

            //lets add an RTE to this
            mType.PropertyGroups.First().PropertyTypes.Add(
                new PropertyType(Guid.Parse(Constants.PropertyEditors.TinyMCEv3), DataTypeDatabaseType.Nvarchar)
            {
                Alias = "content",
                Name  = "Rich Text",
                DataTypeDefinitionId = -87         //tiny mce
            });
            ServiceContext.ContentTypeService.Save(mType);
            var media = MockedMedia.CreateMediaImage(mType, -1);

            media.Properties["content"].Value = "<div>This is some content</div>";
            ServiceContext.MediaService.Save(media);

            var publishedMedia = GetNode(media.Id);

            var propVal = publishedMedia.GetPropertyValue("content");

            Assert.IsInstanceOf <IHtmlString>(propVal);
            Assert.AreEqual("<div>This is some content</div>", propVal.ToString());

            var propVal2 = publishedMedia.GetPropertyValue <IHtmlString>("content");

            Assert.IsInstanceOf <IHtmlString>(propVal2);
            Assert.AreEqual("<div>This is some content</div>", propVal2.ToString());

            var propVal3 = publishedMedia.GetPropertyValue("Content");

            Assert.IsInstanceOf <IHtmlString>(propVal3);
            Assert.AreEqual("<div>This is some content</div>", propVal3.ToString());
        }
Beispiel #10
0
        public void Can_Generate_Xml_Representation_Of_Media()
        {
            // Arrange
            var mediaType = MockedContentTypes.CreateImageMediaType("image2");

            ServiceContext.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);
            var ignored = new FileUploadPropertyEditor(DataValueEditorFactory, mediaFileManager, Microsoft.Extensions.Options.Options.Create(contentSettings), DataTypeService, LocalizationService, LocalizedTextService, UploadAutoFillProperties, ContentService);

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

            media.WriterId = -1; // else it's zero and that's not a user and it breaks the tests
            ServiceContext.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(Factory.GetRequiredService <IEntityXmlSerializer>());

            // 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(ServiceContext.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);
        }
        public void To_Media_Item_Dto()
        {
            var contentType = MockedContentTypes.CreateImageMediaType();
            var content     = MockedMedia.CreateMediaImage(contentType, -1);

            var result = Mapper.Map <IMedia, ContentItemDto <IMedia> >(content);

            AssertContentItem(result, content);
        }
        public void Is_Media_In_Recycle_Bin(string path, bool isInBin)
        {
            var mediaType = MockedContentTypes.CreateImageMediaType();
            var media     = MockedMedia.CreateMediaFile(mediaType, -1);

            media.Path = path;
            media.Id   = 34;

            Assert.AreEqual(isInBin, media.IsInRecycleBin());
        }
Beispiel #13
0
        public void Can_Generate_Xml_Representation_Of_Media()
        {
            // Arrange
            var mediaType = MockedContentTypes.CreateImageMediaType("image2");

            ServiceContext.ContentTypeService.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 ignored = new FileUploadPropertyEditor();

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

            ServiceContext.MediaService.Save(media, 0);

            // 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.ToSafeAliasWithForcingCheck();
            var urlName  = media.GetUrlSegment();

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

            // 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().Name, (string)element.Attribute("writerName"));
            Assert.AreEqual(media.CreatorId.ToString(), (string)element.Attribute("writerID"));
            Assert.AreEqual(media.Version.ToString(), (string)element.Attribute("version"));
            Assert.AreEqual("0", (string)element.Attribute("template"));

            Assert.AreEqual(media.Properties[Constants.Conventions.Media.File].Value.ToString(), element.Elements(Constants.Conventions.Media.File).Single().Value);
            Assert.AreEqual(media.Properties[Constants.Conventions.Media.Width].Value.ToString(), element.Elements(Constants.Conventions.Media.Width).Single().Value);
            Assert.AreEqual(media.Properties[Constants.Conventions.Media.Height].Value.ToString(), element.Elements(Constants.Conventions.Media.Height).Single().Value);
            Assert.AreEqual(media.Properties[Constants.Conventions.Media.Bytes].Value.ToString(), element.Elements(Constants.Conventions.Media.Bytes).Single().Value);
            Assert.AreEqual(media.Properties[Constants.Conventions.Media.Extension].Value.ToString(), element.Elements(Constants.Conventions.Media.Extension).Single().Value);
        }
        private void CreateTestDataForPagingTests(out List <IContent> createdContent, out List <IMember> createdMembers, out List <IMedia> createdMedia)
        {
            //Create content
            createdContent = new List <IContent>();
            var contentType = MockedContentTypes.CreateBasicContentType("blah");

            ServiceContext.ContentTypeService.Save(contentType);
            for (int i = 0; i < 10; i++)
            {
                var c1 = MockedContent.CreateBasicContent(contentType);
                ServiceContext.ContentService.Save(c1);
                createdContent.Add(c1);
            }

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

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

            // Create members
            var memberType = MockedContentTypes.CreateSimpleMemberType("simple");

            ServiceContext.MemberTypeService.Save(memberType);
            createdMembers = MockedMember.CreateSimpleMember(memberType, 10).ToList();
            ServiceContext.MemberService.Save(createdMembers);

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

            // Relate content to media
            foreach (var content in createdContent)
            {
                foreach (var media in createdMedia)
                {
                    ServiceContext.RelationService.Relate(content.Id, media.Id, relType);
                }
            }
            // Relate members to media
            foreach (var member in createdMembers)
            {
                foreach (var media in createdMedia)
                {
                    ServiceContext.RelationService.Relate(member.Id, media.Id, relType);
                }
            }
        }
Beispiel #15
0
        public void Get_Paged_Relations_By_Relation_Type()
        {
            //Create content
            var createdContent = new List <IContent>();
            var contentType    = MockedContentTypes.CreateBasicContentType("blah");

            ServiceContext.ContentTypeService.Save(contentType);
            for (int i = 0; i < 10; i++)
            {
                var c1 = MockedContent.CreateBasicContent(contentType);
                ServiceContext.ContentService.Save(c1);
                createdContent.Add(c1);
            }

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

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

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

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

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

            Assert.AreEqual(100, totalRecs);
            Assert.AreEqual(51, paged.Count);

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

            Assert.AreEqual(100, totalRecs);
            Assert.AreEqual(100, 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 To_Media_Item_Simple()
        {
            var contentType = MockedContentTypes.CreateImageMediaType();
            var content     = MockedMedia.CreateMediaImage(contentType, -1);

            var result = Mapper.Map <IMedia, ContentItemBasic <ContentPropertyBasic, IMedia> >(content);

            AssertBasics(result, content);

            foreach (var p in content.Properties)
            {
                AssertBasicProperty(result, p);
            }
        }
Beispiel #17
0
        public void To_Media_Item_Dto()
        {
            var contentType = MockedContentTypes.CreateImageMediaType();
            var content     = MockedMedia.CreateMediaImage(contentType, -1);

            FixUsers(content);

            var result = Mapper.Map <IMedia, ContentPropertyCollectionDto>(content);

            foreach (var p in content.Properties)
            {
                AssertProperty(result, p);
            }
        }
Beispiel #18
0
        public void Can_Get_Media_With_Crop_By_Path()
        {
            var mediaService = ServiceContext.MediaService;
            var mediaType    = MockedContentTypes.CreateImageMediaType("Image2");

            ServiceContext.MediaTypeService.Save(mediaType);

            var media = MockedMedia.CreateMediaImageWithCrop(mediaType, -1);

            mediaService.Save(media);

            var mediaPath     = "/media/test-image.png";
            var resolvedMedia = mediaService.GetMediaByPath(mediaPath);

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

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

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

            ServiceContext.MediaTypeService.Save(mediaType);

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

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

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

            var clonedMediaType   = ServiceContext.MediaTypeService.Get(clone.Id);
            var originalMediaType = ServiceContext.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);
        }
Beispiel #20
0
        public void Can_Get_Paged_Children_Dont_Get_Descendants()
        {
            var mediaType = MockedContentTypes.CreateImageMediaType("Image2");

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

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

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

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

            var service = ServiceContext.MediaService;

            long total;
            // children in root including the folder - not the descendants in the folder
            var entities = service.GetPagedChildren(-1, 0, 6, out 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));
        }
Beispiel #21
0
        public void To_Media_Item_Simple()
        {
            var contentType = MockedContentTypes.CreateImageMediaType();

            Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType);

            var content = MockedMedia.CreateMediaImage(contentType, -1);

            FixUsers(content);

            var result = Mapper.Map <IMedia, ContentItemBasic <ContentPropertyBasic> >(content);

            AssertBasics(result, content);

            foreach (var p in content.Properties)
            {
                AssertBasicProperty(result, p);
            }
        }
        public void Can_Generate_Xml_Representation_Of_Media()
        {
            // Arrange
            var mediaType = MockedContentTypes.CreateImageMediaType("image2");

            ServiceContext.ContentTypeService.Save(mediaType);

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

            ServiceContext.MediaService.Save(media, 0);

            var nodeName = media.ContentType.Alias.ToSafeAliasWithForcingCheck();
            var urlName  = media.GetUrlSegment();

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

            // 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().Name, (string)element.Attribute("writerName"));
            Assert.AreEqual(media.CreatorId.ToString(), (string)element.Attribute("writerID"));
            Assert.AreEqual(media.Version.ToString(), (string)element.Attribute("version"));
            Assert.AreEqual("0", (string)element.Attribute("template"));

            Assert.AreEqual(media.Properties[Constants.Conventions.Media.File].Value.ToString(), element.Elements(Constants.Conventions.Media.File).Single().Value);
            Assert.AreEqual(media.Properties[Constants.Conventions.Media.Width].Value.ToString(), element.Elements(Constants.Conventions.Media.Width).Single().Value);
            Assert.AreEqual(media.Properties[Constants.Conventions.Media.Height].Value.ToString(), element.Elements(Constants.Conventions.Media.Height).Single().Value);
            Assert.AreEqual(media.Properties[Constants.Conventions.Media.Bytes].Value.ToString(), element.Elements(Constants.Conventions.Media.Bytes).Single().Value);
            Assert.AreEqual(media.Properties[Constants.Conventions.Media.Extension].Value.ToString(), element.Elements(Constants.Conventions.Media.Extension).Single().Value);
        }
Beispiel #23
0
        public void Can_Get_Paged_Children()
        {
            var mediaType = MockedContentTypes.CreateImageMediaType("Image2");

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

            var service = ServiceContext.MediaService;

            long total;
            var  entities = service.GetPagedChildren(-1, 0, 6, out 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));
        }
Beispiel #24
0
        public void Can_Deep_Clone_Media_Type()
        {
            // Arrange
            var contentType = MockedContentTypes.CreateImageMediaType();

            contentType.Id = 99;

            var i = 200;

            foreach (var propertyType in contentType.PropertyTypes)
            {
                propertyType.Id = ++i;
            }
            contentType.Id          = 10;
            contentType.CreateDate  = DateTime.Now;
            contentType.CreatorId   = 22;
            contentType.Description = "test";
            contentType.Icon        = "icon";
            contentType.IsContainer = true;
            contentType.Thumbnail   = "thumb";
            contentType.Key         = Guid.NewGuid();
            contentType.Level       = 3;
            contentType.Path        = "-1,4,10";
            contentType.SortOrder   = 5;
            contentType.Trashed     = false;
            contentType.UpdateDate  = DateTime.Now;

            // Act
            var clone = (MediaType)contentType.DeepClone();

            // Assert
            Assert.AreNotSame(clone, contentType);
            Assert.AreEqual(clone, contentType);
            Assert.AreEqual(clone.Id, contentType.Id);
            Assert.AreEqual(clone.PropertyGroups.Count, contentType.PropertyGroups.Count);
            for (var index = 0; index < contentType.PropertyGroups.Count; index++)
            {
                Assert.AreNotSame(clone.PropertyGroups[index], contentType.PropertyGroups[index]);
                Assert.AreEqual(clone.PropertyGroups[index], contentType.PropertyGroups[index]);
            }
            Assert.AreEqual(clone.PropertyTypes.Count(), contentType.PropertyTypes.Count());
            for (var index = 0; index < contentType.PropertyTypes.Count(); index++)
            {
                Assert.AreNotSame(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));
                Assert.AreEqual(clone.PropertyTypes.ElementAt(index), contentType.PropertyTypes.ElementAt(index));
            }
            Assert.AreEqual(clone.CreateDate, contentType.CreateDate);
            Assert.AreEqual(clone.CreatorId, contentType.CreatorId);
            Assert.AreEqual(clone.Key, contentType.Key);
            Assert.AreEqual(clone.Level, contentType.Level);
            Assert.AreEqual(clone.Path, contentType.Path);
            Assert.AreEqual(clone.SortOrder, contentType.SortOrder);
            Assert.AreEqual(clone.Trashed, contentType.Trashed);
            Assert.AreEqual(clone.UpdateDate, contentType.UpdateDate);
            Assert.AreEqual(clone.Thumbnail, contentType.Thumbnail);
            Assert.AreEqual(clone.Icon, contentType.Icon);
            Assert.AreEqual(clone.IsContainer, contentType.IsContainer);

            //This double verifies by reflection
            var allProps = clone.GetType().GetProperties();

            foreach (var propertyInfo in allProps)
            {
                Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(contentType, null));
            }
        }
        public void Can_Get_Tags_For_Entity_Type_For_Group()
        {
            var provider = TestObjects.GetScopeProvider(Logger);

            using (ScopeProvider.CreateScope())
            {
                var contentRepository = CreateContentRepository(provider, out var contentTypeRepository);
                var mediaRepository   = CreateMediaRepository(provider, out var mediaTypeRepository);

                //create data to relate to
                var contentType = MockedContentTypes.CreateSimpleContentType("test", "Test");
                ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType!
                contentTypeRepository.Save(contentType);

                var content1 = MockedContent.CreateSimpleContent(contentType);
                contentRepository.Save(content1);

                var mediaType = MockedContentTypes.CreateImageMediaType("image2");
                mediaTypeRepository.Save(mediaType);

                var media1 = MockedMedia.CreateMediaImage(mediaType, -1);
                mediaRepository.Save(media1);

                var repository = CreateRepository(provider);
                repository.Assign(
                    content1.Id,
                    contentType.PropertyTypes.First().Id,
                    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"
                    }
                }, false);

                repository.Assign(
                    media1.Id,
                    mediaType.PropertyTypes.Last().Id,
                    new[]
                {
                    new Tag {
                        Text = "tag1", Group = "test"
                    },
                    new Tag {
                        Text = "tag2", Group = "test1"
                    }
                }, false);

                var result1 = repository.GetTagsForEntityType(TaggableObjectTypes.Content, "test1").ToArray();
                var result2 = repository.GetTagsForEntityType(TaggableObjectTypes.Media, "test1").ToArray();

                Assert.AreEqual(2, result1.Length);
                Assert.AreEqual(1, result2.Length);
            }
        }
        public void GroupsContentTypeEvents()
        {
            var num                = 30;
            var contentTypes       = Enumerable.Repeat(MockedContentTypes.CreateBasicContentType(), num);
            var mediaTypes         = Enumerable.Repeat(MockedContentTypes.CreateImageMediaType(), num);
            var memberTypes        = Enumerable.Repeat(MockedContentTypes.CreateSimpleMemberType(), num);
            var definitionsContent = contentTypes.SelectMany(x => new IEventDefinition[]
            {
                new EventDefinition <IContentTypeService, ContentTypeChange <IContentType> .EventArgs>(null, Current.Services.ContentTypeService, new ContentTypeChange <IContentType> .EventArgs(new ContentTypeChange <IContentType>(x, ContentTypeChangeTypes.Create)), "Changed"),
                new EventDefinition <IContentTypeService, SaveEventArgs <IContentType> >(null, Current.Services.ContentTypeService, new SaveEventArgs <IContentType>(x), "Saved"),
            });

            var definitionsMedia = mediaTypes.SelectMany(x => new IEventDefinition[]
            {
                new EventDefinition <IMediaTypeService, ContentTypeChange <IMediaType> .EventArgs>(null, Current.Services.MediaTypeService, new ContentTypeChange <IMediaType> .EventArgs(new ContentTypeChange <IMediaType>(x, ContentTypeChangeTypes.Create)), "Changed"),
                new EventDefinition <IMediaTypeService, SaveEventArgs <IMediaType> >(null, Current.Services.MediaTypeService, new SaveEventArgs <IMediaType>(x), "Saved"),
            });
            var definitionsMember = memberTypes.SelectMany(x => new IEventDefinition[]
            {
                new EventDefinition <IMemberTypeService, ContentTypeChange <IMemberType> .EventArgs>(null, Current.Services.MemberTypeService, new ContentTypeChange <IMemberType> .EventArgs(new ContentTypeChange <IMemberType>(x, ContentTypeChangeTypes.Create)), "Changed"),
                new EventDefinition <IMemberTypeService, SaveEventArgs <IMemberType> >(null, Current.Services.MemberTypeService, new SaveEventArgs <IMemberType>(x), "Saved"),
            });

            var definitions = new List <IEventDefinition>();

            definitions.AddRange(definitionsContent);
            definitions.AddRange(definitionsMedia);
            definitions.AddRange(definitionsMember);

            var result = DistributedCacheBinder.GetGroupedEventList(definitions);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(num * 6, definitions.Count(), "Precondition is we have many definitions");
                Assert.AreEqual(6, result.Count(), "Unexpected number of reduced definitions");
                foreach (var eventDefinition in result)
                {
                    if (eventDefinition.Args is SaveEventArgs <IContentType> saveContentEventArgs)
                    {
                        Assert.AreEqual(num, saveContentEventArgs.SavedEntities.Count());
                    }

                    if (eventDefinition.Args is ContentTypeChange <IContentType> .EventArgs changeContentEventArgs)
                    {
                        Assert.AreEqual(num, changeContentEventArgs.Changes.Count());
                    }

                    if (eventDefinition.Args is SaveEventArgs <IMediaType> saveMediaEventArgs)
                    {
                        Assert.AreEqual(num, saveMediaEventArgs.SavedEntities.Count());
                    }

                    if (eventDefinition.Args is ContentTypeChange <IMediaType> .EventArgs changeMediaEventArgs)
                    {
                        Assert.AreEqual(num, changeMediaEventArgs.Changes.Count());
                    }

                    if (eventDefinition.Args is SaveEventArgs <IMemberType> saveMemberEventArgs)
                    {
                        Assert.AreEqual(num, saveMemberEventArgs.SavedEntities.Count());
                    }

                    if (eventDefinition.Args is ContentTypeChange <IMemberType> .EventArgs changeMemberEventArgs)
                    {
                        Assert.AreEqual(num, changeMemberEventArgs.Changes.Count());
                    }
                }
            });
        }
        public void Can_Get_Tagged_Entities_For_Tag_Group()
        {
            var provider = TestObjects.GetScopeProvider(Logger);

            using (ScopeProvider.CreateScope())
            {
                var contentRepository = CreateContentRepository(provider, out var contentTypeRepository);
                var mediaRepository   = CreateMediaRepository(provider, out var mediaTypeRepository);

                //create data to relate to
                var contentType = MockedContentTypes.CreateSimpleContentType("test", "Test");
                ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType!
                contentTypeRepository.Save(contentType);

                var content1 = MockedContent.CreateSimpleContent(contentType);
                contentRepository.Save(content1);

                var content2 = MockedContent.CreateSimpleContent(contentType);
                contentRepository.Save(content2);

                var mediaType = MockedContentTypes.CreateImageMediaType("image2");
                mediaTypeRepository.Save(mediaType);

                var media1 = MockedMedia.CreateMediaImage(mediaType, -1);
                mediaRepository.Save(media1);

                var repository = CreateRepository(provider);
                repository.Assign(
                    content1.Id,
                    contentType.PropertyTypes.First().Id,
                    new[]
                {
                    new Tag {
                        Text = "tag1", Group = "test"
                    },
                    new Tag {
                        Text = "tag2", Group = "test1"
                    },
                    new Tag {
                        Text = "tag3", Group = "test"
                    }
                }, false);

                repository.Assign(
                    content2.Id,
                    contentType.PropertyTypes.Last().Id,
                    new[]
                {
                    new Tag {
                        Text = "tag1", Group = "test"
                    },
                    new Tag {
                        Text = "tag2", Group = "test1"
                    },
                    new Tag {
                        Text = "tag3", Group = "test"
                    }
                }, false);

                repository.Assign(
                    media1.Id,
                    mediaType.PropertyTypes.Last().Id,
                    new[]
                {
                    new Tag {
                        Text = "tag1", Group = "test"
                    },
                    new Tag {
                        Text = "tag2", Group = "test1"
                    }
                }, false);

                var contentTestIds = repository.GetTaggedEntitiesByTagGroup(TaggableObjectTypes.Content, "test").ToArray();
                //there are two content items tagged against the 'test' group
                Assert.AreEqual(2, contentTestIds.Length);
                //there are a total of two property types tagged against the 'test' group
                Assert.AreEqual(2, contentTestIds.SelectMany(x => x.TaggedProperties).Count());
                //there are a total of 2 tags tagged against the 'test' group
                Assert.AreEqual(2, contentTestIds.SelectMany(x => x.TaggedProperties).SelectMany(x => x.Tags).Select(x => x.Id).Distinct().Count());

                var contentTest1Ids = repository.GetTaggedEntitiesByTagGroup(TaggableObjectTypes.Content, "test1").ToArray();
                //there are two content items tagged against the 'test1' group
                Assert.AreEqual(2, contentTest1Ids.Length);
                //there are a total of two property types tagged against the 'test1' group
                Assert.AreEqual(2, contentTest1Ids.SelectMany(x => x.TaggedProperties).Count());
                //there are a total of 1 tags tagged against the 'test1' group
                Assert.AreEqual(1, contentTest1Ids.SelectMany(x => x.TaggedProperties).SelectMany(x => x.Tags).Select(x => x.Id).Distinct().Count());

                var mediaTestIds = repository.GetTaggedEntitiesByTagGroup(TaggableObjectTypes.Media, "test");
                Assert.AreEqual(1, mediaTestIds.Count());

                var mediaTest1Ids = repository.GetTaggedEntitiesByTagGroup(TaggableObjectTypes.Media, "test1");
                Assert.AreEqual(1, mediaTest1Ids.Count());
            }
        }
        public void Get_Paged_Mixed_Entities_By_Ids()
        {
            //Create content

            var createdContent = new List <IContent>();
            var contentType    = MockedContentTypes.CreateBasicContentType("blah");

            ServiceContext.ContentTypeService.Save(contentType);
            for (int i = 0; i < 10; i++)
            {
                var c1 = MockedContent.CreateBasicContent(contentType);
                ServiceContext.ContentService.Save(c1);
                createdContent.Add(c1);
            }

            //Create media

            var createdMedia = new List <IMedia>();
            var imageType    = MockedContentTypes.CreateImageMediaType("myImage");

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

            // Create members
            var memberType = MockedContentTypes.CreateSimpleMemberType("simple");

            ServiceContext.MemberTypeService.Save(memberType);
            var createdMembers = MockedMember.CreateSimpleMember(memberType, 10).ToList();

            ServiceContext.MemberService.Save(createdMembers);

            var provider = TestObjects.GetScopeProvider(Logger);

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

                var ids = createdContent.Select(x => x.Id).Concat(createdMedia.Select(x => x.Id)).Concat(createdMembers.Select(x => x.Id));

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

                var query = SqlContext.Query <IUmbracoEntity>()
                            .WhereIn(e => e.Id, ids);

                var entities = repo.GetPagedResultsByQuery(query, objectTypes, 0, 20, out var 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);
            }
        }