Browse Source

Add unit tests for Core.Helpers.Expression

pull/57/head
Ionite 1 year ago
parent
commit
35319b5d06
No known key found for this signature in database
  1. 41
      StabilityMatrix.Tests/Core/ExpressionsTests.cs

41
StabilityMatrix.Tests/Core/ExpressionsTests.cs

@ -0,0 +1,41 @@
using StabilityMatrix.Core.Helper;
namespace StabilityMatrix.Tests.Core;
[TestClass]
public class ExpressionsTests
{
private class TestClass
{
public int Id { get; set; }
public NestedTestClass? Nested { get; set; }
}
private class NestedTestClass
{
public string Text { get; set; } = "";
}
[TestMethod]
public void GetAssigner_Simple_PropertyName()
{
var (propertyName, _) =
Expressions.GetAssigner<TestClass, int>(x => x.Id);
// Check that the property name is correct
Assert.AreEqual("Id", propertyName);
}
[TestMethod]
public void GetAssigner_Simple_PropertyAssignment()
{
var obj = new TestClass();
var (_, assigner) =
Expressions.GetAssigner<TestClass, int>(x => x.Id);
assigner.Compile()(obj, 42);
Assert.AreEqual(42, obj.Id);
}
}
Loading…
Cancel
Save