Skip to content

Commit

Permalink
Remove assetIdentifier
Browse files Browse the repository at this point in the history
  • Loading branch information
gormal committed Sep 30, 2021
1 parent ac62e4f commit 007e806
Show file tree
Hide file tree
Showing 21 changed files with 134 additions and 194 deletions.
4 changes: 2 additions & 2 deletions Kentico.Kontent.Management.Tests/EndpointUrlBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void BuildAssetsUrlFromId_WithGivenAssetId_ReturnsExpectedUrl()
{
var assetId = Guid.NewGuid();
var expectedResult = $"https://manage.kontent.ai/v2/projects/{PROJECT_ID}/assets/{assetId}";
var actualResult = _builder.BuildAssetsUrl(AssetIdentifier.ById(assetId));
var actualResult = _builder.BuildAssetsUrl(Reference.ById(assetId));

Assert.Equal(expectedResult, actualResult);
}
Expand All @@ -200,7 +200,7 @@ public void BuildAssetsUrlFromExternalId_WithGivenAssetId_ReturnsExpectedUrl()
{
var externalId = "which-brewing-fits-you";
var expectedResult = $"https://manage.kontent.ai/v2/projects/{PROJECT_ID}/assets/external-id/{externalId}";
var actualResult = _builder.BuildAssetsUrl(AssetIdentifier.ByExternalId(externalId));
var actualResult = _builder.BuildAssetsUrl(Reference.ByExternalId(externalId));

Assert.Equal(expectedResult, actualResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public async Task CreateAsset_WithStream_Uploads_CreatesAsset()
Assert.NotNull(assetResult.Url);

// Cleanup
await _client.DeleteAssetAsync(AssetIdentifier.ById(assetResult.Id));
await _client.DeleteAssetAsync(Reference.ById(assetResult.Id));
}

[Fact]
Expand Down Expand Up @@ -234,7 +234,7 @@ public async Task UpsertAssetByExternalId_WithByteArray_Uploads_CreatesAsset()
Assert.NotNull(assetResult.Url);

// Cleanup
await _client.DeleteAssetAsync(AssetIdentifier.ByExternalId(externalId));
await _client.DeleteAssetAsync(Reference.ByExternalId(externalId));
}

[Fact]
Expand Down Expand Up @@ -266,7 +266,7 @@ public async Task CreateAsset_WithFile_Uploads_CreatesAsset()
Assert.NotNull(assetResult.Url);

// Cleanup
await _client.DeleteAssetAsync(AssetIdentifier.ById(assetResult.Id));
await _client.DeleteAssetAsync(Reference.ById(assetResult.Id));
}

[Fact]
Expand All @@ -293,7 +293,7 @@ public async Task CreateAsset_FromFileSystem_Uploads_CreatesAsset()
Assert.NotNull(assetResult.Url);

// Cleanup
await _client.DeleteAssetAsync(AssetIdentifier.ById(assetResult.Id));
await _client.DeleteAssetAsync(Reference.ById(assetResult.Id));
}

[Fact]
Expand Down Expand Up @@ -327,15 +327,15 @@ public async Task UpsertAssetByExternalId_FromByteArray_Uploads_CreatesAsset()
Assert.NotNull(assetResult.Url);

// Cleanup
await _client.DeleteAssetAsync(AssetIdentifier.ByExternalId(externalId));
await _client.DeleteAssetAsync(Reference.ByExternalId(externalId));
}

[Fact]
public async Task UpdateAssetById_ReturnsUpdatedAsset()
{


var identifier = AssetIdentifier.ById(Guid.Parse("01647205-c8c4-4b41-b524-1a98a7b12750"));
var identifier = Reference.ById(Guid.Parse("01647205-c8c4-4b41-b524-1a98a7b12750"));
var title = "My super asset";
var updatedDescription = new AssetDescription()
{
Expand All @@ -356,7 +356,7 @@ public async Task GetAsset_WhenGivenAssetId_ReturnsGivenAsset()
{


var identifier = AssetIdentifier.ById(Guid.Parse("01647205-c8c4-4b41-b524-1a98a7b12750"));
var identifier = Reference.ById(Guid.Parse("01647205-c8c4-4b41-b524-1a98a7b12750"));

var response = await _client.GetAssetAsync(identifier);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Kentico.Kontent.Management.Models.Assets;
using Kentico.Kontent.Management.Models.LanguageVariants;
using Kentico.Kontent.Management.Models.LanguageVariants.Elements;
using Kentico.Kontent.Management.Models.Shared;
Expand Down Expand Up @@ -202,7 +201,7 @@ private ManagementClient CreateManagementClient(string testName)
},
value = new[]
{
AssetIdentifier.ById(EXISTING_ASSET_ID),
Reference.ById(EXISTING_ASSET_ID),
},
codename = typeof(ComplexTestModel).GetProperty(nameof(ComplexTestModel.TeaserImage)).GetCustomAttribute<JsonPropertyAttribute>()?.PropertyName
},
Expand Down Expand Up @@ -292,7 +291,7 @@ private ManagementClient CreateManagementClient(string testName)
TeaserImage = new AssetElement
{
Element = Reference.ById(typeof(ComplexTestModel).GetProperty(nameof(ComplexTestModel.TeaserImage)).GetKontentElementId()),
Value = new[] { AssetIdentifier.ById(EXISTING_ASSET_ID) },
Value = new[] { Reference.ById(EXISTING_ASSET_ID) },
},
Options = new MultipleChoiceElement
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void GetContentItemVariantUpsertModel_ReturnsExpected()

var teaserImageValue = upsertVariantElements.SingleOrDefault(elementObject =>
elementObject.element.id == type.GetProperty(nameof(model.TeaserImage))?.GetKontentElementId()
).value as IEnumerable<AssetIdentifier>;
).value as IEnumerable<Reference>;

var personaValue = upsertVariantElements.SingleOrDefault(elementObject =>
elementObject.element.id == type.GetProperty(nameof(model.Personas))?.GetKontentElementId()
Expand Down Expand Up @@ -145,7 +145,7 @@ private static ComplexTestModel GetTestModel()
}
}
},
TeaserImage = new AssetElement { Value = new[] { AssetIdentifier.ById(Guid.NewGuid()), AssetIdentifier.ById(Guid.NewGuid()) } },
TeaserImage = new AssetElement { Value = new[] { Reference.ById(Guid.NewGuid()), Reference.ById(Guid.NewGuid()) } },
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() },
Expand Down
8 changes: 4 additions & 4 deletions Kentico.Kontent.Management/ManagementClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ public async Task<ListingResponseModel<AssetModel>> ListAssetsAsync()
/// </summary>
/// <param name="identifier">The identifier of the asset.</param>
/// <returns>The <see cref="AssetModel"/> instance that represents requested asset.</returns>
public async Task<AssetModel> GetAssetAsync(AssetIdentifier identifier)
public async Task<AssetModel> GetAssetAsync(Reference identifier)
{
if (identifier == null)
{
Expand Down Expand Up @@ -1017,7 +1017,7 @@ public async Task<AssetFoldersModel> ModifyAssetFoldersAsync(IEnumerable<AssetFo
/// <param name="identifier">The identifier of the asset.</param>
/// <param name="asset">Represents updated asset.</param>
/// <returns>The <see cref="AssetModel"/> instance that represents updated asset.</returns>
public async Task<AssetModel> UpdateAssetAsync(AssetIdentifier identifier, AssetUpdateModel asset)
public async Task<AssetModel> UpdateAssetAsync(Reference identifier, AssetUpdateModel asset)
{
if (identifier == null)
{
Expand All @@ -1039,7 +1039,7 @@ public async Task<AssetModel> UpdateAssetAsync(AssetIdentifier identifier, Asset
/// Deletes given asset.
/// </summary>
/// <param name="identifier">The identifier of the asset.</param>
public async Task DeleteAssetAsync(AssetIdentifier identifier)
public async Task DeleteAssetAsync(Reference identifier)
{
if (identifier == null)
{
Expand Down Expand Up @@ -1086,7 +1086,7 @@ public async Task<AssetModel> UpsertAssetByExternalIdAsync(string externalId, As
throw new ArgumentNullException(nameof(asset));
}

var endpointUrl = _urlBuilder.BuildAssetsUrl(AssetIdentifier.ByExternalId(externalId));
var endpointUrl = _urlBuilder.BuildAssetsUrl(Reference.ByExternalId(externalId));
var response = await _actionInvoker.InvokeMethodAsync<AssetUpsertModel, AssetModel>(
endpointUrl,
HttpMethod.Put,
Expand Down
42 changes: 0 additions & 42 deletions Kentico.Kontent.Management/Models/Assets/AssetIdentifier.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Kentico.Kontent.Management.Models.Assets;
using Kentico.Kontent.Management.Models.Shared;
using Newtonsoft.Json;

namespace Kentico.Kontent.Management.Models.LanguageVariants.Elements
Expand All @@ -15,19 +15,7 @@ public class AssetElement : BaseElement
/// Gets or sets value of asset element.
/// </summary>
[JsonProperty("value")]
public IEnumerable<AssetIdentifier> Value { get; set; }

/// <summary>
/// Creates new instance of AssertElement
/// <paramref name="data"/>Value of asset element
/// </summary>
public AssetElement(dynamic data = null) : base((object)data)
{
if (data != null)
{
Value = (data.value as IEnumerable<dynamic>)?.Select<dynamic, AssetIdentifier>(identifier => AssetIdentifier.ById(Guid.Parse(identifier.id)));
}
}
public IEnumerable<Reference> Value { get; set; }

/// <summary>
/// Transforms the asset element to dynamic object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ public abstract class BaseElement
[JsonProperty("element", Required = Required.Always)]
public Reference Element { get; set; }

/// <summary>
/// Creates reference of the element.
/// </summary>
public BaseElement(dynamic data = null)
{

if (data?.element?.id != null)
{
// TODO extend by codename + external ID
Element = Reference.ById(Guid.Parse(data.element.id));
}
}

/// <summary>
/// Transforms the element in the language variant to dynamic object.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ public class CustomElement : BaseElement
[JsonProperty("searchable_value")]
public string SearchableValue { get; set; }

public CustomElement(dynamic data = null) : base((object)data)
{
if (data != null)
{
Value = data.value?.ToString();
SearchableValue = data.searchable_value?.ToString();
}
}

public override dynamic ToDynamic(Guid elementId)
{
return new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ public class DateTimeElement : BaseElement
[JsonProperty("value")]
public DateTime Value { get; set; }

public DateTimeElement(dynamic data = null) : base((object)data)
{
if (data != null)
{
Value = Convert.ToDateTime(data.value);
}
}

public override dynamic ToDynamic(Guid elementId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ public class LinkedItemsElement : BaseElement
[JsonProperty("value")]
public IEnumerable<Reference> Value { get; set; }

public LinkedItemsElement(dynamic data = null) : base((object)data)
{
if (data != null)
{
Value = (data.value as IEnumerable<dynamic>)?.Select<dynamic, Reference>(item => Reference.ById(Guid.Parse(item.id)));
}
}

public override dynamic ToDynamic(Guid elementId)
{
return new
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Kentico.Kontent.Management.Models.Assets;
using Kentico.Kontent.Management.Models.Items;
using Kentico.Kontent.Management.Models.Shared;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Kentico.Kontent.Management.Models.LanguageVariants.Elements
{
Expand All @@ -21,14 +16,6 @@ public class MultipleChoiceElement : BaseElement
[JsonProperty("value")]
public IEnumerable<Reference> Value { get; set; }

public MultipleChoiceElement(dynamic data = null) : base((object)data)
{
if (data != null)
{
Value = (data.value as IEnumerable<dynamic>).Select<dynamic, Reference>(identifier => Reference.ById(Guid.Parse(identifier.id)));
}
}

public override dynamic ToDynamic(Guid elementId)
{
return new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ public class NumberElement : BaseElement
[JsonProperty("value")]
public decimal? Value { get; set; }

public NumberElement(dynamic data = null) : base((object)data)
{
if (data != null)
{
Value = Convert.ToDecimal(data.value);
}
}

public override dynamic ToDynamic(Guid elementId)
{
return new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,6 @@ public class RichTextElement : BaseElement
[JsonProperty("value")]
public string Value { get; set; }

public RichTextElement(dynamic data = null) : base((object)data)
{
if (data != null)
{
Value = data.value;
Components = (data.components as IEnumerable<dynamic>)?.Select(component => new ComponentModel
{
Id = Guid.Parse(component.id),
Type = Reference.ById(Guid.Parse(component.type.id)),
Elements = (component.elements as IEnumerable<dynamic>)
});
}
}

public override dynamic ToDynamic(Guid elementId)
{
return new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ public class TaxonomyElement : BaseElement
[JsonProperty("value")]
public IEnumerable<Reference> Value { get; set; }

public TaxonomyElement(dynamic data = null) : base((object)data)
{
if (data != null)
{
Value = (data.value as IEnumerable<dynamic>)?.Select<dynamic, Reference>(identifier => Reference.ById(Guid.Parse(identifier.id)));
}
}

public override dynamic ToDynamic(Guid elementId)
{
return new
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Kentico.Kontent.Management.Models.Shared;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
Expand All @@ -15,14 +16,6 @@ public class TextElement : BaseElement
[JsonProperty("value")]
public string Value { get; set; }

public TextElement(dynamic data = null) : base((object)data)
{
if (data != null)
{
Value = data.value?.ToString();
}
}

public override dynamic ToDynamic(Guid elementId)
{
return new
Expand Down
Loading

0 comments on commit 007e806

Please sign in to comment.