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 UpsertAssetAsync_DynamicallyTyped_UpsertModelIsNull_Throws() { var client = _fileSystemFixture.CreateMockClientWithoutResponse(); await client.Invoking(c => c.UpsertAssetAsync(Reference.ByExternalId("ex"), null)) .Should().ThrowExactlyAsync <ArgumentNullException>(); }
public async Task CreateRenditionAsync_CreateModelIsNull_Throws() { var client = _fileSystemFixture.CreateMockClientWithResponse("AssetRendition.json"); await client.Invoking(x => x.CreateAssetRenditionAsync(Reference.ByExternalId("asset-1"), null)) .Should().ThrowExactlyAsync <ArgumentNullException>(); }
public async Task DeleteAssetAsync_ByExternalId_DeletesAsset() { var client = _fileSystemFixture.CreateMockClientWithoutResponse(); await client.Invoking(c => c.DeleteAssetAsync(Reference.ByExternalId("externalId"))) .Should().NotThrowAsync(); }
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 void BuildListVariantsByComponentUrl_ComponentExternalId_ReturnsCorrectUrl() { var identifier = Reference.ByExternalId("externalId"); var actualUrl = _builder.BuildListVariantsByComponentUrl(identifier); var expectedUrl = $"{ENDPOINT}/projects/{PROJECT_ID}/types/external-id/{identifier.ExternalId}/components"; Assert.Equal(expectedUrl, actualUrl); }
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 BuildItemUrl_ItemExternalId_ReturnsCorrectUrl() { var identifier = Reference.ByExternalId("externalId"); var actualUrl = _builder.BuildItemUrl(identifier); var expectedUrl = $"{ENDPOINT}/projects/{PROJECT_ID}/items/external-id/{identifier.ExternalId}"; Assert.Equal(expectedUrl, actualUrl); }
public async void CreateContentItem() { var client = _fileSystemFixture.CreateMockClientWithResponse("Empty.json"); await client.UpsertContentItemAsync( Reference.ByExternalId("ext-cafe-brno"), new ContentItemUpsertModel { Name = "Brno", Type = Reference.ByExternalId("cafe") }); }
public void BuildAssetsUrlFromExternalId_ByExternalId_ReturnsExpectedUrl() { var externalId = "which-brewing-fits-you"; var expectedResult = $"{ENDPOINT}/projects/{PROJECT_ID}/assets/external-id/{externalId}"; var actualResult = _builder.BuildAssetsUrl(Reference.ByExternalId(externalId)); Assert.Equal(expectedResult, actualResult); }
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 void BuildSnippetsUrl_ByExternalId_ReturnsExpectedUrl() { var identifier = Reference.ByExternalId("external"); var actualUrl = _builder.BuildSnippetsUrl(identifier); var expectedUrl = $"{ENDPOINT}/projects/{PROJECT_ID}/snippets/external-id/{identifier.ExternalId}"; Assert.Equal(expectedUrl, actualUrl); }
public async void DeleteTaxonomyGroup_ByExternalId_DeletesTaxonomyGroup() { var client = _fileSystemFixture.CreateMockClientWithoutResponse(); var identifier = Reference.ByExternalId("externalId"); Func <Task> deleteTaxonomy = async() => await client.DeleteTaxonomyGroupAsync(identifier); await deleteTaxonomy.Should().NotThrowAsync(); }
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 CreateItem() { var client = _fileSystemFixture.CreateMockClientWithResponse("Empty.json"); await client.UpsertContentItemAsync(Reference.ByExternalId("simple-example"), new ContentItemUpsertModel { Name = "Simple example", Type = Reference.ByExternalId("simple-rich-text"), }); }
public async void GetTaxonomyGroup_ByExternalId_GetsTaxonomyGroup() { var client = _fileSystemFixture.CreateMockClientWithResponse("TaxonomyGroup.json"); var expected = _fileSystemFixture.GetExpectedResponse <TaxonomyGroupModel>("TaxonomyGroup.json"); var response = await client.GetTaxonomyGroupAsync(Reference.ByExternalId(expected.ExternalId)); response.Should().BeEquivalentTo(expected); }
public async Task GetAssetAsync_StronglyTyped_ByExternalId_GetsAsset() { var client = _fileSystemFixture.CreateMockClientWithResponse("Asset.json"); var expected = GetExpectedStronglyTypedAssetModel(); var response = await client.GetAssetAsync <ComplexTestModel>(Reference.ByExternalId(expected.ExternalId)); response.Should().BeEquivalentTo(expected); }
public async Task UpsertAssetAsync_DynamicallyTyped_WithFileContent_FileContentIsNull_Throws() { var client = _fileSystemFixture.CreateMockClientWithoutResponse(); var updateModel = new AssetUpsertModel { Title = "xxx" }; await client.Invoking(c => c.UpsertAssetAsync(Reference.ByExternalId("externalId"), null, updateModel)) .Should().ThrowExactlyAsync <ArgumentNullException>(); }
public async Task UpsertAssetAsync_DynamicallyTyped_WithFileContent_UpsertModelIsNull_Throws() { var client = _fileSystemFixture.CreateMockClientWithoutResponse(); var content = new FileContentSource( new MemoryStream(Encoding.UTF8.GetBytes("Hello world from CM API .NET SDK")), "Hello.txt", "text/plain"); await client.Invoking(c => c.UpsertAssetAsync(Reference.ByExternalId("externalId"), content, null)) .Should().ThrowExactlyAsync <ArgumentNullException>(); }
public async void ModifyCollection_Remove_ByExternalId_RemovesCollection() { var client = _fileSystemFixture.CreateMockClientWithoutResponse(); var identifier = Reference.ByExternalId("externalId"); var changes = new[] { new CollectionRemovePatchModel { CollectionIdentifier = identifier } }; Func <Task> deleteCollection = async() => await client.ModifyCollectionAsync(changes); await deleteCollection.Should().NotThrowAsync(); }
public async void UpsertLanguageVariant() { var client = _fileSystemFixture.CreateMockClientWithResponse("Empty.json"); var identifier = new LanguageVariantIdentifier(Reference.ByExternalId("ext-cafe-brno"), Reference.ByCodename("en-US")); var response = await client.UpsertLanguageVariantAsync(identifier, new LanguageVariantUpsertModel { Elements = ElementBuilder.GetElementsAsDynamic(new BaseElement[] { new TextElement { Element = Reference.ByExternalId("street"), Value = "Nove Sady 25", }, new TextElement { Element = Reference.ByExternalId("city"), Value = "Brno", }, new TextElement { Element = Reference.ByExternalId("country"), Value = "Czech republic", }, new TextElement { Element = Reference.ByExternalId("state"), Value = "Jihomoravsky kraj", }, new TextElement { Element = Reference.ByExternalId("zip_code"), Value = "60200", }, new TextElement { Element = Reference.ByExternalId("phone"), Value = "+420 555 555 555", }, new TextElement { Element = Reference.ByExternalId("email"), Value = "*****@*****.**", }, }) }); }
public async void GetLanguage_ByExternalId_GetsLanguage() { var client = _fileSystemFixture.CreateMockClientWithResponse("SingleLanguageResponse.json"); var response = await client.GetLanguageAsync(Reference.ByExternalId("string")); 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 Task UpsertAssetAsync_DynamicallyTyped_ByExternalId_UpsertsAsset() { var client = _fileSystemFixture.CreateMockClientWithResponse("Asset.json"); var expected = GetExpectedDynamicAssetModel(); var updateModel = new AssetUpsertModel { Title = expected.Title, Elements = expected.Elements }; var response = await client.UpsertAssetAsync(Reference.ByExternalId(expected.ExternalId), updateModel); response.Should().BeEquivalentTo(expected); }
public void GetElementsAsDynamic_NoIdentificationProvided_ThrowsException() { Action action = () => ElementBuilder.GetElementsAsDynamic(new BaseElement[] { new TextElement { Element = Reference.ByExternalId(null), Value = "Test" } }); action.Should() .Throw <AggregateException>() .WithInnerException <ArgumentException>(); }
public async void ModifyCollection_Replace_ReplacesCollection() { var client = _fileSystemFixture.CreateMockClientWithResponse("Collections.json"); var identifier = Reference.ByExternalId("second_external_id"); var changes = new[] { new CollectionReplacePatchModel { Reference = identifier, PropertyName = PropertyName.Name, Value = "Second collection" } }; var response = await client.ModifyCollectionAsync(changes); response.Collections.Should().ContainSingle(x => x.Name == "Second collection"); }
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 ModifyCollection_Move_After_MovesCollection() { var client = _fileSystemFixture.CreateMockClientWithResponse("Collections.json"); var expectedItems = _fileSystemFixture.GetExpectedResponse <CollectionsModel>("Collections.json"); var identifier = Reference.ByExternalId("second_external_id"); var changes = new[] { new CollectionMovePatchModel { Reference = identifier, After = Reference.ById(Guid.Empty) } }; var response = await client.ModifyCollectionAsync(changes); response.Should().BeEquivalentTo(expectedItems, options => options.WithStrictOrderingFor(x => x.Collections)); }
public async void UseAsset() { var client = _fileSystemFixture.CreateMockClientWithResponse("Empty.json"); var identifier = new LanguageVariantIdentifier(Reference.ByExternalId("ext-cafe-brno"), Reference.ByCodename("en-US")); var response = await client.UpsertLanguageVariantAsync(identifier, new LanguageVariantUpsertModel { Elements = ElementBuilder.GetElementsAsDynamic(new BaseElement[] { new AssetElement { Element = Reference.ByCodename("photo"), Value = new[] { new AssetWithRenditionsReference(Reference.ByExternalId("brno-cafe-image")) } } }) }); }
public async void UpsertVariant() { var client = _fileSystemFixture.CreateMockClientWithResponse("Empty.json"); var identifier = new LanguageVariantIdentifier(Reference.ByExternalId("123"), Reference.ByCodename("en-US")); await client.UpsertLanguageVariantAsync(identifier, new LanguageVariantUpsertModel { Elements = ElementBuilder.GetElementsAsDynamic(new BaseElement[] { new RichTextElement { Element = Reference.ByExternalId("rich-text"), Value = "<h1>Lorem Ipsum</h1>\n<p>Lorem ipsum dolor sit amet, consectetur <a href=\"https://wikipedia.org\">adipiscing elit</a>, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>\n<object type=\"application/kenticocloud\" data-type=\"component\" data-id=\"a2ee7bac-15ff-4dce-a244-012b9f98dd7b\"></object>\n<p>Ut enim ad minim veniam, <a data-item-external-id=\"second-page\">quis nostrud</a> exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>\n<ul>\n <li>Lorem ipsum dolor sit amet</li>\n <li>Consectetur adipiscing elit</li>\n <li>Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</li>\n</ul><figure data-asset-external-id=\"rich-text-asset\"></figure>", Components = new ComponentModel[] { new ComponentModel { Id = Guid.Parse("a2ee7bac-15ff-4dce-a244-012b9f98dd7b"), Type = Reference.ByExternalId("button"), Elements = ElementBuilder.GetElementsAsDynamic(new BaseElement[] { new TextElement { Element = Reference.ByExternalId("button-text"), Value = "Buy me", }, new TextElement { Element = Reference.ByExternalId("button-link"), Value = "https://kontent.a", } }) } } }, }), }); }
public void ReferenceCreation() { var codenameIdentifier = Reference.ByCodename("on_roasts"); var idIdentifier = Reference.ById(Guid.Parse("9539c671-d578-4fd3-aa5c-b2d8e486c9b8")); var externalIdIdentifier = Reference.ByExternalId("Ext-Item-456-Brno"); }