-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Fixed issue with DisplayValue helper functions (#3575)
fix(core): Fixed issue with DispalyValue helper functions
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 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
43 changes: 43 additions & 0 deletions
43
Core/Tests/Speckle.Core.Tests.Unit/Models/Extensions/DisplayValueTests.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,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; } | ||
} | ||
} |