diff --git a/Core/Core/Models/Extensions/BaseExtensions.cs b/Core/Core/Models/Extensions/BaseExtensions.cs index d919d120c5..adff40d178 100644 --- a/Core/Core/Models/Extensions/BaseExtensions.cs +++ b/Core/Core/Models/Extensions/BaseExtensions.cs @@ -201,6 +201,7 @@ public static bool IsDisplayableObject(this Base speckleObject) { T b => new List { b }, IReadOnlyList list => list, + IEnumerable enumerable => enumerable.OfType().ToList(), _ => null }; } diff --git a/Core/Tests/Speckle.Core.Tests.Unit/Models/Extensions/DisplayValueTests.cs b/Core/Tests/Speckle.Core.Tests.Unit/Models/Extensions/DisplayValueTests.cs new file mode 100644 index 0000000000..59f289c749 --- /dev/null +++ b/Core/Tests/Speckle.Core.Tests.Unit/Models/Extensions/DisplayValueTests.cs @@ -0,0 +1,43 @@ +using NUnit.Framework; +using Speckle.Core.Models; +using Speckle.Core.Models.Extensions; + +namespace Speckle.Core.Tests.Unit.Models.Extensions; + +[TestOf(typeof(BaseExtensions))] +public class DisplayValueTests +{ + private const string PAYLOAD = "This is my payload"; + private static readonly Base s_displayValue = new() { applicationId = PAYLOAD }; + + [TestCaseSource(nameof(TestCases))] + public void TestTryGetDisplayValue_WithValue(Base testCase) + { + var res = testCase.TryGetDisplayValue(); + + Assert.That(res, Has.Count.EqualTo(1)); + Assert.That(res, Has.One.Items.TypeOf().With.Property(nameof(Base.applicationId)).EqualTo(PAYLOAD)); + } + + public static IEnumerable TestCases() + { + var listOfBase = new List { s_displayValue }; //This is what our deserializer will output + var listOfMesh = new List { s_displayValue }; + yield return new Base { ["@displayValue"] = s_displayValue }; + yield return new Base { ["@displayValue"] = s_displayValue }; + yield return new Base { ["displayValue"] = listOfBase }; + yield return new Base { ["displayValue"] = listOfBase }; + yield return new TypedDisplayValue { displayValue = s_displayValue }; + yield return new TypedDisplayValueList { displayValue = listOfMesh }; + } + + private class TypedDisplayValue : Base + { + public Base displayValue { get; set; } + } + + private class TypedDisplayValueList : Base + { + public List displayValue { get; set; } + } +}