Skip to content

Commit 4aa26e1

Browse files
committed
Add some tests for bugs #104 and #105
Still need to correct them
1 parent 3e4641d commit 4aa26e1

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,43 @@ public void Evaluate_ParameterTypeMismatchAutoAdapt()
16411641
.ShouldBeOfType<DateTime>();
16421642
}
16431643

1644+
/// <summary>
1645+
/// To correct #104 Extension methods do not work on context
1646+
/// </summary>
1647+
[Test]
1648+
[Category("Bug")]
1649+
[Category("#104")]
1650+
public void Evaluate_ExtensionMethodOnContext()
1651+
{
1652+
var evaluator = new ExpressionEvaluator
1653+
{
1654+
Context = new List<int>()
1655+
{
1656+
1,2,3,4,5
1657+
}
1658+
};
1659+
1660+
evaluator.Evaluate("Sum()")
1661+
.ShouldBe(15);
1662+
}
1663+
1664+
/// <summary>
1665+
/// To correct #105 Exception should be thrown and not set in the stack
1666+
/// </summary>
1667+
[Test]
1668+
[Category("Bug")]
1669+
[Category("#105")]
1670+
public void Evaluate_Exceptions_NotThrown()
1671+
{
1672+
var evaluator = new ExpressionEvaluator
1673+
{
1674+
Context = new { Person = new Person2 { Name = null, Number = 1.11m } }
1675+
};
1676+
1677+
Should.Throw<Exception>(() => Console.WriteLine(evaluator.Evaluate("\"Test one \" + Person.Name.Trim()")));
1678+
Should.Throw<Exception>(() => Console.WriteLine(evaluator.Evaluate("\"Test two \" + Person.AnotherName.Trim()")));
1679+
}
1680+
16441681
#endregion
16451682

16461683
#region EvaluateWithSpecificEvaluator

0 commit comments

Comments
 (0)