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 SaveMedia() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); IMediaType mediaType = mediaTypeRepository.Get(1032); Media image = MediaBuilder.CreateMediaImage(mediaType, -1); // Act mediaTypeRepository.Save(mediaType); repository.Save(image); IMedia fetched = repository.Get(image.Id); // Assert Assert.That(mediaType.HasIdentity, Is.True); Assert.That(image.HasIdentity, Is.True); TestHelper.AssertPropertyValuesAreEqual(image, fetched); } }
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); }
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); } }
/// <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 SaveMediaMultiple() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository); IMediaType mediaType = mediaTypeRepository.Get(1032); Media file = MediaBuilder.CreateMediaFile(mediaType, -1); // Act repository.Save(file); Media image = MediaBuilder.CreateMediaImage(mediaType, -1); repository.Save(image); // Assert Assert.That(file.HasIdentity, Is.True); Assert.That(image.HasIdentity, Is.True); Assert.That(file.Name, Is.EqualTo("Test File")); Assert.That(image.Name, Is.EqualTo("Test Image")); Assert.That(file.ContentTypeId, Is.EqualTo(mediaType.Id)); Assert.That(image.ContentTypeId, Is.EqualTo(mediaType.Id)); } }
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); } } }
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 async Task GetUrlsByIds_MediaWithIntegerIds_ReturnsValidMap() { IMediaTypeService mediaTypeService = Services.GetRequiredService <IMediaTypeService>(); IMediaService mediaService = Services.GetRequiredService <IMediaService>(); var mediaItems = new List <Media>(); using (ScopeProvider.CreateScope(autoComplete: true)) { IMediaType mediaType = mediaTypeService.Get("image"); mediaTypeService.Save(mediaType); mediaItems.Add(MediaBuilder.CreateMediaImage(mediaType, -1)); mediaItems.Add(MediaBuilder.CreateMediaImage(mediaType, -1)); foreach (Media media in mediaItems) { mediaService.Save(media); } } var queryParameters = new Dictionary <string, object> { ["type"] = Constants.UdiEntityType.Media }; var url = LinkGenerator.GetUmbracoControllerUrl("GetUrlsByIds", typeof(EntityController), queryParameters); var payload = new { ids = new[] { mediaItems[0].Id, mediaItems[1].Id, } }; HttpResponseMessage response = await HttpClientJsonExtensions.PostAsJsonAsync(Client, url, payload); // skip pointless un-parseable cruft. (await response.Content.ReadAsStreamAsync()).Seek(AngularJsonMediaTypeFormatter.XsrfPrefix.Length, SeekOrigin.Begin); IDictionary <int, string> results = await response.Content.ReadFromJsonAsync <IDictionary <int, string> >(); Assert.Multiple(() => { Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsTrue(results ![payload.ids[0]].StartsWith("/media")); Assert.IsTrue(results ![payload.ids[1]].StartsWith("/media"));
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 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 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); } }
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 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); }
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); }
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); } }
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); } } }
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); } }
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); }
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()); } }