Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Fixed regression with displayValue helper functions #30

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Speckle.Core/Models/Extensions/BaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public static bool IsDisplayableObject(this Base speckleObject)
{
T b => new List<T> { b },
IReadOnlyList<T> list => list,
IEnumerable enumerable => enumerable.OfType<T>().ToList(),
_ => null
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Base>().With.Property(nameof(Base.applicationId)).EqualTo(PAYLOAD));
}

public static IEnumerable<Base> TestCases()
{
var listOfBase = new List<object> { s_displayValue }; //This is what our deserializer will output
var listOfMesh = new List<Base> { 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<Base> displayValue { get; set; }
}
}