Skip to content

Commit

Permalink
Add extra unit test for calling methods on a string property (#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH authored May 2, 2024
1 parent cb77861 commit 37795c5
Showing 1 changed file with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public void Bar()
Name = nameof(Foo);
}

public string Name { get; set; }
public string? Name { get; set; }

public string? Description { get; set; }

public MyClass Child { get; set; }
}
Expand Down Expand Up @@ -1683,24 +1685,53 @@ public void DynamicExpressionParser_ParseLambda_StringEquals_WithCombinedConditi

// #803
[Fact]
public void DynamicExpressionParser_ParseLambda_StringEquals_WithConstantString()
public void DynamicExpressionParser_ParseLambda_Calling_Equals_On_ConstantString()
{
// Arrange
var parameters = new[]
{
Expression.Parameter(typeof(MyClass), "myClass")
};

var invokerArguments = new List<object>
var invokerArguments = new object[]
{
new MyClass { Name = "Foo" }
};

// Act
var expression = "Name == \"test\" || \"foo\".Equals(it.Name, StringComparison.OrdinalIgnoreCase)";
var expression = "Name == \"test\" || Name.ToLower() == \"abc\" or \"foo\".Equals(it.Name, StringComparison.OrdinalIgnoreCase)";
var lambdaExpression = DynamicExpressionParser.ParseLambda(parameters, null, expression);
var del = lambdaExpression.Compile();
var result = del.DynamicInvoke(invokerArguments.ToArray());
var result = del.DynamicInvoke(invokerArguments);

// Assert
result.Should().Be(true);
}

// #810
[Fact]
public void DynamicExpressionParser_ParseLambda_Calling_ToLower_On_String()
{
// Arrange
var parameters = new[]
{
Expression.Parameter(typeof(MyClass), "myClass")
};

var invokerArguments = new object[]
{
new MyClass
{
Name = "Foo",
Description = "Bar"
}
};

// Act
var expression = "(Name != null && Convert.ToString(Name).ToLower().Contains(\"foo\")) or (Description != null && Convert.ToString(Description).ToLower().Contains(\"bar\"))";
var lambdaExpression = DynamicExpressionParser.ParseLambda(parameters, null, expression);
var del = lambdaExpression.Compile();
var result = del.DynamicInvoke(invokerArguments);

// Assert
result.Should().Be(true);
Expand Down

0 comments on commit 37795c5

Please sign in to comment.