public async void ModifyTaxonomyGroup_Replace_ModifiesTaxonomyGroup() { var client = _fileSystemFixture.CreateMockClientWithResponse("TaxonomyGroup.json"); var taxonomy = _fileSystemFixture.GetExpectedResponse <TaxonomyGroupModel>("TaxonomyGroup.json"); var newTerm = new TaxonomyTermCreateModel { Name = "Espro", Codename = "espro", ExternalId = "b378225f-6dfc-e261-3848-dd030a6d7883", Terms = Array.Empty <TaxonomyTermCreateModel>() }; var changes = new TaxonomyGroupReplacePatchModel { PropertyName = PropertyName.Terms, Reference = Reference.ByCodename("old"), Value = new List <TaxonomyTermCreateModel> { newTerm } }; var response = await client.ModifyTaxonomyGroupAsync(Reference.ByCodename(taxonomy.Codename), new List <TaxonomyGroupReplacePatchModel> { changes }); response.Terms.Should().ContainEquivalentOf(newTerm); }
public async void CreateAsset() { var client = _fileSystemFixture.CreateMockClientWithResponse("Empty.json"); // Uses the file reference object obtained in step 1 var createdAssetResponse = await client.UpsertAssetAsync(Reference.ByExternalId("which-brewing-fits-you"), new AssetUpsertModel { // 'fileReference' is only required when creating a new asset // To create a file reference, see the "Upload a binary file" endpoint FileReference = new FileReference { Id = "8660e19c-7bbd-48a3-bb51-721934c7756c", Type = FileReferenceTypeEnum.Internal }, Title = "Brno Cafe", Descriptions = new AssetDescription[] { new AssetDescription { Description = "Cafe in Brno", Language = Reference.ByCodename("en-US") }, new AssetDescription { Description = "Café en Brno", Language = Reference.ByCodename("es-ES") } } }); }
public async Task GetAssetAsync_StronglyTyped_ByCodename_Throws() { var client = _fileSystemFixture.CreateMockClientWithoutResponse(); await client.Invoking(c => c.GetAssetAsync <ComplexTestModel>(Reference.ByCodename("codename"))) .Should().ThrowExactlyAsync <InvalidOperationException>(); }
public async void UpsertLanguageVariantWithElementBuilder() { // Remove next line in codesample var client = _fileSystemFixture.CreateMockClientWithResponse("ArticleLanguageVariantUpdatedResponse.json"); var itemIdentifier = Reference.ById(Guid.Parse("9539c671-d578-4fd3-aa5c-b2d8e486c9b8")); var languageIdentifier = Reference.ByCodename("en-US"); var identifier = new LanguageVariantIdentifier(itemIdentifier, languageIdentifier); // Elements to update var elements = ElementBuilder.GetElementsAsDynamic(new BaseElement[] { new TextElement() { // You can use `Reference.ById` if you don't have the model Element = Reference.ById(typeof(ArticleModel).GetProperty(nameof(ArticleModel.Title)).GetKontentElementId()), Value = "On Roasts - changed" }, new DateTimeElement() { // You can use `Reference.ById` if you don't have the model Element = Reference.ById(typeof(ArticleModel).GetProperty(nameof(ArticleModel.PostDate)).GetKontentElementId()), Value = new DateTime(2018, 7, 4) }, }); var upsertModel = new LanguageVariantUpsertModel() { Elements = elements }; // Upserts a language variant of a content item var response = await client.UpsertLanguageVariantAsync(identifier, upsertModel); }
public async void ModifyLanguages_Replace_ModifiesLanguages() { var client = _fileSystemFixture.CreateMockClientWithResponse("ModifyLanguages_Replace_ModifiesLanguages.json"); var patchModel = new[] { new LanguagePatchModel { PropertyName = LanguagePropertyName.FallbackLanguage, Value = new { Codename = "en-US" } }, new LanguagePatchModel { PropertyName = LanguagePropertyName.Name, Value = "Deutsch" } }; var modifiedLanguage = await client.ModifyLanguageAsync(Reference.ByCodename("de-DE"), patchModel); using (new AssertionScope()) { modifiedLanguage.Name.Should().BeEquivalentTo("Deutsch"); modifiedLanguage.FallbackLanguage.Id.Should().Equals(Guid.Parse("00000000-0000-0000-0000-000000000000")); } }
public async void UsertVariant() { var client = _fileSystemFixture.CreateMockClientWithResponse("Empty.json"); var identifier = new LanguageVariantIdentifier(Reference.ByExternalId("123"), Reference.ByCodename("en-US")); var response = await client.UpsertLanguageVariantAsync(identifier, new LanguageVariantUpsertModel { Elements = ElementBuilder.GetElementsAsDynamic(new BaseElement[] { new TextElement { Element = Reference.ByCodename("title"), Value = "On Roasts" }, new LinkedItemsElement { Element = Reference.ByCodename("related_articles"), Value = new [] { Reference.ByExternalId("456"), } } }) }); }
public async Task DeleteAssetAsync_ByCodename_DeletesAsset() { var client = _fileSystemFixture.CreateMockClientWithoutResponse(); await client.Invoking(c => c.DeleteAssetAsync(Reference.ByCodename("c"))) .Should().ThrowExactlyAsync <InvalidOperationException>(); }
public async void UpdateAssetWithElementBuilder() { // Remove next line in codesample var client = _fileSystemFixture.CreateMockClientWithResponse("AssetResponse.json"); // Elements to update var taxonomyElements = ElementBuilder.GetElementsAsDynamic( new TaxonomyElement { Element = Reference.ByCodename("taxonomy-categories"), Value = new[] { Reference.ByCodename("hello"), Reference.ByCodename("SDK"), } }); // Defines the asset to update var asset = new AssetUpsertModel { Elements = taxonomyElements }; var assetReference = Reference.ById(Guid.Parse("6d1c8ee9-76bc-474f-b09f-8a54a98f06ea")); // Updates asset metadata var response = await client.UpsertAssetAsync(assetReference, asset); }
public async void QuickStartAddLanguageVariant() { // Remove next line in codesample var client = _fileSystemFixture.CreateMockClientWithResponse("ArticleLanguageVariantResponse.json"); var componentId = "04bc8d32-97ab-431a-abaa-83102fc4c198"; var contentTypeCodename = "article"; var relatedArticle1Guid = Guid.Parse("b4e7bfaa-593c-4ae4-a231-5136b10757b8"); var relatedArticle2Guid = Guid.Parse("6d1c8ee9-76bc-474f-b09f-8a54a98f06ea"); var taxonomyTermGuid1 = Guid.Parse("5c060bf3-ed38-4c77-acfa-9868e6e2b5dd"); var taxonomyTermGuid2 = Guid.Parse("5c060bf3-ed38-4c77-acfa-9868e6e2b5dd"); // Defines the content elements to update var stronglyTypedElements = new ArticleModel { Title = new TextElement() { Value = "On Roasts" }, PostDate = new DateTimeElement() { Value = new DateTime(2017, 7, 4) }, BodyCopy = new RichTextElement { Value = $"<p>Rich Text</p><object type=\"application/kenticocloud\" data-type=\"component\" data-id=\"{componentId}\"></object>", Components = new ComponentModel[] { new ComponentModel { Id = Guid.Parse(componentId), Type = Reference.ByCodename(contentTypeCodename), Elements = new dynamic[] { new { element = new { id = typeof(ArticleModel).GetProperty(nameof(ArticleModel.Title)).GetKontentElementId() }, value = "Article component title", } } } } }, RelatedArticles = new LinkedItemsElement { Value = new[] { relatedArticle1Guid, relatedArticle2Guid }.Select(Reference.ById) }, Personas = new TaxonomyElement { Value = new[] { taxonomyTermGuid1, taxonomyTermGuid2 }.Select(Reference.ById) }, UrlPattern = new UrlSlugElement { Value = "on-roasts", Mode = "custom" }, }; // Specifies the content item and the language variant var itemIdentifier = Reference.ByCodename("on_roasts"); var languageIdentifier = Reference.ByCodename("en-US"); var identifier = new LanguageVariantIdentifier(itemIdentifier, languageIdentifier); // Upserts a language variant of your content item var response = await client.UpsertLanguageVariantAsync<ArticleModel>(identifier, stronglyTypedElements); }
public async void CreateSecondItem() { var client = _fileSystemFixture.CreateMockClientWithResponse("Empty.json"); await client.UpsertContentItemAsync( Reference.ByExternalId("456"), new ContentItemUpsertModel { Name = "Donate with us", Type = Reference.ByCodename("article") }); }
public void BuildProjectRoleUrl_WithCodename_ReturnsCorrectUrl() { var roleIdentifier = Reference.ByCodename("codename"); var actualUrl = _builder.BuildProjectRoleUrl(roleIdentifier); var expectedUrl = $"{ENDPOINT}/projects/{PROJECT_ID}/roles/codename/{roleIdentifier.Codename}"; Assert.Equal(expectedUrl, actualUrl); }
public async void ModifyContentTypeSnippetAsync_NoChanges_Throws() { var client = _fileSystemFixture.CreateMockClientWithoutResponse(); await client.Invoking(x => x.ModifyContentTypeSnippetAsync(Reference.ByCodename("tweet"), new List <ContentTypeSnippetOperationBaseModel> { })) .Should().ThrowAsync <ArgumentException>(); }
public void BuildListVariantsByComponentUrl_ComponentCodename_ReturnsCorrectUrl() { var identifier = Reference.ByCodename("codename"); var actualUrl = _builder.BuildListVariantsByComponentUrl(identifier); var expectedUrl = $"{ENDPOINT}/projects/{PROJECT_ID}/types/codename/{identifier.Codename}/components"; Assert.Equal(expectedUrl, actualUrl); }
public void BuildItemUrl_ItemCodename_ReturnsCorrectUrl() { var identifier = Reference.ByCodename("codename"); var actualUrl = _builder.BuildItemUrl(identifier); var expectedUrl = $"{ENDPOINT}/projects/{PROJECT_ID}/items/codename/{identifier.Codename}"; Assert.Equal(expectedUrl, actualUrl); }
public async void CreateType() { var client = _fileSystemFixture.CreateMockClientWithResponse("Empty.json"); var response = await client.CreateContentTypeAsync(new ContentTypeCreateModel { Name = "Blogpost", Codename = "blogpost", ContentGroups = new[] { new ContentGroupModel { Name = "Content", ExternalId = "content", }, new ContentGroupModel { Name = "Metadata", ExternalId = "metadata", }, new ContentGroupModel { Name = "Topic", ExternalId = "topic", } }, Elements = new ElementMetadataBase[] { new TextElementMetadataModel { Name = "Title", ContentGroup = Reference.ByExternalId("content") }, new AssetElementMetadataModel { Name = "Image", ContentGroup = Reference.ByExternalId("content") }, new RichTextElementMetadataModel { Name = "Blog content", ContentGroup = Reference.ByExternalId("content") }, new ContentTypeSnippetElementMetadataModel { SnippetIdentifier = Reference.ByCodename("metadata"), Codename = "metadata", ContentGroup = Reference.ByExternalId("metadata") }, new TaxonomyElementMetadataModel { TaxonomyGroup = Reference.ByExternalId("blog_topic"), Codename = "taxonomy", ContentGroup = Reference.ByExternalId("topic") } } }); }
public async Task GetProjectRole_ByCodename_GetsProjectRole() { var client = _fileSystemFixture.CreateMockClientWithResponse("ProjectRole.json"); var expected = _fileSystemFixture.GetExpectedResponse <ProjectRoleModel>("ProjectRole.json"); var response = await client.GetProjectRoleAsync(Reference.ByCodename(expected.Codename)); response.Should().BeEquivalentTo(expected); }
public void BuildWorkflowsUrl_ByCodename_ReturnsExpectedUrl() { var codename = "codename"; var actualUrl = _builder.BuildWorkflowsUrl(Reference.ByCodename(codename)); var expectedUrl = $"{ENDPOINT}/projects/{PROJECT_ID}/workflows/codename/{codename}"; Assert.Equal(expectedUrl, actualUrl); }
public void BuildVariantsUrl_ItemCodenameLanguageId_ReturnsCorrectUrl() { var itemIdentifier = Reference.ByCodename("codename"); var languageIdentifier = Reference.ById(Guid.NewGuid()); var identifier = new LanguageVariantIdentifier(itemIdentifier, languageIdentifier); var actualUrl = _builder.BuildVariantsUrl(identifier); var expectedUrl = $"{ENDPOINT}/projects/{PROJECT_ID}/items/codename/{itemIdentifier.Codename}/variants/{languageIdentifier.Id}"; Assert.Equal(expectedUrl, actualUrl); }
public void BuildVariantsUrl_ItemExternalIdLanguageCodename_ReturnsCorrectUrl() { var itemIdentifier = Reference.ByExternalId("externalId"); var languageIdentifier = Reference.ByCodename("codename"); var identifier = new LanguageVariantIdentifier(itemIdentifier, languageIdentifier); var actualUrl = _builder.BuildVariantsUrl(identifier); var expectedUrl = $"{ENDPOINT}/projects/{PROJECT_ID}/items/external-id/{itemIdentifier.ExternalId}/variants/codename/{languageIdentifier.Codename}"; Assert.Equal(expectedUrl, actualUrl); }
public async void DeleteTaxonomyGroup_ByCodename_DeletesTaxonomyGroup() { var client = _fileSystemFixture.CreateMockClientWithoutResponse(); var identifier = Reference.ByCodename("codename"); Func <Task> deleteTaxonomy = async() => await client.DeleteTaxonomyGroupAsync(identifier); await deleteTaxonomy.Should().NotThrowAsync(); }
public async void GetTaxonomyGroup_ByCodename_GetsTaxonomyGroup() { var client = _fileSystemFixture.CreateMockClientWithResponse("TaxonomyGroup.json"); var expected = _fileSystemFixture.GetExpectedResponse <TaxonomyGroupModel>("TaxonomyGroup.json"); var response = await client.GetTaxonomyGroupAsync(Reference.ByCodename(expected.Codename)); response.Should().BeEquivalentTo(expected); }
public async void GetContentTypeAsync_GetsContentTypeAsync() { var client = _fileSystemFixture.CreateMockClientWithResponse("ContentType.json"); var expected = _fileSystemFixture.GetExpectedResponse <ContentTypeModel>("ContentType.json"); var response = await client.GetContentTypeAsync(Reference.ByCodename("codename")); response.Should().BeEquivalentTo(expected); }
public async Task GetContentTypeSnippetAsync_GetsContentTypeSnippetAsync() { var client = _fileSystemFixture.CreateMockClientWithResponse("Snippet.json"); var expected = _fileSystemFixture.GetExpectedResponse <ContentTypeSnippetModel>("Snippet.json"); var response = await client.GetContentTypeSnippetAsync(Reference.ByCodename("metadata")); response.Should().BeEquivalentTo(expected); }
public async Task UpsertAssetAsync_DynamicallyTyped_ByCodename_UpsertsAsset() { var client = _fileSystemFixture.CreateMockClientWithoutResponse(); var updateModel = new AssetUpsertModel { Title = "xxx" }; await client.Invoking(c => c.UpsertAssetAsync(Reference.ByCodename("c"), updateModel)) .Should().ThrowExactlyAsync <InvalidOperationException>(); }
public async void QuickStartCreateContentItem() { // Remove next line in codesample var client = _fileSystemFixture.CreateMockClientWithResponse("ArticleContentItemResponse.json"); var item = new ContentItemCreateModel { Codename = "on_roasts", Name = "On Roasts", Type = Reference.ByCodename("article") }; var responseItem = await client.CreateContentItemAsync(item); }
public async void ModifyCollection_Remove_ByCodename_RemovesCollection() { var client = _fileSystemFixture.CreateMockClientWithoutResponse(); var identifier = Reference.ByCodename("codename"); var changes = new[] { new CollectionRemovePatchModel { CollectionIdentifier = identifier } }; Func <Task> deleteCollection = async() => await client.ModifyCollectionAsync(changes); await deleteCollection.Should().NotThrowAsync(); }
public async void GetLanguage_ByCodename_GetsLanguage() { var client = _fileSystemFixture.CreateMockClientWithResponse("SingleLanguageResponse.json"); var response = await client.GetLanguageAsync(Reference.ByCodename("default")); using (new AssertionScope()) { response.Name.Should().BeEquivalentTo("Default project language"); response.Codename.Should().BeEquivalentTo("default"); response.ExternalId.Should().BeEquivalentTo("string"); response.FallbackLanguage.Id.Should().Equals(Guid.Parse("00000000-0000-0000-0000-000000000000")); response.IsActive.Should().BeTrue(); response.IsDefault.Should().BeTrue(); } }
public async void ModifyTaxonomyGroup_Remove_ModifiesTaxonomyGroup() { var client = _fileSystemFixture.CreateMockClientWithResponse("TaxonomyGroup.json"); var taxonomy = _fileSystemFixture.GetExpectedResponse <TaxonomyGroupModel>("TaxonomyGroup.json"); var changes = new TaxonomyGroupRemovePatchModel { Reference = Reference.ByCodename("toBeRemoved"), }; var response = await client.ModifyTaxonomyGroupAsync(Reference.ByCodename(taxonomy.Codename), new List <TaxonomyGroupRemovePatchModel> { changes }); response.Terms.Should().NotContain(term => term.Codename == "toBeRemoved"); }
public async void UseAssetRichText() { var client = _fileSystemFixture.CreateMockClientWithResponse("Empty.json"); var identifier = new LanguageVariantIdentifier(Reference.ByExternalId("new-cafes"), Reference.ByCodename("en-US")); var response = await client.UpsertLanguageVariantAsync(identifier, new LanguageVariantUpsertModel { Elements = ElementBuilder.GetElementsAsDynamic(new BaseElement[] { new RichTextElement { Element = Reference.ByCodename("body_copy"), Value = "<p>...</p> <figure data-asset-external-id=\"brno-cafe-image\"></figure>", } }) }); }
public async void RetrieveAndUpsertStronglyTypedModel() { // Remove next line in codesample var client = _fileSystemFixture.CreateMockClientWithResponse("ArticleLanguageVariantResponse.json"); var itemIdentifier = Reference.ById(Guid.Parse("9539c671-d578-4fd3-aa5c-b2d8e486c9b8")); var languageIdentifier = Reference.ByCodename("en-US"); var identifier = new LanguageVariantIdentifier(itemIdentifier, languageIdentifier); var response = await client.GetLanguageVariantAsync<ArticleModel>(identifier); response.Elements.Title = new TextElement() { Value = "On Roasts - changed" }; response.Elements.PostDate = new DateTimeElement() { Value = new DateTime(2018, 7, 4) }; // Remove next line in codesample client = _fileSystemFixture.CreateMockClientWithResponse("ArticleLanguageVariantUpdatedResponse.json"); var responseVariant = await client.UpsertLanguageVariantAsync(identifier, response.Elements); }