Skip to content

Commit cac9576

Browse files
authored
Add OrderBy NullPropagation tests (#865)
1 parent bf213e6 commit cac9576

File tree

3 files changed

+224
-134
lines changed

3 files changed

+224
-134
lines changed

test/System.Linq.Dynamic.Core.Tests/EntitiesTests.OrderBy.cs

+22
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,26 @@ public void Entities_OrderBy_RestrictOrderByIsTrue_InvalidExpressionShouldThrow(
5151
// Assert
5252
action.Should().Throw<ParseException>().WithMessage("No property or field 'IIF' exists in type 'Blog'");
5353
}
54+
55+
[Fact]
56+
public void Entities_OrderBy_NullPropagation_Int()
57+
{
58+
// Arrange
59+
var resultBlogs = _context.Blogs.OrderBy(b => b.NullableInt ?? -1).ToArray();
60+
var dynamicResultBlogs = _context.Blogs.OrderBy("np(NullableInt, -1)").ToArray();
61+
62+
// Assert
63+
Assert.Equal(resultBlogs, dynamicResultBlogs);
64+
}
65+
66+
[Fact]
67+
public void Entities_OrderBy_NullPropagation_String()
68+
{
69+
// Arrange
70+
var resultBlogs = _context.Blogs.OrderBy(b => b.X ?? "_").ToArray();
71+
var dynamicResultBlogs = _context.Blogs.OrderBy("np(X, \"_\")").ToArray();
72+
73+
// Assert
74+
Assert.Equal(resultBlogs, dynamicResultBlogs);
75+
}
5476
}

test/System.Linq.Dynamic.Core.Tests/Helpers/Models/User.cs

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class User
2424

2525
public int? NullableInt { get; set; }
2626

27+
public string? NullableString { get; set; }
28+
2729
public int Income { get; set; }
2830

2931
public char C { get; set; }

0 commit comments

Comments
 (0)