-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from zzzprojects/stef_call_methods_which_retu…
…rn_nullable Fixed : calling methods which return a nullable
- Loading branch information
Showing
2 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
test/System.Linq.Dynamic.Core.Tests/QueryableTests.Methods.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using Xunit; | ||
|
||
namespace System.Linq.Dynamic.Core.Tests | ||
{ | ||
public partial class QueryableTests | ||
{ | ||
[Fact] | ||
public void CallMethod() | ||
{ | ||
// Arrange | ||
var query = new[] { new Test() }.AsQueryable(); | ||
|
||
// Act | ||
var result = query.Select<decimal>("t => t.GetDecimal()").First(); | ||
|
||
// Assert | ||
Assert.Equal(42, result); | ||
} | ||
|
||
[Fact] | ||
public void CallMethodWhichReturnsNullable() | ||
{ | ||
// Arrange | ||
var query = new[] { new Test() }.AsQueryable(); | ||
|
||
// Act | ||
var result = query.Select<decimal?>("t => t.GetNullableDecimal()").First(); | ||
|
||
// Assert | ||
Assert.Equal(null, result); | ||
} | ||
|
||
[Fact] | ||
public void CallMethodWhichReturnsNullable_WithValue() | ||
{ | ||
// Arrange | ||
var query = new[] { new Test() }.AsQueryable(); | ||
|
||
// Act | ||
var result = query.Select<decimal?>("t => t.GetNullableDecimalWithValue()").First(); | ||
|
||
// Assert | ||
Assert.Equal(100, result); | ||
} | ||
} | ||
|
||
class Test | ||
{ | ||
public decimal GetDecimal() | ||
{ | ||
return 42; | ||
} | ||
|
||
public decimal? GetNullableDecimal() | ||
{ | ||
return null; | ||
} | ||
|
||
public decimal? GetNullableDecimalWithValue() | ||
{ | ||
return 100; | ||
} | ||
} | ||
} |