public void Can_Get_Tags_For_Content_For_Group() { var provider = TestObjects.GetScopeProvider(Logger); using (ScopeProvider.CreateScope()) { var contentRepository = CreateContentRepository(provider, out var contentTypeRepository); //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 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( content2.Id, contentType.PropertyTypes.First().Id, new[] { new Tag { Text = "tag1", Group = "test" }, new Tag { Text = "tag2", Group = "test" } }, false); var result = repository.GetTagsForEntity(content1.Id, "test1"); Assert.AreEqual(2, result.Count()); } }
public void CreateTestData() { var relateContent = new RelationType( "Relate Content on Copy", "relateContentOnCopy", true, Constants.ObjectTypes.Document, new Guid("C66BA18E-EAF3-4CFF-8A22-41B16D66A972")); var relateContentType = new RelationType("Relate ContentType on Copy", "relateContentTypeOnCopy", true, Constants.ObjectTypes.DocumentType, new Guid("A2CB7800-F571-4787-9638-BC48539A0EFB")); var provider = TestObjects.GetScopeProvider(Logger); using (var scope = provider.CreateScope()) { var accessor = (IScopeAccessor)provider; var relationTypeRepository = new RelationTypeRepository(accessor, AppCaches.Disabled, Mock.Of <ILogger>()); var entityRepository = new EntityRepository(accessor); var relationRepository = new RelationRepository(accessor, Mock.Of <ILogger>(), relationTypeRepository, entityRepository); relationTypeRepository.Save(relateContent); relationTypeRepository.Save(relateContentType); //Create and Save ContentType "umbTextpage" -> (NodeDto.NodeIdSeed) ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage"); ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType! ServiceContext.ContentTypeService.Save(contentType); //Create and Save Content "Homepage" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 1) Content textpage = MockedContent.CreateSimpleContent(contentType); ServiceContext.ContentService.Save(textpage, 0); //Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 2) Content subpage = MockedContent.CreateSimpleContent(contentType, "Text Page 1", textpage.Id); ServiceContext.ContentService.Save(subpage, 0); //Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 3) Content subpage2 = MockedContent.CreateSimpleContent(contentType, "Text Page 2", textpage.Id); ServiceContext.ContentService.Save(subpage2, 0); var relation = new Relation(textpage.Id, subpage.Id, relateContent) { Comment = string.Empty }; var relation2 = new Relation(textpage.Id, subpage2.Id, relateContent) { Comment = string.Empty }; relationRepository.Save(relation); relationRepository.Save(relation2); scope.Complete(); } }
public void Can_Get_Tags_For_Property_By_Key() { var provider = TestObjects.GetScopeProvider(Logger); using (ScopeProvider.CreateScope()) { var contentRepository = CreateDocumentRepository(provider, out var contentTypeRepository); //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 repository = CreateRepository(provider); repository.Assign( content1.Id, contentType.PropertyTypes.First().Id, new[] { new Tag { Text = "tag1", Group = "test" }, new Tag { Text = "tag2", Group = "test" }, new Tag { Text = "tag3", Group = "test" }, new Tag { Text = "tag4", Group = "test" } }, false); repository.Assign( content1.Id, contentType.PropertyTypes.Last().Id, new[] { new Tag { Text = "tag1", Group = "test" }, new Tag { Text = "tag2", Group = "test" } }, false); var result1 = repository.GetTagsForProperty(content1.Key, contentType.PropertyTypes.First().Alias).ToArray(); var result2 = repository.GetTagsForProperty(content1.Key, contentType.PropertyTypes.Last().Alias).ToArray(); Assert.AreEqual(4, result1.Length); Assert.AreEqual(2, result2.Length); } }
private void CreateStuff(out int id1, out int id2, out int id3, out string alias) { var contentService = ServiceContext.ContentService; var ctAlias = "umbTextpage" + Guid.NewGuid().ToString("N"); alias = ctAlias; for (int i = 0; i < 20; i++) { contentService.CreateContentWithIdentity("Test", -1, "umbTextpage", 0); } var contentTypeService = ServiceContext.ContentTypeService; var contentType = MockedContentTypes.CreateSimpleContentType(ctAlias, "test Doc Type"); contentTypeService.Save(contentType); for (int i = 0; i < 20; i++) { contentService.CreateContentWithIdentity("Test", -1, ctAlias, 0); } var parent = contentService.CreateContentWithIdentity("Test", -1, ctAlias, 0); id1 = parent.Id; for (int i = 0; i < 20; i++) { contentService.CreateContentWithIdentity("Test", parent, ctAlias); } IContent current = parent; for (int i = 0; i < 20; i++) { current = contentService.CreateContentWithIdentity("Test", current, ctAlias); } contentType = MockedContentTypes.CreateSimpleContentType("umbMandatory" + Guid.NewGuid().ToString("N"), "Mandatory Doc Type", true); contentType.PropertyGroups.First().PropertyTypes.Add( new PropertyType("test", DataTypeDatabaseType.Ntext, "tags") { DataTypeDefinitionId = 1041 }); contentTypeService.Save(contentType); var content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1); content1.SetTags("tags", new[] { "hello", "world", "some", "tags" }, true); contentService.Publish(content1); id2 = content1.Id; var content2 = MockedContent.CreateSimpleContent(contentType, "Tagged content 2", -1); content2.SetTags("tags", new[] { "hello", "world", "some", "tags" }, true); contentService.Publish(content2); id3 = content2.Id; contentService.MoveToRecycleBin(content1); }
public void Can_Remove_Specific_Tags_From_Property() { var provider = TestObjects.GetScopeProvider(Logger); using (ScopeProvider.CreateScope()) { var contentRepository = CreateContentRepository(provider, out var contentTypeRepository); //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 content = MockedContent.CreateSimpleContent(contentType); contentRepository.Save(content); var repository = CreateRepository(provider); repository.Assign( content.Id, contentType.PropertyTypes.First().Id, new[] { new Tag { Text = "tag1", Group = "test" }, new Tag { Text = "tag2", Group = "test" }, new Tag { Text = "tag3", Group = "test" }, new Tag { Text = "tag4", Group = "test" } }, false); repository.Remove( content.Id, contentType.PropertyTypes.First().Id, new[] { new Tag { Text = "tag2", Group = "test" }, new Tag { Text = "tag3", Group = "test" } }); var result = repository.GetTagsForEntity(content.Id).ToArray(); Assert.AreEqual(2, result.Length); Assert.AreEqual("tag1", result[0].Text); Assert.AreEqual("tag4", result[1].Text); } }
public void DirtyProperty_Reset_Clears_SavedPublishedState() { var contentType = MockedContentTypes.CreateTextPageContentType(); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); content.PublishedState = PublishedState.Publishing; Assert.IsFalse(content.Published); content.ResetDirtyProperties(false); // resets Assert.AreEqual(PublishedState.Unpublished, content.PublishedState); Assert.IsFalse(content.Published); }
public void Can_Verify_Mocked_Content() { // Arrange var contentType = MockedContentTypes.CreateTextpageContentType(); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); // Act // Assert Assert.That(content, Is.Not.Null); }
public void EntityService_Can_Get_Child_Content_By_ParentId_And_UmbracoObjectType_With_Variant_Names() { var service = ServiceContext.EntityService; var contentType = MockedContentTypes.CreateSimpleContentType("test1", "Test1", false); contentType.Variations = ContentVariation.Culture; ServiceContext.ContentTypeService.Save(contentType); var root = MockedContent.CreateSimpleContent(contentType); root.SetCultureName("Root", _langFr.IsoCode); // else cannot save ServiceContext.ContentService.Save(root); for (int i = 0; i < 10; i++) { var c1 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), root); if (i % 2 == 0) { c1.SetCultureName("Test " + i + " - FR", _langFr.IsoCode); c1.SetCultureName("Test " + i + " - ES", _langEs.IsoCode); } else { c1.SetCultureName("Test", _langFr.IsoCode); // else cannot save } ServiceContext.ContentService.Save(c1); } var entities = service.GetChildren(root.Id, UmbracoObjectTypes.Document).ToArray(); Assert.AreEqual(10, entities.Length); for (int i = 0; i < entities.Length; i++) { Assert.AreEqual(0, entities[i].AdditionalData.Count); if (i % 2 == 0) { var doc = (IDocumentEntitySlim)entities[i]; var keys = doc.CultureNames.Keys.ToList(); var vals = doc.CultureNames.Values.ToList(); Assert.AreEqual(_langFr.IsoCode.ToLowerInvariant(), keys[0].ToLowerInvariant()); Assert.AreEqual("Test " + i + " - FR", vals[0]); Assert.AreEqual(_langEs.IsoCode.ToLowerInvariant(), keys[1].ToLowerInvariant()); Assert.AreEqual("Test " + i + " - ES", vals[1]); } else { Assert.AreEqual(0, entities[i].AdditionalData.Count); } } }
public void Should_Not_Clear_Published_Flag_When_Unpublishing_From_Saved() { var contentType = MockedContentTypes.CreateTextpageContentType(); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); content.ResetDirtyProperties(false); content.ChangePublishedState(PublishedState.Saved); content.ResetDirtyProperties(false); content.ChangePublishedState(PublishedState.Unpublished); Assert.IsFalse(content.ShouldClearPublishedFlagForPreviousVersions()); }
public void Should_Create_New_Version_When_Saving_After_Publishing() { var contentType = MockedContentTypes.CreateTextpageContentType(); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); content.ResetDirtyProperties(false); content.ChangePublishedState(PublishedState.Published); content.ResetDirtyProperties(false); content.ChangePublishedState(PublishedState.Saved); Assert.IsTrue(content.ShouldCreateNewVersion()); }
public void CreateTestData() { var relateContent = new RelationType(new Guid(Constants.ObjectTypes.Document), new Guid("C66BA18E-EAF3-4CFF-8A22-41B16D66A972"), "relateContentOnCopy") { IsBidirectional = true, Name = "Relate Content on Copy" }; var relateContentType = new RelationType(new Guid(Constants.ObjectTypes.DocumentType), new Guid("A2CB7800-F571-4787-9638-BC48539A0EFB"), "relateContentTypeOnCopy") { IsBidirectional = true, Name = "Relate ContentType on Copy" }; var provider = new PetaPocoUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); var relationTypeRepository = new RelationTypeRepository(unitOfWork); var relationRepository = new RelationRepository(unitOfWork, NullCacheProvider.Current, relationTypeRepository); relationTypeRepository.AddOrUpdate(relateContent); relationTypeRepository.AddOrUpdate(relateContentType); unitOfWork.Commit(); //Create and Save ContentType "umbTextpage" -> 1045 ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage"); ServiceContext.ContentTypeService.Save(contentType); //Create and Save Content "Homepage" based on "umbTextpage" -> 1046 Content textpage = MockedContent.CreateSimpleContent(contentType); ServiceContext.ContentService.Save(textpage, 0); //Create and Save Content "Text Page 1" based on "umbTextpage" -> 1047 Content subpage = MockedContent.CreateSimpleContent(contentType, "Text Page 1", textpage.Id); ServiceContext.ContentService.Save(subpage, 0); //Create and Save Content "Text Page 1" based on "umbTextpage" -> 1048 Content subpage2 = MockedContent.CreateSimpleContent(contentType, "Text Page 2", textpage.Id); ServiceContext.ContentService.Save(subpage2, 0); var relation = new Relation(textpage.Id, subpage.Id, relateContent) { Comment = string.Empty }; var relation2 = new Relation(textpage.Id, subpage2.Id, relateContent) { Comment = string.Empty }; relationRepository.AddOrUpdate(relation); relationRepository.AddOrUpdate(relation2); unitOfWork.Commit(); }
public void Should_Not_Persist_Values_When_Saving_After_Publishing_But_No_Data_Changed() { var contentType = MockedContentTypes.CreateTextpageContentType(); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); content.ResetDirtyProperties(false); content.ChangePublishedState(PublishedState.Published); content.ResetDirtyProperties(false); content.ChangePublishedState(PublishedState.Saved); Assert.IsFalse(content.RequiresSaving()); }
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); } } }
public void To_Display_Model_With_Non_Grouped_Properties() { var idSeed = 1; var contentType = MockedContentTypes.CreateSimpleContentType(); //add non-grouped properties contentType.AddPropertyType(new PropertyType(Constants.PropertyEditors.TextboxAlias, DataTypeDatabaseType.Ntext, "nonGrouped1") { Name = "Non Grouped 1", Description = "", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -88 }); contentType.AddPropertyType(new PropertyType(Constants.PropertyEditors.TextboxAlias, DataTypeDatabaseType.Ntext, "nonGrouped2") { Name = "Non Grouped 2", Description = "", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -88 }); //set ids or it wont work contentType.Id = idSeed; foreach (var p in contentType.PropertyTypes) { p.Id = idSeed; idSeed++; } var content = MockedContent.CreateSimpleContent(contentType); foreach (var p in content.Properties) { p.Id = idSeed; idSeed++; } //need ids for tabs var id = 1; foreach (var g in content.PropertyGroups) { g.Id = id; id++; } //ensure that nothing is marked as dirty contentType.ResetDirtyProperties(false); //ensure that nothing is marked as dirty content.ResetDirtyProperties(false); var result = Mapper.Map <IContent, ContentItemDisplay>(content); AssertBasics(result, content); foreach (var p in content.Properties) { AssertDisplayProperty(result, p, ApplicationContext); } Assert.AreEqual(content.PropertyGroups.Count(), result.Tabs.Count() - 1); Assert.IsTrue(result.Tabs.Any(x => x.Label == ui.Text("general", "properties"))); Assert.AreEqual(2, result.Tabs.Where(x => x.Label == ui.Text("general", "properties")).SelectMany(x => x.Properties.Where(p => p.Alias.StartsWith("_umb_") == false)).Count()); }
private IEnumerable <IContent> CreateChildrenOf(IContentType contentType, IContent content, int depth) { var list = new List <IContent>(); for (int i = 0; i < depth; i++) { var c = MockedContent.CreateSimpleContent(contentType, "Hierarchy Simple Text Subpage " + i, content); list.Add(c); Console.WriteLine("Created: 'Hierarchy Simple Text Subpage {0}' - Depth: {1}", i, depth); } return(list); }
public void All_Dirty_Properties_Get_Reset() { var contentType = MockedContentTypes.CreateTextpageContentType(); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); content.ResetDirtyProperties(false); Assert.IsFalse(content.IsDirty()); foreach (var prop in content.Properties) { Assert.IsFalse(prop.IsDirty()); } }
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 DirtyProperty_Reset_Clears_SavedPublishedState() { var contentType = MockedContentTypes.CreateTextPageContentType(); Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); content.PublishedState = PublishedState.Publishing; Assert.IsFalse(content.Published); content.ResetDirtyProperties(false); // resets Assert.AreEqual(PublishedState.Unpublished, content.PublishedState); Assert.IsFalse(content.Published); }
public void To_Content_Item_Simple() { var contentType = MockedContentTypes.CreateSimpleContentType(); var content = MockedContent.CreateSimpleContent(contentType); var result = Mapper.Map <IContent, ContentItemBasic <ContentPropertyBasic, IContent> >(content); AssertBasics(result, content); foreach (var p in content.Properties) { AssertBasicProperty(result, p); } }
public void SupersededEvents() { DoSaveForContent += OnDoThingFail; DoDeleteForContent += OnDoThingFail; DoForTestArgs += OnDoThingFail; DoForTestArgs2 += OnDoThingFail; var contentType = MockedContentTypes.CreateBasicContentType(); var content1 = MockedContent.CreateBasicContent(contentType); content1.Id = 123; var content2 = MockedContent.CreateBasicContent(contentType); content2.Id = 456; var content3 = MockedContent.CreateBasicContent(contentType); content3.Id = 789; var scopeProvider = _testObjects.GetScopeProvider(Mock.Of <ILogger>()); using (var scope = scopeProvider.CreateScope(eventDispatcher: new PassiveEventDispatcher())) { //content1 will be filtered from the args scope.Events.Dispatch(DoSaveForContent, this, new SaveEventArgs <IContent>(new[] { content1, content3 })); scope.Events.Dispatch(DoDeleteForContent, this, new DeleteEventArgs <IContent>(content1), "DoDeleteForContent"); scope.Events.Dispatch(DoSaveForContent, this, new SaveEventArgs <IContent>(content2)); //this entire event will be filtered scope.Events.Dispatch(DoForTestArgs, this, new TestEventArgs(content1)); scope.Events.Dispatch(DoForTestArgs2, this, new TestEventArgs2(content1)); // events have been queued var events = scope.Events.GetEvents(EventDefinitionFilter.All).ToArray(); Assert.AreEqual(4, events.Length); Assert.AreEqual(typeof(SaveEventArgs <IContent>), events[0].Args.GetType()); Assert.AreEqual(1, ((SaveEventArgs <IContent>)events[0].Args).SavedEntities.Count()); Assert.AreEqual(content3.Id, ((SaveEventArgs <IContent>)events[0].Args).SavedEntities.First().Id); Assert.AreEqual(typeof(DeleteEventArgs <IContent>), events[1].Args.GetType()); Assert.AreEqual(content1.Id, ((DeleteEventArgs <IContent>)events[1].Args).DeletedEntities.First().Id); Assert.AreEqual(typeof(SaveEventArgs <IContent>), events[2].Args.GetType()); Assert.AreEqual(content2.Id, ((SaveEventArgs <IContent>)events[2].Args).SavedEntities.First().Id); Assert.AreEqual(typeof(TestEventArgs2), events[3].Args.GetType()); } }
public void Can_Verify_Mocked_Content() { // Arrange var contentType = MockedContentTypes.CreateTextPageContentType(); Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); // Act // Assert Assert.That(content, Is.Not.Null); }
public void Can_Verify_Dirty_Property_On_Content() { // Arrange var contentType = MockedContentTypes.CreateTextpageContentType(); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); // Act content.ResetDirtyProperties(); content.Name = "New Home"; // Assert Assert.That(content.Name, Is.EqualTo("New Home")); Assert.That(content.IsPropertyDirty("Name"), Is.True); }
public void Can_Set_Property_Value_As_String() { // Arrange var contentType = MockedContentTypes.CreateTextpageContentType(); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); // Act content.SetValue("title", "This is the new title"); // Assert Assert.That(content.Properties.Any(), Is.True); Assert.That(content.Properties["title"], Is.Not.Null); Assert.That(content.Properties["title"].Value, Is.EqualTo("This is the new title")); }
public void TagApiConsistencyTest() { var contentService = ServiceContext.ContentService; var contentTypeService = ServiceContext.ContentTypeService; var tagService = ServiceContext.TagService; var contentType = MockedContentTypes.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", true); contentType.PropertyGroups.First().PropertyTypes.Add( new PropertyType("test", ValueStorageType.Ntext, "tags") { DataTypeId = 1041 }); contentTypeService.Save(contentType); IContent content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1); content1.AssignTags("tags", new[] { "cow", "pig", "goat" }); contentService.SaveAndPublish(content1); // change content1.AssignTags("tags", new[] { "elephant" }, true); content1.RemoveTags("tags", new[] { "cow" }); contentService.SaveAndPublish(content1); // more changes content1.AssignTags("tags", new[] { "mouse" }, true); contentService.SaveAndPublish(content1); content1.RemoveTags("tags", new[] { "mouse" }); contentService.SaveAndPublish(content1); // get it back content1 = contentService.GetById(content1.Id); var tagsValue = content1.GetValue("tags").ToString(); var tagsValues = JsonConvert.DeserializeObject <string[]>(tagsValue); Assert.AreEqual(3, tagsValues.Length); Assert.Contains("pig", tagsValues); Assert.Contains("goat", tagsValues); Assert.Contains("elephant", tagsValues); var tags = tagService.GetTagsForProperty(content1.Id, "tags").ToArray(); Assert.IsTrue(tags.All(x => x.Group == "default")); tagsValues = tags.Select(x => x.Text).ToArray(); Assert.AreEqual(3, tagsValues.Length); Assert.Contains("pig", tagsValues); Assert.Contains("goat", tagsValues); Assert.Contains("elephant", tagsValues); }
public void To_Content_Item_Dto() { var contentType = MockedContentTypes.CreateSimpleContentType(); var content = MockedContent.CreateSimpleContent(contentType); FixUsers(content); var result = Mapper.Map <IContent, ContentPropertyCollectionDto>(content); foreach (var p in content.Properties) { AssertProperty(result, p); } }
public void Can_Deep_Clone_Perf_Test() { // Arrange var contentType = MockedContentTypes.CreateTextPageContentType(); contentType.Id = 99; var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); var i = 200; foreach (var property in content.Properties) { property.Id = ++i; } content.Id = 10; content.CreateDate = DateTime.Now; content.CreatorId = 22; content.Key = Guid.NewGuid(); content.Level = 3; content.Path = "-1,4,10"; content.ContentSchedule.Add(DateTime.Now, DateTime.Now.AddDays(1)); //content.ChangePublishedState(PublishedState.Published); content.SortOrder = 5; content.TemplateId = 88; content.Trashed = false; content.UpdateDate = DateTime.Now; content.WriterId = 23; var runtimeCache = new ObjectCacheAppCache(); runtimeCache.Insert(content.Id.ToString(CultureInfo.InvariantCulture), () => content); var proflog = GetTestProfilingLogger(); using (proflog.DebugDuration <ContentTests>("STARTING PERF TEST WITH RUNTIME CACHE")) { for (int j = 0; j < 1000; j++) { var clone = runtimeCache.Get(content.Id.ToString(CultureInfo.InvariantCulture)); } } using (proflog.DebugDuration <ContentTests>("STARTING PERF TEST WITHOUT RUNTIME CACHE")) { for (int j = 0; j < 1000; j++) { var clone = (ContentType)contentType.DeepClone(); } } }
public void PropertyValuesWithSpecialTypes() { var provider = TestObjects.GetScopeProvider(Logger); using (var scope = provider.CreateScope()) { var repository = CreateRepository((IScopeAccessor)provider, out var contentTypeRepository, out DataTypeRepository dataTypeDefinitionRepository); var editor = new DecimalPropertyEditor(Logger); var dtd = new DataType(editor) { Name = "test", DatabaseType = ValueStorageType.Decimal }; dataTypeDefinitionRepository.Save(dtd); const string decimalPropertyAlias = "decimalProperty"; const string intPropertyAlias = "intProperty"; const string dateTimePropertyAlias = "datetimeProperty"; var dateValue = new DateTime(2016, 1, 6); var propertyTypeCollection = new PropertyTypeCollection(true, new List <PropertyType> { MockedPropertyTypes.CreateDecimalProperty(decimalPropertyAlias, "Decimal property", dtd.Id), MockedPropertyTypes.CreateIntegerProperty(intPropertyAlias, "Integer property"), MockedPropertyTypes.CreateDateTimeProperty(dateTimePropertyAlias, "DateTime property") }); var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage", propertyTypeCollection); contentTypeRepository.Save(contentType); // int and decimal values are passed in as strings as they would be from the backoffice UI var textpage = MockedContent.CreateSimpleContentWithSpecialDatabaseTypes(contentType, "*****@*****.**", -1, "100", "150", dateValue); repository.Save(textpage); scope.Complete(); Assert.That(contentType.HasIdentity, Is.True); Assert.That(textpage.HasIdentity, Is.True); var persistedTextpage = repository.Get(textpage.Id); Assert.That(persistedTextpage.Name, Is.EqualTo(textpage.Name)); Assert.AreEqual(100m, persistedTextpage.GetValue(decimalPropertyAlias)); Assert.AreEqual(persistedTextpage.GetValue(decimalPropertyAlias), textpage.GetValue(decimalPropertyAlias)); Assert.AreEqual(150, persistedTextpage.GetValue(intPropertyAlias)); Assert.AreEqual(persistedTextpage.GetValue(intPropertyAlias), textpage.GetValue(intPropertyAlias)); Assert.AreEqual(dateValue, persistedTextpage.GetValue(dateTimePropertyAlias)); Assert.AreEqual(persistedTextpage.GetValue(dateTimePropertyAlias), textpage.GetValue(dateTimePropertyAlias)); } }
public void TagsCanBecomeInvariant2() { var languageService = ServiceContext.LocalizationService; languageService.Save(new Language("fr-FR")); // en-US is already there var enId = ServiceContext.LocalizationService.GetLanguageIdByIsoCode("en-US").Value; var contentService = ServiceContext.ContentService; var contentTypeService = ServiceContext.ContentTypeService; var tagService = ServiceContext.TagService; var contentType = MockedContentTypes.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", true); PropertyType propertyType; contentType.PropertyGroups.First().PropertyTypes.Add( propertyType = new PropertyType("test", ValueStorageType.Ntext, "tags") { DataTypeId = 1041, Variations = ContentVariation.Culture }); contentType.Variations = ContentVariation.Culture; contentTypeService.Save(contentType); IContent content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1); content1.SetCultureName("name-fr", "fr-FR"); content1.SetCultureName("name-en", "en-US"); content1.AssignTags("tags", new[] { "hello", "world", "some", "tags", "plus" }, culture: "fr-FR"); content1.AssignTags("tags", new[] { "hello", "world", "another", "one" }, culture: "en-US"); contentService.SaveAndPublish(content1); IContent content2 = MockedContent.CreateSimpleContent(contentType, "Tagged content 2", -1); content2.SetCultureName("name-fr", "fr-FR"); content2.SetCultureName("name-en", "en-US"); content2.AssignTags("tags", new[] { "hello", "world", "some", "tags", "plus" }, culture: "fr-FR"); content2.AssignTags("tags", new[] { "hello", "world", "another", "one" }, culture: "en-US"); contentService.SaveAndPublish(content2); //// pretend we already have invariant values //using (var scope = ScopeProvider.CreateScope()) //{ // scope.Database.Execute("INSERT INTO [cmsTags] ([tag], [group], [languageId]) SELECT DISTINCT [tag], [group], NULL FROM [cmsTags] WHERE [languageId] IS NOT NULL"); //} // this should work propertyType.Variations = ContentVariation.Nothing; Assert.DoesNotThrow(() => contentTypeService.Save(contentType)); }
public void Can_Verify_Content_Is_Trashed() { // Arrange var contentType = MockedContentTypes.CreateTextpageContentType(); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); // Act content.ResetDirtyProperties(); content.ChangeTrashedState(true); // Assert Assert.That(content.IsPropertyDirty("Trashed"), Is.True); Assert.That(content.Trashed, Is.True); Assert.That(content.IsPropertyDirty("Name"), Is.False); }
public void Should_Create_New_Version_When_Saving_After_Publishing() { var contentType = MockedContentTypes.CreateTextpageContentType(); var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1); content.ResetDirtyProperties(false); content.ChangePublishedState(PublishedState.Published); content.ResetDirtyProperties(false); //no version will be created if no data is changed content.Properties.First().Value = "hello world"; content.ChangePublishedState(PublishedState.Saved); Assert.IsTrue(content.ShouldCreateNewVersion()); }