public async Task ActionInvokerSerializeEnum_EnumIsSerializedAsString() { var httpClient = new FakeManagementHttpClient(); var actionInvoker = new _ActionInvoker(httpClient, new MessageCreator("{api_key}")); var assetUpsertModel = new AssetUpsertModel() { Title = "Asset", Descriptions = new[] { new AssetDescription() { Description = "Description", Language = Reference.ById(Guid.Empty) }, }, FileReference = new FileReference() { Id = "ab7bdf75-781b-4bf9-aed8-501048860402", Type = FileReferenceTypeEnum.Internal } }; await actionInvoker.InvokeMethodAsync <AssetUpsertModel, dynamic>("{endpoint_url}", HttpMethod.Put, assetUpsertModel); Assert.Contains("\"type\":\"internal\"", httpClient._requestBody); }
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 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 DisableWebhook_ById_DisablesWebhook() { var client = _fileSystemFixture.CreateMockClientWithoutResponse(); Func <Task> disableWebhook = async() => await client.DisableWebhookAsync(Reference.ById(Guid.NewGuid())); await disableWebhook.Should().NotThrowAsync(); }
public void BuildListVariantsByComponentUrl_ComponentId_ReturnsCorrectUrl() { var identifier = Reference.ById(Guid.NewGuid()); var actualUrl = _builder.BuildListVariantsByComponentUrl(identifier); var expectedUrl = $"{ENDPOINT}/projects/{PROJECT_ID}/types/{identifier.Id}/components"; Assert.Equal(expectedUrl, actualUrl); }
public void BuildProjectRoleUrl_WithId_ReturnsCorrectUrl() { var roleIdentifier = Reference.ById(Guid.NewGuid()); var actualUrl = _builder.BuildProjectRoleUrl(roleIdentifier); var expectedUrl = $"{ENDPOINT}/projects/{PROJECT_ID}/roles/{roleIdentifier.Id}"; Assert.Equal(expectedUrl, actualUrl); }
public async Task DeleteAssetAsync_ById_DeletesAsset() { var client = _fileSystemFixture.CreateMockClientWithoutResponse(); await client.Invoking(c => c.DeleteAssetAsync(Reference.ById(Guid.Empty))) .Should().NotThrowAsync(); }
public void BuildItemUrl_ItemId_ReturnsCorrectUrl() { var identifier = Reference.ById(Guid.NewGuid()); var actualUrl = _builder.BuildItemUrl(identifier); var expectedUrl = $"{ENDPOINT}/projects/{PROJECT_ID}/items/{identifier.Id}"; Assert.Equal(expectedUrl, actualUrl); }
public void BuildAssetsUrlFromId_ById_ReturnsExpectedUrl() { var assetId = Guid.NewGuid(); var expectedResult = $"{ENDPOINT}/projects/{PROJECT_ID}/assets/{assetId}"; var actualResult = _builder.BuildAssetsUrl(Reference.ById(assetId)); Assert.Equal(expectedResult, actualResult); }
public async void GetTaxonomyGroup_ById_GetsTaxonomyGroup() { var client = _fileSystemFixture.CreateMockClientWithResponse("TaxonomyGroup.json"); var expected = _fileSystemFixture.GetExpectedResponse <TaxonomyGroupModel>("TaxonomyGroup.json"); var response = await client.GetTaxonomyGroupAsync(Reference.ById(expected.Id)); response.Should().BeEquivalentTo(expected); }
public void BuildVariantsUrl_ItemExternalIdLanguageId_ReturnsCorrectUrl() { var itemIdentifier = Reference.ByExternalId("externalId"); var languageIdentifier = Reference.ById(Guid.NewGuid()); var identifier = new LanguageVariantIdentifier(itemIdentifier, languageIdentifier); var actualUrl = _builder.BuildVariantsUrl(identifier); var expectedUrl = $"{ENDPOINT}/projects/{PROJECT_ID}/items/external-id/{itemIdentifier.ExternalId}/variants/{languageIdentifier.Id}"; Assert.Equal(expectedUrl, actualUrl); }
public void BuildWorkflowsUrl_ById_ReturnsExpectedUrl() { var internalId = Guid.NewGuid(); var actualUrl = _builder.BuildWorkflowsUrl(Reference.ById(internalId)); var expectedUrl = $"{ENDPOINT}/projects/{PROJECT_ID}/workflows/{internalId}"; Assert.Equal(expectedUrl, actualUrl); }
public async Task GetProjectRole_ById_GetsProjectRole() { var client = _fileSystemFixture.CreateMockClientWithResponse("ProjectRole.json"); var expected = _fileSystemFixture.GetExpectedResponse <ProjectRoleModel>("ProjectRole.json"); var response = await client.GetProjectRoleAsync(Reference.ById(expected.Id)); response.Should().BeEquivalentTo(expected); }
public async void DeleteTaxonomyGroup_ById_DeletesTaxonomyGroup() { var client = _fileSystemFixture.CreateMockClientWithoutResponse(); var identifier = Reference.ById(Guid.NewGuid()); Func <Task> deleteTaxonomy = async() => await client.DeleteTaxonomyGroupAsync(identifier); await deleteTaxonomy.Should().NotThrowAsync(); }
public async void GetWebhook_ById_GetsWebhook() { var client = _fileSystemFixture.CreateMockClientWithResponse("Webhook.json"); var webhook = _fileSystemFixture.GetExpectedResponse <WebhookModel>("Webhook.json"); var response = await client.GetWebhookAsync(Reference.ById(webhook.Id)); response.Should().BeEquivalentTo(webhook); }
public async Task GetAssetAsync_StronglyTyped_ById_GetsAsset() { var client = _fileSystemFixture.CreateMockClientWithResponse("Asset.json"); var expected = GetExpectedStronglyTypedAssetModel(); var response = await client.GetAssetAsync <ComplexTestModel>(Reference.ById(expected.Id)); response.Should().BeEquivalentTo(expected); }
public async Task ListLanguageVariantsByItemAsync_DynamicallyTyped_ListsVariants() { var client = _fileSystemFixture.CreateMockClientWithResponse("LanguageVariants.json"); var expected = new[] { "00000000-0000-0000-0000-000000000000", "10000000-0000-0000-0000-000000000000" } .Select(x => GetExpectedLanguageVariantModel(languageId: x)); var identifier = Reference.ById(Guid.Parse("4b628214-e4fe-4fe0-b1ff-955df33e1515")); var response = await client.ListLanguageVariantsByItemAsync(identifier); response.Should().BeEquivalentTo(expected); }
public async void ModifyCollection_Remove_ById_RemovesCollection() { var client = _fileSystemFixture.CreateMockClientWithoutResponse(); var identifier = Reference.ById(Guid.NewGuid()); var changes = new[] { new CollectionRemovePatchModel { CollectionIdentifier = identifier } }; Func <Task> deleteCollection = async() => await client.ModifyCollectionAsync(changes); await deleteCollection.Should().NotThrowAsync(); }
public IEnumerable <dynamic> GetDynamicElements <T>(T stronglyTypedElements) { var type = typeof(T); var elements = type.GetProperties() .Where(x => (x.GetMethod?.IsPublic ?? false) && x.PropertyType?.BaseType == typeof(BaseElement) && x.GetValue(stronglyTypedElements) != null) .Select(x => { var element = (BaseElement)x.GetValue(stronglyTypedElements); element.Element = Reference.ById(x.GetKontentElementId()); return(element?.ToDynamic()); }); return(elements); }
public async void GetLanguage_ById_GetsLanguage() { var client = _fileSystemFixture.CreateMockClientWithResponse("SingleLanguageResponse.json"); var response = await client.GetLanguageAsync(Reference.ById(Guid.Parse("00000000-0000-0000-0000-000000000000"))); 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_ById_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.ById(expected.Id), updateModel); response.Should().BeEquivalentTo(expected); }
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); }
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 ModifyCollection_AddInto_MovesCollection() { var client = _fileSystemFixture.CreateMockClientWithResponse("Collections.json"); var expected = new CollectionCreateModel { Codename = "second_collection", ExternalId = "second_external_id", Name = "Second collection" }; var change = new CollectionAddIntoPatchModel { Value = expected, After = Reference.ById(Guid.Empty) }; var response = await client.ModifyCollectionAsync(new[] { change }); response.Collections.Should().ContainEquivalentOf(expected); }
public void GetElementsAsDynamic_IdIdentification_ReturnCorrectResult() { var id = Guid.Parse("ebc7f389-8ad3-4366-b2ca-e452c3f2a807"); var elementValue = "Test"; var elements = ElementBuilder.GetElementsAsDynamic(new BaseElement[] { new TextElement { Element = Reference.ById(id), Value = elementValue } }); using (new AssertionScope()) { elements.Should().HaveCount(1); ((object)elements.First()?.element?.id).Should().Be(id); ((object)elements.First()?.value).Should().Be(elementValue); } }
public async Task UpsertAssetAsync_DynamicallyTyped_WithFileContent_UpsertsAsset() { var client = _fileSystemFixture.CreateMockClientWithResponse("File.json", "Asset.json"); var expected = GetExpectedDynamicAssetModel(); var stream = new MemoryStream(Encoding.UTF8.GetBytes("Hello world from CM API .NET SDK")); var fileName = "Hello.txt"; var contentType = "text/plain"; var updateModel = new AssetUpsertModel { Title = expected.Title, Elements = expected.Elements }; var content = new FileContentSource(stream, fileName, contentType); var response = await client.UpsertAssetAsync(Reference.ById(expected.Id), content, updateModel); response.Should().BeEquivalentTo(expected); }
public async void CreateLanguage_CreatesLanguage() { var client = _fileSystemFixture.CreateMockClientWithResponse("CreateLanguage_CreatesLanguage.json"); var newLanguage = new LanguageCreateModel { Name = "German (Germany)", Codename = "de-DE", IsActive = false, ExternalId = "standard-german", FallbackLanguage = Reference.ById(Guid.Parse("00000000-0000-0000-0000-000000000000")) }; var response = await client.CreateLanguageAsync(newLanguage); using (new AssertionScope()) { response.Name.Should().BeEquivalentTo(newLanguage.Name); response.Codename.Should().BeEquivalentTo(newLanguage.Codename); response.ExternalId.Should().BeEquivalentTo(newLanguage.ExternalId); response.FallbackLanguage.Id.Should().Equals(newLanguage.FallbackLanguage.Id); } }
public void BuildAssetRenditionsUrlFromAssetIdAndRenditionCodename_RenditionDoesNotSupportCodename_Throws() { _builder.Invoking(x => x.BuildAssetRenditionsUrl(new AssetRenditionIdentifier(Reference.ById(Guid.NewGuid()), Reference.ByCodename("not-supported")))) .Should().ThrowExactly <InvalidOperationException>(); }
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"); }
private static ComplexTestModel GetTestModel() { var componentId = Guid.NewGuid(); var contentTypeId = Guid.NewGuid(); return(new ComplexTestModel { Title = new TextElement { Value = "text" }, Rating = new NumberElement { Value = 3.14m }, SelectedForm = new CustomElement { Value = "{\"formId\": 42}", SearchableValue = "Almighty form!", }, PostDate = new DateTimeElement() { Value = new DateTime(2017, 7, 4) }, UrlPattern = new UrlSlugElement { Value = "urlslug", Mode = "custom" }, 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 = componentId, Type = Reference.ById(contentTypeId), Elements = new BaseElement[] { new TextElement { Value = "text" } } } } }, TeaserImage = new AssetElement { Value = new[] { new AssetWithRenditionsReference(Reference.ById(Guid.NewGuid()), new[] { Reference.ById(Guid.NewGuid()) }), new AssetWithRenditionsReference(Reference.ById(Guid.NewGuid()), new[] { Reference.ById(Guid.NewGuid()), Reference.ById(Guid.NewGuid()), }), new AssetWithRenditionsReference(Reference.ById(Guid.NewGuid()), Array.Empty <Reference>()), } }, RelatedArticles = new LinkedItemsElement { Value = new[] { Guid.NewGuid(), Guid.NewGuid() }.Select(Reference.ById).ToArray() }, Personas = new TaxonomyElement { Value = new[] { Guid.NewGuid(), Guid.NewGuid() }.Select(Reference.ById).ToList() }, Options = new MultipleChoiceElement { Value = new[] { Guid.NewGuid(), Guid.NewGuid() }.Select(Reference.ById).ToList() }, }); }