public void Get_User_Permissions_For_Assigned_Permission_Nodes() { // Arrange var user = CreateTestUser(out var userGroup); var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); var contentType = ContentTypeBuilder.CreateSimpleContentType(defaultTemplateId: template.Id); ContentTypeService.Save(contentType); Content[] content = { ContentBuilder.CreateSimpleContent(contentType), ContentBuilder.CreateSimpleContent(contentType), ContentBuilder.CreateSimpleContent(contentType) }; ContentService.Save(content); ContentService.SetPermission(content[0], ActionBrowse.ActionLetter, new[] { userGroup.Id }); ContentService.SetPermission(content[0], ActionDelete.ActionLetter, new[] { userGroup.Id }); ContentService.SetPermission(content[0], ActionMove.ActionLetter, new[] { userGroup.Id }); ContentService.SetPermission(content[1], ActionBrowse.ActionLetter, new[] { userGroup.Id }); ContentService.SetPermission(content[1], ActionDelete.ActionLetter, new[] { userGroup.Id }); ContentService.SetPermission(content[2], ActionBrowse.ActionLetter, new[] { userGroup.Id }); // Act var permissions = UserService.GetPermissions(user, content[0].Id, content[1].Id, content[2].Id).ToArray(); // Assert Assert.AreEqual(3, permissions.Length); Assert.AreEqual(3, permissions[0].AssignedPermissions.Length); Assert.AreEqual(2, permissions[1].AssignedPermissions.Length); Assert.AreEqual(1, permissions[2].AssignedPermissions.Length); }
public void Can_Perform_Delete_With_Heirarchy_On_ContentTypeRepository() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { ContentTypeRepository repository = ContentTypeRepository; ContentType ctMain = ContentTypeBuilder.CreateSimpleContentType(defaultTemplateId: 0); ContentType ctChild1 = ContentTypeBuilder.CreateSimpleContentType("child1", "Child 1", ctMain, randomizeAliases: true, defaultTemplateId: 0); ContentType ctChild2 = ContentTypeBuilder.CreateSimpleContentType("child2", "Child 2", ctChild1, randomizeAliases: true, defaultTemplateId: 0); repository.Save(ctMain); repository.Save(ctChild1); repository.Save(ctChild2); // Act IContentType resolvedParent = repository.Get(ctMain.Id); repository.Delete(resolvedParent); // Assert Assert.That(repository.Exists(ctMain.Id), Is.False); Assert.That(repository.Exists(ctChild1.Id), Is.False); Assert.That(repository.Exists(ctChild2.Id), Is.False); } }
public void Can_Perform_Query_On_ContentTypeRepository_Sort_By_Name() { IContentType contentType; // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { ContentTypeRepository repository = ContentTypeRepository; contentType = repository.Get(_textpageContentType.Id); ContentType child1 = ContentTypeBuilder.CreateSimpleContentType("abc", "abc", contentType, randomizeAliases: true, defaultTemplateId: 0); repository.Save(child1); ContentType child3 = ContentTypeBuilder.CreateSimpleContentType("zyx", "zyx", contentType, randomizeAliases: true, defaultTemplateId: 0); repository.Save(child3); ContentType child2 = ContentTypeBuilder.CreateSimpleContentType("a123", "a123", contentType, randomizeAliases: true, defaultTemplateId: 0); repository.Save(child2); scope.Complete(); } using (IScope scope = provider.CreateScope()) { ContentTypeRepository repository = ContentTypeRepository; // Act IEnumerable <IContentType> contentTypes = repository.Get(scope.SqlContext.Query <IContentType>().Where(x => x.ParentId == contentType.Id)); // Assert Assert.That(contentTypes.Count(), Is.EqualTo(3)); Assert.AreEqual("a123", contentTypes.ElementAt(0).Name); Assert.AreEqual("abc", contentTypes.ElementAt(1).Name); Assert.AreEqual("zyx", contentTypes.ElementAt(2).Name); } }
public void GivenIndexingDocument_WhenRichTextPropertyData_CanStoreImmenseFields() { using (GetSynchronousContentIndex(false, out var index, out _, out var contentValueSetBuilder)) { index.CreateIndex(); var contentType = ContentTypeBuilder.CreateBasicContentType(); contentType.AddPropertyType(new PropertyType(TestHelper.ShortStringHelper, "test", ValueStorageType.Ntext) { Alias = "rte", Name = "RichText", PropertyEditorAlias = Constants.PropertyEditors.Aliases.TinyMce }); var content = ContentBuilder.CreateBasicContent(contentType); content.Id = 555; content.Path = "-1,555"; var luceneStringFieldMaxLength = ByteBlockPool.BYTE_BLOCK_SIZE - 2; var faker = new Faker(); var immenseText = faker.Random.String(luceneStringFieldMaxLength + 10); content.Properties["rte"].SetValue(immenseText); var valueSet = contentValueSetBuilder.GetValueSets(content); index.IndexItems(valueSet); var results = index.Searcher.CreateQuery().Id(555).Execute(); var result = results.First(); var key = $"{UmbracoExamineFieldNames.RawFieldPrefix}rte"; Assert.IsTrue(result.Values.ContainsKey(key)); Assert.Greater(result.Values[key].Length, luceneStringFieldMaxLength); } }
public void Can_Perform_Add_On_ContentTypeRepository() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { // Act ContentType contentType = ContentTypeBuilder.CreateSimpleContentType("test", "Test", propertyGroupAlias: "testGroup", propertyGroupName: "testGroup"); ContentTypeRepository.Save(contentType); IContentType fetched = ContentTypeRepository.Get(contentType.Id); // Assert Assert.That(contentType.HasIdentity, Is.True); Assert.That(contentType.PropertyGroups.All(x => x.HasIdentity), Is.True); Assert.That(contentType.PropertyTypes.All(x => x.HasIdentity), Is.True); Assert.That(contentType.Path.Contains(","), Is.True); Assert.That(contentType.SortOrder, Is.GreaterThan(0)); Assert.That(contentType.PropertyGroups.ElementAt(0).Name == "testGroup", Is.True); int groupId = contentType.PropertyGroups.ElementAt(0).Id; Assert.That(contentType.PropertyTypes.All(x => x.PropertyGroupId.Value == groupId), Is.True); foreach (IPropertyType propertyType in contentType.PropertyTypes) { Assert.AreNotEqual(propertyType.Key, Guid.Empty); } TestHelper.AssertPropertyValuesAreEqual(fetched, contentType, ignoreProperties: new[] { "DefaultTemplate", "AllowedTemplates", "UpdateDate" }); } }
public async Task Content_Item_With_Schedule_Raises_SendingContentNotification() { IContentTypeService contentTypeService = GetRequiredService <IContentTypeService>(); IContentService contentService = GetRequiredService <IContentService>(); IJsonSerializer serializer = GetRequiredService <IJsonSerializer>(); var contentType = new ContentTypeBuilder().Build(); contentTypeService.Save(contentType); var contentToRequest = new ContentBuilder() .WithoutIdentity() .WithContentType(contentType) .Build(); contentService.Save(contentToRequest); _handler = notification => notification.Content.AllowPreview = false; var url = PrepareApiControllerUrl <ContentController>(x => x.GetById(contentToRequest.Id)); HttpResponseMessage response = await Client.GetAsync(url); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); var text = await response.Content.ReadAsStringAsync(); text = text.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix); var display = serializer.Deserialize <ContentItemDisplayWithSchedule>(text); Assert.AreEqual(1, _messageCount); Assert.IsNotNull(display); Assert.IsFalse(display.AllowPreview); }
public void Can_Compose_Composite_ContentType_Collection() { // Arrange var simpleContentType = ContentTypeBuilder.CreateSimpleContentType(); var propertyType = new PropertyTypeBuilder() .WithAlias("coauthor") .WithName("Co-author") .Build(); var simple2ContentType = ContentTypeBuilder.CreateSimpleContentType( "anotherSimple", "Another Simple Page", propertyTypeCollection: new PropertyTypeCollection(true, new List <PropertyType> { propertyType })); // Act var added = simpleContentType.AddContentType(simple2ContentType); var compositionPropertyGroups = simpleContentType.CompositionPropertyGroups; var compositionPropertyTypes = simpleContentType.CompositionPropertyTypes; // Assert Assert.That(added, Is.True); Assert.That(compositionPropertyGroups.Count(), Is.EqualTo(1)); Assert.That(compositionPropertyTypes.Count(), Is.EqualTo(4)); }
public void DirtyProperty_UpdateDate() { var contentTypeService = Mock.Of <IContentTypeService>(); var contentType = ContentTypeBuilder.CreateTextPageContentType(); Mock.Get(contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())) .Returns(contentType); var content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1); var prop = content.Properties.First(); content.ResetDirtyProperties(false); var d = content.UpdateDate; prop.SetValue("A"); Assert.IsTrue(content.IsAnyUserPropertyDirty()); Assert.IsFalse(content.IsEntityDirty()); Assert.AreEqual(d, content.UpdateDate); content.UpdateDate = DateTime.Now; Assert.IsTrue(content.IsEntityDirty()); Assert.AreNotEqual(d, content.UpdateDate); // so... changing UpdateDate would count as a content property being changed // however in ContentRepository.PersistUpdatedItem, we change UpdateDate AFTER // we've tested for RequiresSaving & RequiresNewVersion so it's OK }
public void IsDirtyTests() { var propertyType = new PropertyTypeBuilder() .WithAlias("prop") .Build(); var prop = new Property(propertyType); var contentType = new ContentTypeBuilder() .WithAlias("contentType") .Build(); contentType.AddPropertyType(propertyType); var content = CreateContent(contentType); prop.SetValue("a"); Assert.AreEqual("a", prop.GetValue()); Assert.IsNull(prop.GetValue(published: true)); Assert.IsTrue(prop.IsDirty()); content.SetValue("prop", "a"); Assert.AreEqual("a", content.GetValue("prop")); Assert.IsNull(content.GetValue("prop", published: true)); Assert.IsTrue(content.IsDirty()); Assert.IsTrue(content.IsAnyUserPropertyDirty()); //// how can we tell which variation was dirty? }
public void DirtyProperty_WasDirty_UserProperty() { var contentTypeService = Mock.Of <IContentTypeService>(); var contentType = ContentTypeBuilder.CreateTextPageContentType(); Mock.Get(contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())) .Returns(contentType); var content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1); var prop = content.Properties.First(); content.ResetDirtyProperties(false); Assert.IsFalse(content.IsDirty()); Assert.IsFalse(content.WasDirty()); prop.SetValue("a"); prop.SetValue("b"); Assert.IsTrue(content.IsDirty()); Assert.IsFalse(content.WasDirty()); content.ResetDirtyProperties(false); Assert.IsFalse(content.IsDirty()); Assert.IsFalse(content.WasDirty()); prop.SetValue("a"); prop.SetValue("b"); content.ResetDirtyProperties(true); // what PersistUpdatedItem does Assert.IsFalse(content.IsDirty()); //// Assert.IsFalse(content.WasDirty()); // not impacted by user properties Assert.IsTrue(content.WasDirty()); // now it is! prop.SetValue("a"); prop.SetValue("b"); content.ResetDirtyProperties(); // what PersistUpdatedItem does Assert.IsFalse(content.IsDirty()); //// Assert.IsFalse(content.WasDirty()); // not impacted by user properties Assert.IsTrue(content.WasDirty()); // now it is! }
public void DirtyProperty_OnlyIfActuallyChanged_User() { var contentTypeService = Mock.Of <IContentTypeService>(); var contentType = ContentTypeBuilder.CreateTextPageContentType(); Mock.Get(contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())) .Returns(contentType); var content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1); var prop = content.Properties.First(); // if you assign a user property with its value it is not dirty // if you assign it with another value then back, it is dirty prop.SetValue("A"); content.ResetDirtyProperties(false); Assert.IsFalse(prop.IsDirty()); prop.SetValue("B"); Assert.IsTrue(prop.IsDirty()); content.ResetDirtyProperties(false); Assert.IsFalse(prop.IsDirty()); prop.SetValue("B"); Assert.IsFalse(prop.IsDirty()); prop.SetValue("A"); prop.SetValue("B"); Assert.IsTrue(prop.IsDirty()); }
public void DirtyProperty_WasDirty_ContentSortOrder() { var contentTypeService = Mock.Of <IContentTypeService>(); var contentType = ContentTypeBuilder.CreateTextPageContentType(); Mock.Get(contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())) .Returns(contentType); var content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1); content.ResetDirtyProperties(false); Assert.IsFalse(content.IsDirty()); Assert.IsFalse(content.WasDirty()); content.SortOrder = 0; content.SortOrder = 1; Assert.IsTrue(content.IsDirty()); Assert.IsFalse(content.WasDirty()); content.ResetDirtyProperties(false); Assert.IsFalse(content.IsDirty()); Assert.IsFalse(content.WasDirty()); content.SortOrder = 0; content.SortOrder = 1; content.ResetDirtyProperties(true); // what PersistUpdatedItem does Assert.IsFalse(content.IsDirty()); Assert.IsTrue(content.WasDirty()); content.SortOrder = 0; content.SortOrder = 1; content.ResetDirtyProperties(); // what PersistUpdatedItem does Assert.IsFalse(content.IsDirty()); Assert.IsTrue(content.WasDirty()); }
public async Task PostSave_Simple_Invariant() { ILocalizationService localizationService = GetRequiredService <ILocalizationService>(); // Add another language localizationService.Save(new LanguageBuilder() .WithCultureInfo(DkIso) .WithIsDefault(false) .Build()); string url = PrepareApiControllerUrl <ContentController>(x => x.PostSave(null)); IContentService contentService = GetRequiredService <IContentService>(); IContentTypeService contentTypeService = GetRequiredService <IContentTypeService>(); IContentType contentType = new ContentTypeBuilder() .WithId(0) .AddPropertyType() .WithAlias("title") .WithValueStorageType(ValueStorageType.Integer) .WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox) .WithName("Title") .Done() .WithContentVariation(ContentVariation.Nothing) .Build(); contentTypeService.Save(contentType); Content content = new ContentBuilder() .WithId(0) .WithName("Invariant") .WithContentType(contentType) .AddPropertyData() .WithKeyValue("title", "Cool invariant title") .Done() .Build(); contentService.SaveAndPublish(content); ContentItemSave model = new ContentItemSaveBuilder() .WithContent(content) .Build(); // Act HttpResponseMessage response = await Client.PostAsync(url, new MultipartFormDataContent { { new StringContent(JsonConvert.SerializeObject(model)), "contentItem" } }); // Assert string body = await response.Content.ReadAsStringAsync(); body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix); Assert.Multiple(() => { Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, body); ContentItemDisplay display = JsonConvert.DeserializeObject <ContentItemDisplay>(body); Assert.AreEqual(1, display.Variants.Count()); }); }
public void SingleContentType() { ContentTypeBuilder b = new ContentTypeBuilder(); b.Set("text/html"); Assert.Equal("text/html", b.Build()); }
public void Can_Verify_AllowedChildContentTypes_On_ContentType() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { ContentTypeRepository repository = ContentTypeRepository; ContentType subpageContentType = ContentTypeBuilder.CreateSimpleContentType("umbSubpage", "Subpage"); ContentType simpleSubpageContentType = ContentTypeBuilder.CreateSimpleContentType("umbSimpleSubpage", "Simple Subpage"); repository.Save(subpageContentType); repository.Save(simpleSubpageContentType); // Act IContentType contentType = repository.Get(_simpleContentType.Id); contentType.AllowedContentTypes = new List <ContentTypeSort> { new ContentTypeSort(new Lazy <int>(() => subpageContentType.Id), 0, subpageContentType.Alias), new ContentTypeSort(new Lazy <int>(() => simpleSubpageContentType.Id), 1, simpleSubpageContentType.Alias) }; repository.Save(contentType); // Assert IContentType updated = repository.Get(_simpleContentType.Id); Assert.That(updated.AllowedContentTypes.Any(), Is.True); Assert.That(updated.AllowedContentTypes.Any(x => x.Alias == subpageContentType.Alias), Is.True); Assert.That(updated.AllowedContentTypes.Any(x => x.Alias == simpleSubpageContentType.Alias), Is.True); } }
public void Maps_Templates_Correctly() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { var templateRepo = new TemplateRepository((IScopeAccessor)provider, AppCaches.Disabled, LoggerFactory.CreateLogger <TemplateRepository>(), FileSystems, IOHelper, ShortStringHelper, Mock.Of <IViewHelper>()); ContentTypeRepository repository = ContentTypeRepository; Template[] templates = new[] { new Template(ShortStringHelper, "test1", "test1"), new Template(ShortStringHelper, "test2", "test2"), new Template(ShortStringHelper, "test3", "test3") }; foreach (Template template in templates) { templateRepo.Save(template); } ContentType contentType = ContentTypeBuilder.CreateSimpleContentType(); contentType.AllowedTemplates = new[] { templates[0], templates[1] }; contentType.SetDefaultTemplate(templates[0]); repository.Save(contentType); // re-get IContentType result = repository.Get(contentType.Id); Assert.AreEqual(2, result.AllowedTemplates.Count()); Assert.AreEqual(templates[0].Id, result.DefaultTemplate.Id); } }
/// <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 Get_User_Permissions_For_Unassigned_Permission_Nodes() { // Arrange var user = CreateTestUser(out _); var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); var contentType = ContentTypeBuilder.CreateSimpleContentType(defaultTemplateId: template.Id); ContentTypeService.Save(contentType); Content[] content = { ContentBuilder.CreateSimpleContent(contentType), ContentBuilder.CreateSimpleContent(contentType), ContentBuilder.CreateSimpleContent(contentType) }; ContentService.Save(content); // Act var permissions = UserService.GetPermissions(user, content[0].Id, content[1].Id, content[2].Id).ToArray(); // Assert Assert.AreEqual(3, permissions.Length); Assert.AreEqual(17, permissions[0].AssignedPermissions.Length); Assert.AreEqual(17, permissions[1].AssignedPermissions.Length); Assert.AreEqual(17, permissions[2].AssignedPermissions.Length); }
public void Replacing_History_Cleanup_Removes_Old_Dirty_History_Properties() { var contentType = ContentTypeBuilder.CreateBasicContentType(); contentType.Alias = "NewValue"; contentType.HistoryCleanup.KeepAllVersionsNewerThanDays = 2; contentType.PropertyChanged += (sender, args) => { // Ensure that property changed is only invoked for history cleanup Assert.AreEqual(nameof(contentType.HistoryCleanup), args.PropertyName); }; // Since we're replacing the entire HistoryCleanup the changed property is no longer dirty, the entire HistoryCleanup is contentType.HistoryCleanup = new HistoryCleanup(); Assert.Multiple(() => { Assert.IsTrue(contentType.IsDirty()); Assert.IsFalse(contentType.WasDirty()); Assert.AreEqual(2, contentType.GetDirtyProperties().Count()); Assert.IsTrue(contentType.IsPropertyDirty(nameof(contentType.HistoryCleanup))); Assert.IsTrue(contentType.IsPropertyDirty(nameof(contentType.Alias))); }); }
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 GetDocumentVersionsEligibleForCleanup_Always_ExcludesActiveVersions() { Template template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); var contentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Textpage", defaultTemplateId: template.Id); ContentTypeService.Save(contentType); ContentTypeService.Save(contentType); var content = ContentBuilder.CreateSimpleContent(contentType); ContentService.SaveAndPublish(content); // At this point content has 2 versions, a draft version and a published version. ContentService.SaveAndPublish(content); // At this point content has 3 versions, a historic version, a draft version and a published version. using (ScopeProvider.CreateScope()) { var sut = new DocumentVersionRepository(ScopeAccessor); var results = sut.GetDocumentVersionsEligibleForCleanup(); Assert.Multiple(() => { Assert.AreEqual(1, results.Count); Assert.AreEqual(1, results.First().VersionId); }); } }
public void Serialize_ForContentTypeWithHistoryCleanupPolicy_OutputsSerializedHistoryCleanupPolicy() { // Arrange var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); // else, FK violation on contentType! var contentType = ContentTypeBuilder.CreateTextPageContentType(defaultTemplateId: template.Id); contentType.HistoryCleanup = new HistoryCleanup { PreventCleanup = true, KeepAllVersionsNewerThanDays = 1, KeepLatestVersionPerDayForDays = 2 }; ContentTypeService.Save(contentType); // Act var element = Serializer.Serialize(contentType); // Assert Assert.Multiple(() => { Assert.That(element.Element("HistoryCleanupPolicy") !.Attribute("preventCleanup") !.Value, Is.EqualTo("true")); Assert.That(element.Element("HistoryCleanupPolicy") !.Attribute("keepAllVersionsNewerThanDays") !.Value, Is.EqualTo("1")); Assert.That(element.Element("HistoryCleanupPolicy") !.Attribute("keepLatestVersionPerDayForDays") !.Value, Is.EqualTo("2")); }); }
public void Can_Compose_Nested_Composite_ContentType_Collection() { // Arrange ContentType metaContentType = ContentTypeBuilder.CreateMetaContentType(); ContentType simpleContentType = ContentTypeBuilder.CreateSimpleContentType(); PropertyType propertyType = new PropertyTypeBuilder() .WithAlias("coauthor") .WithName("Co-author") .Build(); ContentType simple2ContentType = ContentTypeBuilder.CreateSimpleContentType( "anotherSimple", "Another Simple Page", propertyTypeCollection: new PropertyTypeCollection(true, new List <PropertyType> { propertyType })); // Act bool addedMeta = simple2ContentType.AddContentType(metaContentType); bool added = simpleContentType.AddContentType(simple2ContentType); IEnumerable <PropertyGroup> compositionPropertyGroups = simpleContentType.CompositionPropertyGroups; IEnumerable <IPropertyType> compositionPropertyTypes = simpleContentType.CompositionPropertyTypes; // Assert Assert.That(addedMeta, Is.True); Assert.That(added, Is.True); Assert.That(compositionPropertyGroups.Count(), Is.EqualTo(2)); Assert.That(compositionPropertyTypes.Count(), Is.EqualTo(6)); Assert.That(simpleContentType.ContentTypeCompositionExists("meta"), Is.True); }
public void DeleteVersions_Always_DeletesSpecifiedVersions() { Template template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); var contentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Textpage", defaultTemplateId: template.Id); ContentTypeService.Save(contentType); var content = ContentBuilder.CreateSimpleContent(contentType); ContentService.SaveAndPublish(content); ContentService.SaveAndPublish(content); ContentService.SaveAndPublish(content); ContentService.SaveAndPublish(content); using (var scope = ScopeProvider.CreateScope()) { var query = scope.SqlContext.Sql(); query.Select <ContentVersionDto>() .From <ContentVersionDto>(); var sut = new DocumentVersionRepository(ScopeAccessor); sut.DeleteVersions(new [] { 1, 2, 3 }); var after = scope.Database.Fetch <ContentVersionDto>(query); Assert.Multiple(() => { Assert.AreEqual(2, after.Count); Assert.True(after.All(x => x.Id > 3)); }); } }
public void Can_Verify_Content_Is_Published() { ContentType contentType = ContentTypeBuilder.CreateTextPageContentType(); Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType); Content content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1); content.ResetDirtyProperties(); content.PublishedState = PublishedState.Publishing; Assert.IsFalse(content.IsPropertyDirty("Published")); Assert.IsFalse(content.Published); Assert.IsFalse(content.IsPropertyDirty("Name")); Assert.AreEqual(PublishedState.Publishing, content.PublishedState); // the repo would do content.Published = true; // and then Assert.IsTrue(content.IsPropertyDirty("Published")); Assert.IsTrue(content.Published); Assert.IsFalse(content.IsPropertyDirty("Name")); Assert.AreEqual(PublishedState.Published, content.PublishedState); // and before returning, content.ResetDirtyProperties(); // and then Assert.IsFalse(content.IsPropertyDirty("Published")); Assert.IsTrue(content.Published); Assert.IsFalse(content.IsPropertyDirty("Name")); Assert.AreEqual(PublishedState.Published, content.PublishedState); }
public void After_Committing_Changes_Was_Dirty_Is_True_On_Changed_Property() { // Arrange ContentType contentType = ContentTypeBuilder.CreateTextPageContentType(); contentType.ResetDirtyProperties(); // reset Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType); Content content = ContentBuilder.CreateTextpageContent(contentType, "test", -1); content.ResetDirtyProperties(); // Act content.SetValue("title", "new title"); Assert.That(content.IsEntityDirty(), Is.False); Assert.That(content.IsDirty(), Is.True); Assert.That(content.IsPropertyDirty("title"), Is.True); Assert.That(content.IsAnyUserPropertyDirty(), Is.True); Assert.That(content.GetDirtyUserProperties().Count(), Is.EqualTo(1)); Assert.That(content.Properties[0].IsDirty(), Is.True); Assert.That(content.Properties["title"].IsDirty(), Is.True); content.ResetDirtyProperties(); // this would be like committing the entity // Assert Assert.That(content.WasDirty(), Is.True); Assert.That(content.Properties[0].WasDirty(), Is.True); Assert.That(content.WasPropertyDirty("title"), Is.True); Assert.That(content.Properties["title"].IsDirty(), Is.False); Assert.That(content.Properties["title"].WasDirty(), Is.True); }
public void Can_Add_New_Property_To_New_PropertyType_In_New_PropertyGroup() { // Arrange ContentType contentType = ContentTypeBuilder.CreateTextPageContentType(); Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType); Content content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1); // Act PropertyType propertyType = new PropertyTypeBuilder() .WithAlias("subtitle") .WithName("Subtitle") .Build(); var propertyGroup = new PropertyGroup(true) { Alias = "testGroup", Name = "Test Group", SortOrder = 3 }; propertyGroup.PropertyTypes.Add(propertyType); contentType.PropertyGroups.Add(propertyGroup); var newProperty = new Property(propertyType); newProperty.SetValue("Subtitle Test"); content.Properties.Add(newProperty); // Assert Assert.That(content.Properties.Count, Is.EqualTo(5)); Assert.That(content.Properties["subtitle"].GetValue(), Is.EqualTo("Subtitle Test")); Assert.That(content.Properties["title"].GetValue(), Is.EqualTo("Textpage textpage")); }
public void Can_Add_New_Property_To_New_PropertyType() { // Arrange ContentType contentType = ContentTypeBuilder.CreateTextPageContentType(); Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType); Content content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1); // Act PropertyType propertyType = new PropertyTypeBuilder() .WithAlias("subtitle") .WithName("Subtitle") .Build(); contentType.PropertyGroups["content"].PropertyTypes.Add(propertyType); var newProperty = new Property(propertyType); newProperty.SetValue("This is a subtitle Test"); content.Properties.Add(newProperty); // Assert Assert.That(content.Properties.Contains("subtitle"), Is.True); Assert.That(content.Properties["subtitle"].GetValue(), Is.EqualTo("This is a subtitle Test")); }
public void Can_Serialize_Without_Error() { // Arrange ContentType contentType = ContentTypeBuilder.CreateTextPageContentType(); contentType.Id = 99; Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType); Content content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1); int i = 200; foreach (IProperty 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.SortOrder = 5; content.TemplateId = 88; content.Trashed = false; content.UpdateDate = DateTime.Now; content.WriterId = 23; string json = JsonConvert.SerializeObject(content); Debug.Print(json); }
public void Get_Non_Grouped_Properties() { ContentType contentType = ContentTypeBuilder.CreateSimpleContentType(); // Add non-grouped properties PropertyType pt1 = new PropertyTypeBuilder() .WithAlias("nonGrouped1") .WithName("Non Grouped 1") .Build(); PropertyType pt2 = new PropertyTypeBuilder() .WithAlias("nonGrouped2") .WithName("Non Grouped 2") .Build(); contentType.AddPropertyType(pt1); contentType.AddPropertyType(pt2); // Ensure that nothing is marked as dirty contentType.ResetDirtyProperties(false); Mock.Get(_contentTypeService).As <IContentTypeBaseService>().Setup(x => x.Get(It.IsAny <int>())).Returns(contentType); Content content = ContentBuilder.CreateSimpleContent(contentType); IEnumerable <IProperty> nonGrouped = content.GetNonGroupedProperties(); Assert.AreEqual(2, nonGrouped.Count()); Assert.AreEqual(5, content.Properties.Count()); }
public ContentTypeCodeGenerator( ContentTypeConfiguration configuration, XDocument contentTypeDefintion, CodeDomProvider codeDomProvider ) { this.configuration = configuration; this.codeDomProvider = codeDomProvider; contentTypeBuilder = new ContentTypeBuilder(configuration, contentTypeDefintion); }