public void Automatically_Track_Relations() { var mt = MediaTypeBuilder.CreateSimpleMediaType("testMediaType", "Test Media Type"); MediaTypeService.Save(mt); var m1 = MediaBuilder.CreateSimpleMedia(mt, "hello 1", -1); var m2 = MediaBuilder.CreateSimpleMedia(mt, "hello 1", -1); MediaService.Save(m1); MediaService.Save(m2); var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); var ct = ContentTypeBuilder.CreateTextPageContentType("richTextTest", defaultTemplateId: template.Id); ct.AllowedTemplates = Enumerable.Empty <ITemplate>(); ContentTypeService.Save(ct); var c1 = ContentBuilder.CreateTextpageContent(ct, "my content 1", -1); ContentService.Save(c1); var c2 = ContentBuilder.CreateTextpageContent(ct, "my content 2", -1); // 'bodyText' is a property with a RTE property editor which we knows tracks relations c2.Properties["bodyText"].SetValue(@"<p> <img src='/media/12312.jpg' data-udi='umb://media/" + m1.Key.ToString("N") + @"' /> </p><p><img src='/media/234234.jpg' data-udi=""umb://media/" + m2.Key.ToString("N") + @""" /> </p> <p> <a href=""{locallink:umb://document/" + c1.Key.ToString("N") + @"}"">hello</a> </p>"); ContentService.Save(c2); var relations = RelationService.GetByParentId(c2.Id).ToList(); Assert.AreEqual(3, relations.Count); Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedMediaAlias, relations[0].RelationType.Alias); Assert.AreEqual(m1.Id, relations[0].ChildId); Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedMediaAlias, relations[1].RelationType.Alias); Assert.AreEqual(m2.Id, relations[1].ChildId); Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedDocumentAlias, relations[2].RelationType.Alias); Assert.AreEqual(c1.Id, relations[2].ChildId); }
public void CacheActiveForIntsAndGuids() { var realCache = new AppCaches( new ObjectCacheAppCache(), new DictionaryAppCache(), new IsolatedCaches(t => new ObjectCacheAppCache())); IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { MediaRepository repository = CreateRepository(provider, out MediaTypeRepository mediaTypeRepository, appCaches: realCache); IUmbracoDatabase udb = ScopeAccessor.AmbientScope.Database; udb.EnableSqlCount = false; MediaType mediaType = MediaTypeBuilder.CreateSimpleMediaType("umbTextpage1", "Textpage"); mediaTypeRepository.Save(mediaType); Media media = MediaBuilder.CreateSimpleMedia(mediaType, "hello", -1); repository.Save(media); udb.EnableSqlCount = true; // go get it, this should already be cached since the default repository key is the INT IMedia found = repository.Get(media.Id); Assert.AreEqual(0, udb.SqlCount); // retrieve again, this should use cache found = repository.Get(media.Id); Assert.AreEqual(0, udb.SqlCount); // reset counter udb.EnableSqlCount = false; udb.EnableSqlCount = true; // now get by GUID, this won't be cached yet because the default repo key is not a GUID found = repository.Get(media.Key); int sqlCount = udb.SqlCount; Assert.Greater(sqlCount, 0); // retrieve again, this should use cache now found = repository.Get(media.Key); Assert.AreEqual(sqlCount, udb.SqlCount); } }
public void Deleting_Media_Types_With_Hierarchy_Of_Media_Items_Doesnt_Raise_Trashed_Event_For_Deleted_Items() { ContentNotificationHandler.MovedMediaToRecycleBin = MovedMediaToRecycleBin; try { IMediaType contentType1 = MediaTypeBuilder.CreateSimpleMediaType("test1", "Test1"); MediaTypeService.Save(contentType1); IMediaType contentType2 = MediaTypeBuilder.CreateSimpleMediaType("test2", "Test2"); MediaTypeService.Save(contentType2); IMediaType contentType3 = MediaTypeBuilder.CreateSimpleMediaType("test3", "Test3"); MediaTypeService.Save(contentType3); IMediaType[] contentTypes = { contentType1, contentType2, contentType3 }; var parentId = -1; var ids = new List <int>(); for (var i = 0; i < 2; i++) { for (var index = 0; index < contentTypes.Length; index++) { var contentType = contentTypes[index]; var contentItem = MediaBuilder.CreateSimpleMedia(contentType, "MyName_" + index + "_" + i, parentId); MediaService.Save(contentItem); parentId = contentItem.Id; ids.Add(contentItem.Id); } } foreach (var contentType in contentTypes.Reverse()) { MediaTypeService.Delete(contentType); } } finally { ContentNotificationHandler.MovedMediaToRecycleBin = null; } }
public void Deleting_Media_Type_With_Hierarchy_Of_Media_Items_Moves_Orphaned_Media_To_Recycle_Bin() { IMediaType contentType1 = MediaTypeBuilder.CreateSimpleMediaType("test1", "Test1"); MediaTypeService.Save(contentType1); IMediaType contentType2 = MediaTypeBuilder.CreateSimpleMediaType("test2", "Test2"); MediaTypeService.Save(contentType2); IMediaType contentType3 = MediaTypeBuilder.CreateSimpleMediaType("test3", "Test3"); MediaTypeService.Save(contentType3); IMediaType[] contentTypes = { contentType1, contentType2, contentType3 }; var parentId = -1; var ids = new List <int>(); for (var i = 0; i < 2; i++) { for (var index = 0; index < contentTypes.Length; index++) { var contentType = contentTypes[index]; var contentItem = MediaBuilder.CreateSimpleMedia(contentType, "MyName_" + index + "_" + i, parentId); MediaService.Save(contentItem); parentId = contentItem.Id; ids.Add(contentItem.Id); } } // delete the first content type, all other content of different content types should be in the recycle bin MediaTypeService.Delete(contentTypes[0]); var found = MediaService.GetByIds(ids); Assert.AreEqual(4, found.Count()); foreach (var content in found) { Assert.IsTrue(content.Trashed); } }
public void Return_List_Of_Content_Items_Where_Media_Item_Referenced() { var mt = MediaTypeBuilder.CreateSimpleMediaType("testMediaType", "Test Media Type"); MediaTypeService.Save(mt); var m1 = MediaBuilder.CreateSimpleMedia(mt, "hello 1", -1); MediaService.Save(m1); var ct = ContentTypeBuilder.CreateTextPageContentType("richTextTest"); ct.AllowedTemplates = Enumerable.Empty <ITemplate>(); ContentTypeService.Save(ct); void CreateContentWithMediaRefs() { var content = ContentBuilder.CreateTextpageContent(ct, "my content 2", -1); // 'bodyText' is a property with a RTE property editor which we knows automatically tracks relations content.Properties["bodyText"].SetValue(@"<p> <img src='/media/12312.jpg' data-udi='umb://media/" + m1.Key.ToString("N") + @"' /> </p>"); ContentService.Save(content); } for (var i = 0; i < 6; i++) { CreateContentWithMediaRefs(); // create 6 content items referencing the same media } var relations = RelationService.GetByChildId(m1.Id, Constants.Conventions.RelationTypes.RelatedMediaAlias) .ToList(); Assert.AreEqual(6, relations.Count); var entities = RelationService.GetParentEntitiesFromRelations(relations).ToList(); Assert.AreEqual(6, entities.Count); }
public void Can_Update_Media_Property_Values() { IMediaType mediaType = MediaTypeBuilder.CreateSimpleMediaType("test", "Test"); MediaTypeService.Save(mediaType); IMedia media = MediaBuilder.CreateSimpleMedia(mediaType, "hello", -1); media.SetValue("title", "title of mine"); media.SetValue("bodyText", "hello world"); MediaService.Save(media); // re-get media = MediaService.GetById(media.Id); media.SetValue("title", "another title of mine"); // Change a value media.SetValue("bodyText", null); // Clear a value media.SetValue("author", "new author"); // Add a value MediaService.Save(media); // re-get media = MediaService.GetById(media.Id); Assert.AreEqual("another title of mine", media.GetValue("title")); Assert.IsNull(media.GetValue("bodyText")); Assert.AreEqual("new author", media.GetValue("author")); }
private static IMedia CreateMedia(int nodeId) { MediaType mediaType = MediaTypeBuilder.CreateSimpleMediaType("image", "Image"); return(MediaBuilder.CreateSimpleMedia(mediaType, "Test image", -1, nodeId)); }
public void Can_Perform_Update_On_UserRepository() { var ct = ContentTypeBuilder.CreateBasicContentType("test"); var mt = MediaTypeBuilder.CreateSimpleMediaType("testmedia", "TestMedia"); // Arrange ICoreScopeProvider provider = ScopeProvider; using (var scope = provider.CreateCoreScope(autoComplete: true)) { var userRepository = CreateRepository(provider); var userGroupRepository = CreateUserGroupRepository(provider); ContentTypeRepository.Save(ct); MediaTypeRepository.Save(mt); var content = ContentBuilder.CreateBasicContent(ct); var media = MediaBuilder.CreateSimpleMedia(mt, "asdf", -1); DocumentRepository.Save(content); MediaRepository.Save(media); var user = CreateAndCommitUserWithGroup(userRepository, userGroupRepository); // Act var resolved = (User)userRepository.Get(user.Id); resolved.Name = "New Name"; // the db column is not used, default permissions are taken from the user type's permissions, this is a getter only //// resolved.DefaultPermissions = "ZYX"; resolved.Language = "fr"; resolved.IsApproved = false; resolved.RawPasswordValue = "new"; resolved.IsLockedOut = true; resolved.StartContentIds = new[] { content.Id }; resolved.StartMediaIds = new[] { media.Id }; resolved.Email = "*****@*****.**"; resolved.Username = "******"; userRepository.Save(resolved); var updatedItem = (User)userRepository.Get(user.Id); // Assert Assert.That(updatedItem.Id, Is.EqualTo(resolved.Id)); Assert.That(updatedItem.Name, Is.EqualTo(resolved.Name)); Assert.That(updatedItem.Language, Is.EqualTo(resolved.Language)); Assert.That(updatedItem.IsApproved, Is.EqualTo(resolved.IsApproved)); Assert.That(updatedItem.RawPasswordValue, Is.EqualTo(resolved.RawPasswordValue)); Assert.That(updatedItem.IsLockedOut, Is.EqualTo(resolved.IsLockedOut)); Assert.IsTrue(updatedItem.StartContentIds.UnsortedSequenceEqual(resolved.StartContentIds)); Assert.IsTrue(updatedItem.StartMediaIds.UnsortedSequenceEqual(resolved.StartMediaIds)); Assert.That(updatedItem.Email, Is.EqualTo(resolved.Email)); Assert.That(updatedItem.Username, Is.EqualTo(resolved.Username)); Assert.That(updatedItem.AllowedSections.Count(), Is.EqualTo(resolved.AllowedSections.Count())); foreach (var allowedSection in resolved.AllowedSections) { Assert.IsTrue(updatedItem.AllowedSections.Contains(allowedSection)); } } }