Skip to content

Commit

Permalink
Add OrderBy NullPropagation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed Dec 24, 2024
1 parent bf213e6 commit 3e61d5f
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 134 deletions.
22 changes: 22 additions & 0 deletions test/System.Linq.Dynamic.Core.Tests/EntitiesTests.OrderBy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,26 @@ public void Entities_OrderBy_RestrictOrderByIsTrue_InvalidExpressionShouldThrow(
// Assert
action.Should().Throw<ParseException>().WithMessage("No property or field 'IIF' exists in type 'Blog'");
}

[Fact]
public void Entities_OrderBy_NullPropagation_Int()
{
// Arrange
var resultBlogs = _context.Blogs.OrderBy(b => b.NullableInt ?? -1).ToArray();
var dynamicResultBlogs = _context.Blogs.OrderBy("np(NullableInt, -1)").ToArray();

// Assert
Assert.Equal(resultBlogs, dynamicResultBlogs);
}

[Fact]
public void Entities_OrderBy_NullPropagation_String()
{
// Arrange
var resultBlogs = _context.Blogs.OrderBy(b => b.X ?? "_").ToArray();
var dynamicResultBlogs = _context.Blogs.OrderBy("np(X, \"_\")").ToArray();

// Assert
Assert.Equal(resultBlogs, dynamicResultBlogs);
}
}
2 changes: 2 additions & 0 deletions test/System.Linq.Dynamic.Core.Tests/Helpers/Models/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class User

public int? NullableInt { get; set; }

public string? NullableString { get; set; }

public int Income { get; set; }

public char C { get; set; }
Expand Down
Loading

0 comments on commit 3e61d5f

Please sign in to comment.