示例#1
0
        public void EntityService_Can_Get_Paged_Media_Children()
        {
            var folderType     = ServiceContext.MediaTypeService.Get(1031);
            var imageMediaType = ServiceContext.MediaTypeService.Get(1032);

            var root = MockedMedia.CreateMediaFolder(folderType, -1);

            ServiceContext.MediaService.Save(root);
            for (int i = 0; i < 10; i++)
            {
                var c1 = MockedMedia.CreateMediaImage(imageMediaType, root.Id);
                ServiceContext.MediaService.Save(c1);
            }

            var service = ServiceContext.EntityService;

            long total;
            var  entities = service.GetPagedChildren(root.Id, UmbracoObjectTypes.Media, 0, 6, out total).ToArray();

            Assert.That(entities.Length, Is.EqualTo(6));
            Assert.That(total, Is.EqualTo(10));
            entities = service.GetPagedChildren(root.Id, UmbracoObjectTypes.Media, 1, 6, out total).ToArray();
            Assert.That(entities.Length, Is.EqualTo(4));
            Assert.That(total, Is.EqualTo(10));
        }
示例#2
0
        public override void CreateTestData()
        {
            if (_isSetup == false)
            {
                _isSetup = true;

                base.CreateTestData();

                //Create and Save folder-Media -> 1050
                var folderMediaType = ServiceContext.MediaTypeService.Get(1031);
                var folder          = MockedMedia.CreateMediaFolder(folderMediaType, -1);
                ServiceContext.MediaService.Save(folder, 0);
                folderId = folder.Id;

                //Create and Save image-Media -> 1051
                var imageMediaType = ServiceContext.MediaTypeService.Get(1032);
                var image          = MockedMedia.CreateMediaImage(imageMediaType, folder.Id);
                ServiceContext.MediaService.Save(image, 0);

                //Create and Save file-Media -> 1052
                var fileMediaType = ServiceContext.MediaTypeService.Get(1033);
                var file          = MockedMedia.CreateMediaFile(fileMediaType, folder.Id);
                ServiceContext.MediaService.Save(file, 0);

                var subfolder = MockedMedia.CreateMediaFolder(folderMediaType, folder.Id);
                ServiceContext.MediaService.Save(subfolder, 0);
                var subfolder2 = MockedMedia.CreateMediaFolder(folderMediaType, subfolder.Id);
                ServiceContext.MediaService.Save(subfolder2, 0);
            }
        }
示例#3
0
        public void EntityService_Can_Get_Paged_Media_Descendants()
        {
            var folderType     = ServiceContext.MediaTypeService.Get(1031);
            var imageMediaType = ServiceContext.MediaTypeService.Get(1032);

            var root = MockedMedia.CreateMediaFolder(folderType, -1);

            ServiceContext.MediaService.Save(root);
            var count = 0;

            for (int i = 0; i < 10; i++)
            {
                var c1 = MockedMedia.CreateMediaImage(imageMediaType, root.Id);
                ServiceContext.MediaService.Save(c1);
                count++;

                for (int j = 0; j < 5; j++)
                {
                    var c2 = MockedMedia.CreateMediaImage(imageMediaType, c1.Id);
                    ServiceContext.MediaService.Save(c2);
                    count++;
                }
            }

            var service = ServiceContext.EntityService;

            long total;
            var  entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 31, out total).ToArray();

            Assert.That(entities.Length, Is.EqualTo(31));
            Assert.That(total, Is.EqualTo(60));
            entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 1, 31, out total).ToArray();
            Assert.That(entities.Length, Is.EqualTo(29));
            Assert.That(total, Is.EqualTo(60));
        }
示例#4
0
        public void QueryMedia_ContentTypeAliasFilter()
        {
            // we could support this, but it would require an extra join on the query,
            // and we don't absolutely need it now, so leaving it out for now

            // Arrange
            var folderMediaType = ServiceContext.MediaTypeService.Get(1031);
            var provider        = TestObjects.GetScopeProvider(Logger);

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

                // Act
                for (int i = 0; i < 10; i++)
                {
                    var folder = MockedMedia.CreateMediaFolder(folderMediaType, -1);
                    repository.Save(folder);
                }


                var types  = new[] { "Folder" };
                var query  = scope.SqlContext.Query <IMedia>().Where(x => types.Contains(x.ContentType.Alias));
                var result = repository.Get(query);

                // Assert
                Assert.That(result.Count(), Is.GreaterThanOrEqualTo(11));
            }
        }
        public void EntityService_Can_Get_Paged_Media_Descendants_With_Search()
        {
            var folderType     = ServiceContext.ContentTypeService.GetMediaType(1031);
            var imageMediaType = ServiceContext.ContentTypeService.GetMediaType(1032);

            var root = MockedMedia.CreateMediaFolder(folderType, -1);

            ServiceContext.MediaService.Save(root);

            for (int i = 0; i < 10; i++)
            {
                var c1 = MockedMedia.CreateMediaImage(imageMediaType, root.Id);
                c1.Name = "ssss" + Guid.NewGuid();
                ServiceContext.MediaService.Save(c1);

                for (int j = 0; j < 5; j++)
                {
                    var c2 = MockedMedia.CreateMediaImage(imageMediaType, c1.Id);
                    c2.Name = "tttt" + Guid.NewGuid();
                    ServiceContext.MediaService.Save(c2);
                }
            }

            var service = ServiceContext.EntityService;

            long total;
            var  entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 10, out total, filter: "ssss").ToArray();

            Assert.That(entities.Length, Is.EqualTo(10));
            Assert.That(total, Is.EqualTo(10));
            entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 50, out total, filter: "tttt").ToArray();
            Assert.That(entities.Length, Is.EqualTo(50));
            Assert.That(total, Is.EqualTo(50));
        }
示例#6
0
        public void QueryMedia_ContentTypeIdFilter()
        {
            // Arrange
            var folderMediaType = ServiceContext.MediaTypeService.Get(1031);
            var provider        = TestObjects.GetScopeProvider(Logger);

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

                // Act
                for (int i = 0; i < 10; i++)
                {
                    var folder = MockedMedia.CreateMediaFolder(folderMediaType, -1);
                    repository.Save(folder);
                }


                var types  = new[] { 1031 };
                var query  = scope.SqlContext.Query <IMedia>().Where(x => types.Contains(x.ContentTypeId));
                var result = repository.Get(query);

                // Assert
                Assert.That(result.Count(), Is.GreaterThanOrEqualTo(11));
            }
        }
示例#7
0
        private Tuple <IMedia, IMedia, IMedia, IMedia, IMedia> CreateTrashedTestMedia()
        {
            //Create and Save folder-Media -> 1050
            var folderMediaType = ServiceContext.MediaTypeService.Get(1031);
            var folder          = MockedMedia.CreateMediaFolder(folderMediaType, -1);

            ServiceContext.MediaService.Save(folder);

            //Create and Save folder-Media -> 1051
            var folder2 = MockedMedia.CreateMediaFolder(folderMediaType, -1);

            ServiceContext.MediaService.Save(folder2);

            //Create and Save image-Media  -> 1052
            var imageMediaType = ServiceContext.MediaTypeService.Get(1032);
            var image          = (Media)MockedMedia.CreateMediaImage(imageMediaType, 1050);

            ServiceContext.MediaService.Save(image);

            //Create and Save folder-Media that is trashed -> 1053
            var folderTrashed = (Media)MockedMedia.CreateMediaFolder(folderMediaType, -21);

            folderTrashed.Trashed = true;
            ServiceContext.MediaService.Save(folderTrashed);

            //Create and Save image-Media child of folderTrashed -> 1054
            var imageTrashed = (Media)MockedMedia.CreateMediaImage(imageMediaType, folderTrashed.Id);

            imageTrashed.Trashed = true;
            ServiceContext.MediaService.Save(imageTrashed);


            return(new Tuple <IMedia, IMedia, IMedia, IMedia, IMedia>(folder, folder2, image, folderTrashed, imageTrashed));
        }
        public void Can_Perform_GetByQuery_On_MediaRepository_With_ContentType_Alias_Filter()
        {
            // Arrange
            var folderMediaType = ServiceContext.ContentTypeService.GetMediaType(1031);
            var provider        = new PetaPocoUnitOfWorkProvider(Logger);
            var unitOfWork      = provider.GetUnitOfWork();
            MediaTypeRepository mediaTypeRepository;

            using (var repository = CreateRepository(unitOfWork, out mediaTypeRepository))
            {
                // Act
                for (int i = 0; i < 10; i++)
                {
                    var folder = MockedMedia.CreateMediaFolder(folderMediaType, -1);
                    repository.AddOrUpdate(folder);
                }
                unitOfWork.Commit();

                var types = new[] { "Folder" };
                var query = Query <IMedia> .Builder.Where(x => types.Contains(x.ContentType.Alias));

                var result = repository.GetByQuery(query);

                // Assert
                Assert.That(result.Count(), Is.GreaterThanOrEqualTo(11));
            }
        }
示例#9
0
        public void EntityService_Can_Get_Paged_Media_Descendants_Without_Recycled()
        {
            var folderType     = ServiceContext.MediaTypeService.Get(1031);
            var imageMediaType = ServiceContext.MediaTypeService.Get(1032);

            var root = MockedMedia.CreateMediaFolder(folderType, -1);

            ServiceContext.MediaService.Save(root);
            var toDelete = new List <IMedia>();

            for (int i = 0; i < 10; i++)
            {
                var c1 = MockedMedia.CreateMediaImage(imageMediaType, root.Id);
                ServiceContext.MediaService.Save(c1);

                if (i % 2 == 0)
                {
                    toDelete.Add(c1);
                }

                for (int j = 0; j < 5; j++)
                {
                    var c2 = MockedMedia.CreateMediaImage(imageMediaType, c1.Id);
                    ServiceContext.MediaService.Save(c2);
                }
            }

            foreach (var content in toDelete)
            {
                ServiceContext.MediaService.MoveToRecycleBin(content);
            }

            var service = ServiceContext.EntityService;

            long total;
            //search at root to see if it returns recycled
            var entities = service.GetPagedDescendants(UmbracoObjectTypes.Media, 0, 1000, out total, includeTrashed: false)
                           .Select(x => x.Id)
                           .ToArray();

            foreach (var media in toDelete)
            {
                Assert.IsFalse(entities.Contains(media.Id));
            }
        }
示例#10
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));
        }
示例#11
0
        public void CreateTestData()
        {
            //Create and Save folder-Media -> (NodeDto.NodeIdSeed)
            var folderMediaType = ServiceContext.MediaTypeService.Get(1031);
            var folder          = MockedMedia.CreateMediaFolder(folderMediaType, -1);

            ServiceContext.MediaService.Save(folder, 0);

            //Create and Save image-Media -> (NodeDto.NodeIdSeed + 1)
            var imageMediaType = ServiceContext.MediaTypeService.Get(1032);
            var image          = MockedMedia.CreateMediaImage(imageMediaType, folder.Id);

            ServiceContext.MediaService.Save(image, 0);

            //Create and Save file-Media -> (NodeDto.NodeIdSeed + 2)
            var fileMediaType = ServiceContext.MediaTypeService.Get(1033);
            var file          = MockedMedia.CreateMediaFile(fileMediaType, folder.Id);

            ServiceContext.MediaService.Save(file, 0);
        }
示例#12
0
        public void CreateTestData()
        {
            //Create and Save folder-Media -> 1045
            var folderMediaType = ServiceContext.ContentTypeService.GetMediaType(1031);
            var folder          = MockedMedia.CreateMediaFolder(folderMediaType, -1);

            ServiceContext.MediaService.Save(folder, 0);

            //Create and Save image-Media -> 1046
            var imageMediaType = ServiceContext.ContentTypeService.GetMediaType(1032);
            var image          = MockedMedia.CreateMediaImage(imageMediaType, folder.Id);

            ServiceContext.MediaService.Save(image, 0);

            //Create and Save file-Media -> 1047
            var fileMediaType = ServiceContext.ContentTypeService.GetMediaType(1033);
            var file          = MockedMedia.CreateMediaFile(fileMediaType, folder.Id);

            ServiceContext.MediaService.Save(file, 0);
        }
示例#13
0
        public void Rebuild_All_Xml_Structures_For_Content_Type()
        {
            var provider   = new PetaPocoUnitOfWorkProvider(Logger);
            var unitOfWork = provider.GetUnitOfWork();
            MediaTypeRepository mediaTypeRepository;

            using (var repository = CreateRepository(unitOfWork, out mediaTypeRepository))
            {
                var imageMediaType  = mediaTypeRepository.Get(1032);
                var fileMediaType   = mediaTypeRepository.Get(1033);
                var folderMediaType = mediaTypeRepository.Get(1031);

                for (var i = 0; i < 30; i++)
                {
                    var image = MockedMedia.CreateMediaImage(imageMediaType, -1);
                    repository.AddOrUpdate(image);
                }
                for (var i = 0; i < 30; i++)
                {
                    var file = MockedMedia.CreateMediaFile(fileMediaType, -1);
                    repository.AddOrUpdate(file);
                }
                for (var i = 0; i < 30; i++)
                {
                    var folder = MockedMedia.CreateMediaFolder(folderMediaType, -1);
                    repository.AddOrUpdate(folder);
                }
                unitOfWork.Commit();

                //delete all xml
                unitOfWork.Database.Execute("DELETE FROM cmsContentXml");
                Assert.AreEqual(0, unitOfWork.Database.ExecuteScalar <int>("SELECT COUNT(*) FROM cmsContentXml"));

                repository.RebuildXmlStructures(media => new XElement("test"), 10, contentTypeIds: new[] { 1032, 1033 });

                Assert.AreEqual(62, unitOfWork.Database.ExecuteScalar <int>("SELECT COUNT(*) FROM cmsContentXml"));
            }
        }