private Tuple <IMedia, IMedia, IMedia, IMedia, IMedia> CreateTrashedTestMedia() { // Create and Save folder-Media -> 1050 IMediaType folderMediaType = MediaTypeService.Get(1031); Media folder = MediaBuilder.CreateMediaFolder(folderMediaType, -1); MediaService.Save(folder); // Create and Save folder-Media -> 1051 Media folder2 = MediaBuilder.CreateMediaFolder(folderMediaType, -1); MediaService.Save(folder2); // Create and Save image-Media -> 1052 IMediaType imageMediaType = MediaTypeService.Get(1032); Media image = MediaBuilder.CreateMediaImage(imageMediaType, 1050); MediaService.Save(image); // Create and Save folder-Media that is trashed -> 1053 Media folderTrashed = MediaBuilder.CreateMediaFolder(folderMediaType, -21); folderTrashed.Trashed = true; MediaService.Save(folderTrashed); // Create and Save image-Media child of folderTrashed -> 1054 Media imageTrashed = MediaBuilder.CreateMediaImage(imageMediaType, folderTrashed.Id); imageTrashed.Trashed = true; MediaService.Save(imageTrashed); return(new Tuple <IMedia, IMedia, IMedia, IMedia, IMedia>(folder, folder2, image, folderTrashed, imageTrashed)); }
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 IMediaType folderMediaType = MediaTypeService.Get(1031); IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); // Act for (int i = 0; i < 10; i++) { Media folder = MediaBuilder.CreateMediaFolder(folderMediaType, -1); repository.Save(folder); } string[] types = new[] { "Folder" }; IQuery <IMedia> query = provider.CreateQuery <IMedia>().Where(x => types.Contains(x.ContentType.Alias)); IEnumerable <IMedia> result = repository.Get(query); // Assert Assert.That(result.Count(), Is.GreaterThanOrEqualTo(11)); } }
public void QueryMedia_ContentTypeIdFilter() { // Arrange IMediaType folderMediaType = MediaTypeService.Get(1031); IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); // Act for (int i = 0; i < 10; i++) { Media folder = MediaBuilder.CreateMediaFolder(folderMediaType, -1); repository.Save(folder); } int[] types = new[] { 1031 }; IQuery <IMedia> query = provider.CreateQuery <IMedia>().Where(x => types.Contains(x.ContentTypeId)); IEnumerable <IMedia> result = repository.Get(query); // Assert Assert.That(result.Count(), Is.GreaterThanOrEqualTo(11)); } }
public void QueryMedia_ContentTypeIdFilter() { // Arrange var folderMediaType = MediaTypeService.Get(1031); var provider = ScopeProvider; using (var scope = provider.CreateScope()) { var repository = CreateRepository(provider, out var mediaTypeRepository); // Act for (var i = 0; i < 10; i++) { var folder = MediaBuilder.CreateMediaFolder(folderMediaType, -1); repository.Save(folder); } int[] types = { 1031 }; var query = provider.CreateQuery <IMedia>().Where(x => types.Contains(x.ContentTypeId)); var result = repository.Get(query); // Assert Assert.That(result.Count(), Is.GreaterThanOrEqualTo(11)); } }
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)); }
public void CreateTestData() { // Create and Save folder-Media -> (1051) IMediaType folderMediaType = MediaTypeService.Get(1031); _testFolder = MediaBuilder.CreateMediaFolder(folderMediaType, -1); MediaService.Save(_testFolder, 0); // Create and Save image-Media -> (1052) IMediaType imageMediaType = MediaTypeService.Get(1032); _testImage = MediaBuilder.CreateMediaImage(imageMediaType, _testFolder.Id); MediaService.Save(_testImage, 0); // Create and Save file-Media -> (1053) IMediaType fileMediaType = MediaTypeService.Get(1033); _testFile = MediaBuilder.CreateMediaFile(fileMediaType, _testFolder.Id); MediaService.Save(_testFile, 0); }