-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API-748 - Add logic to be able to pass metaproperty options during sa…
…ve & modify media (#70) * Added ITypeToDictionaryConverter * Added converter for metaproperty options * Added "metaproperty" param to queries * Version update to 2.2.10
- Loading branch information
Huib Piguillet
authored
Dec 3, 2021
1 parent
b772d7d
commit d1480c6
Showing
8 changed files
with
250 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) Bynder. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Bynder.Sdk.Api.Converters | ||
{ | ||
/// <summary> | ||
/// Interface for type converters used to decode specific | ||
/// parameters to strings | ||
/// </summary> | ||
public interface ITypeToDictionaryConverter | ||
{ | ||
/// <summary> | ||
/// Checks if the converter can convert a specific type | ||
/// </summary> | ||
/// <param name="typeToConvert">Type to convert from</param> | ||
/// <returns>true if it can convert the type</returns> | ||
bool CanConvert(Type typeToConvert); | ||
|
||
/// <summary> | ||
/// Converts the value to string | ||
/// </summary> | ||
/// <param name="value">value to be converted</param> | ||
/// <returns>converted string value</returns> | ||
IDictionary<string, string> Convert(object value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Bynder.Sdk.Api.Converters | ||
{ | ||
public class MetapropertyOptionsConverter : ITypeToDictionaryConverter | ||
{ | ||
|
||
public bool CanConvert(Type typeToConvert) | ||
{ | ||
return typeof(IDictionary<string, IList<string>>).IsAssignableFrom(typeToConvert); | ||
} | ||
|
||
public IDictionary<string, string> Convert(object value) | ||
{ | ||
return ((IDictionary<string, IList<string>>)value).ToDictionary( | ||
item => item.Key, | ||
item => string.Join(",", item.Value) | ||
); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
Bynder/Test/Api/Converters/MetapropertyOptionsConverterTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Collections.Generic; | ||
using Bynder.Sdk.Api.Converters; | ||
using Xunit; | ||
|
||
namespace Bynder.Test.Api.Converters | ||
{ | ||
public class MetapropertyOptionsConverterTest | ||
{ | ||
[Fact] | ||
public void CanConvertOnlyWhenTypeIsDateTimeOffset() | ||
{ | ||
var converter = new MetapropertyOptionsConverter(); | ||
Assert.False(converter.CanConvert(typeof(int))); | ||
Assert.False(converter.CanConvert(typeof(string))); | ||
Assert.False(converter.CanConvert(typeof(bool))); | ||
Assert.True(converter.CanConvert(typeof(IDictionary<string, IList<string>>))); | ||
} | ||
|
||
[Fact] | ||
public void ConvertReturnsStringWithDate() | ||
{ | ||
const string metaprop1 = "metaprop1"; | ||
const string metaprop1option1 = "metaprop1option1"; | ||
const string metaprop1option2 = "metaprop1option2"; | ||
const string metaprop1option3 = "metaprop1option3"; | ||
|
||
const string metaprop2 = "metaprop2"; | ||
const string metaprop2option1 = "metaprop2option1"; | ||
const string metaprop2option2 = "metaprop2option2"; | ||
const string metaprop2option3 = "metaprop2option3"; | ||
|
||
const string metaprop3 = "metaprop3"; | ||
const string metaprop3option1 = "metaprop3option1"; | ||
const string metaprop3option2 = "metaprop3option2"; | ||
const string metaprop3option3 = "metaprop3option3"; | ||
|
||
var converter = new MetapropertyOptionsConverter(); | ||
var converted = converter.Convert(new Dictionary<string, IList<string>> | ||
{ | ||
{ metaprop1, new List<string> { metaprop1option1, metaprop1option2, metaprop1option3 } }, | ||
{ metaprop2, new List<string> { metaprop2option1, metaprop2option2, metaprop2option3 } }, | ||
{ metaprop3, new List<string> { metaprop3option1, metaprop3option2, metaprop3option3 } } | ||
}); | ||
var expected = new Dictionary<string, string> | ||
{ | ||
{ metaprop1, $"{metaprop1option1},{metaprop1option2},{metaprop1option3}" }, | ||
{ metaprop2, $"{metaprop2option1},{metaprop2option2},{metaprop2option3}" }, | ||
{ metaprop3, $"{metaprop3option1},{metaprop3option2},{metaprop3option3}" } | ||
}; | ||
Assert.Equal(expected, converted); | ||
} | ||
} | ||
} |
Oops, something went wrong.