public void Getting_1000_Uncached_Items() { // Arrange var contentType = ContentTypeService.Get(ContentType.Id); var pages = ContentBuilder.CreateTextpageContent(contentType, -1, 1000); ContentService.Save(pages, 0); using (var scope = ScopeProvider.CreateScope()) { var repository = DocumentRepository; // Act var watch = Stopwatch.StartNew(); var contents = repository.GetMany(); watch.Stop(); var elapsed = watch.ElapsedMilliseconds; Debug.Print("1000 content items retrieved in {0} ms without caching", elapsed); // Assert // Assert.That(contents.Any(x => x.HasIdentity == false), Is.False); // Assert.That(contents.Any(x => x == null), Is.False); } }
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 Root_Node_With_Domains_Causes_No_Warning() { // Setup domain service var domainServiceMock = new Mock <IDomainService>(); domainServiceMock.Setup(x => x.GetAssignedDomains(1060, It.IsAny <bool>())) .Returns(new[] { new UmbracoDomain("/", "da-dk"), new UmbracoDomain("/en", "en-us") }); // Create content, we need to specify and ID in order to be able to configure domain service var rootNode = new ContentBuilder() .WithContentType(CreateContentType()) .WithId(1060) .AddContentCultureInfosCollection() .AddCultureInfos() .WithCultureIso("da-dk") .Done() .AddCultureInfos() .WithCultureIso("en-us") .Done() .Done() .Build(); var culturesPublished = new[] { "en-us", "da-dk" }; var notifications = new SimpleNotificationModel(); var contentController = CreateContentController(domainServiceMock.Object); contentController.AddDomainWarnings(rootNode, culturesPublished, notifications); Assert.IsEmpty(notifications.Notifications); }
public void Root_Node_Without_Domains_Causes_SingleWarning() { var domainServiceMock = new Mock <IDomainService>(); domainServiceMock.Setup(x => x.GetAssignedDomains(It.IsAny <int>(), It.IsAny <bool>())) .Returns(Enumerable.Empty <IDomain>()); var rootNode = new ContentBuilder() .WithContentType(CreateContentType()) .WithId(1060) .AddContentCultureInfosCollection() .AddCultureInfos() .WithCultureIso("da-dk") .Done() .AddCultureInfos() .WithCultureIso("en-us") .Done() .Done() .Build(); var culturesPublished = new[] { "en-us", "da-dk" }; var notifications = new SimpleNotificationModel(); var contentController = CreateContentController(domainServiceMock.Object); contentController.AddDomainWarnings(rootNode, culturesPublished, notifications); Assert.AreEqual(1, notifications.Notifications.Count(x => x.NotificationType == NotificationStyle.Warning)); }
public void One_Warning_Per_Culture_Being_Published() { var domainServiceMock = new Mock <IDomainService>(); domainServiceMock.Setup(x => x.GetAssignedDomains(It.IsAny <int>(), It.IsAny <bool>())) .Returns(new[] { new UmbracoDomain("/", "da-dk") }); var rootNode = new ContentBuilder() .WithContentType(CreateContentType()) .WithId(1060) .AddContentCultureInfosCollection() .AddCultureInfos() .WithCultureIso("da-dk") .Done() .AddCultureInfos() .WithCultureIso("en-us") .Done() .Done() .Build(); var culturesPublished = new[] { "en-us", "da-dk", "nl-bk", "se-sv" }; var notifications = new SimpleNotificationModel(); var contentController = CreateContentController(domainServiceMock.Object); contentController.AddDomainWarnings(rootNode, culturesPublished, notifications); Assert.AreEqual(3, notifications.Notifications.Count(x => x.NotificationType == NotificationStyle.Warning)); }
public void GetPagedItemsByContentId_WithInvariantCultureContent_ReturnsPaginatedResults() { var 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); // Draft + Published ContentService.SaveAndPublish(content); // New Draft using (ScopeProvider.CreateScope()) { var sut = new DocumentVersionRepository((IScopeAccessor)ScopeProvider); var page1 = sut.GetPagedItemsByContentId(content.Id, 0, 2, out var page1Total); var page2 = sut.GetPagedItemsByContentId(content.Id, 1, 2, out var page2Total); Assert.Multiple(() => { Assert.AreEqual(2, page1.Count()); Assert.AreEqual(3, page1Total); Assert.AreEqual(1, page2.Count()); Assert.AreEqual(3, page2Total); }); } }
public async Task Content_Not_Published() { var contentType = ContentTypeBuilder.CreateBasicContentType(); var content = ContentBuilder.CreateBasicContent(contentType); content.Id = 1046; // FIXME: we are using this ID only because it's built into the test XML published cache content.Path = "-1,1046"; var umbracoContextAccessor = GetUmbracoContextAccessor("http://localhost:8000"); var publishedRouter = CreatePublishedRouter( umbracoContextAccessor, new[] { new ContentFinderByUrl(Mock.Of <ILogger <ContentFinderByUrl> >(), umbracoContextAccessor) }); var umbracoContext = umbracoContextAccessor.GetRequiredUmbracoContext(); var urlProvider = GetUrlProvider(umbracoContextAccessor, _requestHandlerSettings, _webRoutingSettings, out var uriUtility); var urls = (await content.GetContentUrlsAsync( publishedRouter, umbracoContext, GetLangService("en-US", "fr-FR"), GetTextService(), Mock.Of <IContentService>(), VariationContextAccessor, Mock.Of <ILogger <IContent> >(), uriUtility, urlProvider)).ToList(); Assert.AreEqual(1, urls.Count); Assert.AreEqual("content/itemNotPublished", urls[0].Text); Assert.IsFalse(urls[0].IsUrl); }
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 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 }
/// <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 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_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 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")); }
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_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 void Getting_1000_Cached_Items() { // Arrange IContentType contentType = ContentTypeService.Get(ContentType.Id); IEnumerable <Content> pages = ContentBuilder.CreateTextpageContent(contentType, -1, 1000); ContentService.Save(pages, 0); using (IScope scope = ScopeProvider.CreateScope()) { DocumentRepository repository = DocumentRepository; // Act IEnumerable <IContent> contents = repository.GetMany(); var watch = Stopwatch.StartNew(); IEnumerable <IContent> contentsCached = repository.GetMany(); watch.Stop(); long elapsed = watch.ElapsedMilliseconds; Debug.Print("1000 content items retrieved in {0} ms with caching", elapsed); // Assert // Assert.That(contentsCached.Any(x => x.HasIdentity == false), Is.False); // Assert.That(contentsCached.Any(x => x == null), Is.False); // Assert.That(contentsCached.Count(), Is.EqualTo(contents.Count())); } }
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 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 frmMain() { InitializeComponent(); PipelineHelper.DefaultInit(); builder = new ContentBuilder(null); builder.BuildStatusChanged += Builder_BuildStatusChanged; builder.ItemProgress += Builder_ItemProgress; builder.BuildMessage += Builder_BuildMessage; treeMap = new Dictionary <ContentItem, TreeNode>(); treeContentFiles.NodeMouseClick += TreeContentFilesOnNodeMouseClick; this.newFolderMenuItem.Click += (o, e) => AddNewFolder.Execute(GetSelectedItem(), CurrentProject.File); this.existingFolderMenuItem.Click += (o, e) => AddExistingFolder.Execute(GetSelectedItem(), CurrentProject.File); this.existingItemMenuItem.Click += (o, e) => AddExistingItem.Execute(GetSelectedItem(), CurrentProject.File); this.deleteMenuItem.Click += (o, e) => DeleteItem.Execute(GetSelectedItem()); this.deleteToolStripMenuItem.Click += (o, e) => DeleteItem.Execute(GetSelectedItem()); this.deleteToolStripMenuItem1.Click += (o, e) => DeleteItem.Execute(GetSelectedItem()); this.renameMenuItem.Click += (o, e) => RenameItem.Execute(GetSelectedItem(), treeMap); this.renameToolStripMenuItem.Click += (o, e) => RenameItem.Execute(GetSelectedItem(), treeMap); this.renameToolStripMenuItem1.Click += (o, e) => RenameItem.Execute(GetSelectedItem(), treeMap); this.buildToolStripMenuItem.Click += (o, e) => BuildItem.Execute(GetSelectedItem(), builder); this.buildToolStripMenuItem1.Click += (o, e) => BuildItem.Execute(GetSelectedItem(), builder); this.buildToolStripMenuItem2.Click += (o, e) => BuildItem.Execute(GetSelectedItem(), builder); }
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 async Task Should_ReturnDifferences_Test() { // Arrange const int id = 1; Content content1 = new ContentBuilder() .WithId(id) .WithLeftContent("BilacSP".ConvertToBase64FromUTF8String()) .Build(); Content content2 = new ContentBuilder() .WithId(id) .WithRightContent("BilakRP".ConvertToBase64FromUTF8String()) .Build(); await CreateContentAsync(content1, ContentDirection.Left).ConfigureAwait(false); await CreateContentAsync(content2, ContentDirection.Right).ConfigureAwait(false); // Act var response = await Client.GetAsync($"/v1/diff/{id}"); response.EnsureSuccessStatusCode(); // Assert var result = await response.Content.ReadAsStringAsync(); var differences = JsonConvert.DeserializeObject <List <ContentDiff> >(result); Assert.True(differences.Count > 0); }
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_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 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 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 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_Verify_Usage_Of_New_PropertyType_On_Content() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { ContentTypeRepository repository = ContentTypeRepository; IContentType contentType = repository.Get(_textpageContentType.Id); Content subpage = ContentBuilder.CreateTextpageContent(contentType, "Text Page 1", contentType.Id); DocumentRepository.Save(subpage); PropertyGroup propertyGroup = contentType.PropertyGroups.First(x => x.Name == "Meta"); propertyGroup.PropertyTypes.Add(new PropertyType(ShortStringHelper, "test", ValueStorageType.Ntext, "metaAuthor") { Name = "Meta Author", Description = string.Empty, Mandatory = false, SortOrder = 1, DataTypeId = -88 }); repository.Save(contentType); // Act IContent content = DocumentRepository.Get(subpage.Id); content.SetValue("metaAuthor", "John Doe"); DocumentRepository.Save(content); // Assert IContent updated = DocumentRepository.Get(subpage.Id); Assert.That(updated.GetValue("metaAuthor").ToString(), Is.EqualTo("John Doe")); Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(5)); Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "metaAuthor"), 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_Type_Has_Content_Nodes() { // Arrange IScopeProvider provider = ScopeProvider; using (IScope scope = provider.CreateScope()) { ContentTypeRepository repository = ContentTypeRepository; int contentTypeId = _textpageContentType.Id; IContentType contentType = repository.Get(contentTypeId); // Act bool result = repository.HasContentNodes(contentTypeId); Content subpage = ContentBuilder.CreateTextpageContent(contentType, "Test Page 1", contentType.Id); DocumentRepository.Save(subpage); bool result2 = repository.HasContentNodes(contentTypeId); // Assert Assert.That(result, Is.False); Assert.That(result2, Is.True); } }
public MainForm() { InitializeComponent(); contentBuilder = new ContentBuilder(); contentManager = new ContentManager(contentViewerControl.Services, contentBuilder.OutputDirectory); // Automatically bring up the "Load Content" dialog when first shown. this.Shown += openToolStripMenuItem_Click; }
public void GenerateBabylonFile(string file, string outputFile, bool skinned, bool rightToLeft) { if (OnImportProgressChanged != null) OnImportProgressChanged(0); var scene = new BabylonScene(Path.GetDirectoryName(outputFile)); var services = new ServiceContainer(); // Create a graphics device var form = new Form(); services.AddService<IGraphicsDeviceService>(GraphicsDeviceService.AddRef(form.Handle, 1, 1)); var contentBuilder = new ContentBuilder(ExtraPipelineAssemblies); var contentManager = new ContentManager(services, contentBuilder.OutputDirectory); // Tell the ContentBuilder what to build. contentBuilder.Clear(); contentBuilder.Add(Path.GetFullPath(file), "Model", Importer, skinned ? "SkinnedModelProcessor" : "ModelProcessor"); // Build this new model data. string buildError = contentBuilder.Build(); if (string.IsNullOrEmpty(buildError)) { var model = contentManager.Load<Model>("Model"); ParseModel(model, scene, rightToLeft); } else { throw new Exception(buildError); } // Output scene.Prepare(); using (var outputStream = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) { var ser = new DataContractJsonSerializer(typeof(BabylonScene)); ser.WriteObject(outputStream, scene); } // Cleaning foreach (var path in exportedTexturesFilename.Values) { File.Delete(path); } if (OnImportProgressChanged != null) OnImportProgressChanged(100); }
public NxContentLoader(Game1 g) { contentBuilder = new ContentBuilder(); contentManager = new ContentManager(g.Services, contentBuilder.OutputDirectory); }