-
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
92 additions
and
32 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
114 changes: 84 additions & 30 deletions
114
test/System.Linq.Dynamic.Core.Tests/QueryableTests.Max.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 |
---|---|---|
@@ -1,36 +1,90 @@ | ||
using System.Linq.Dynamic.Core.Tests.Helpers.Models; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace System.Linq.Dynamic.Core.Tests | ||
namespace System.Linq.Dynamic.Core.Tests; | ||
|
||
public partial class QueryableTests | ||
{ | ||
public partial class QueryableTests | ||
[Fact] | ||
public void Max() | ||
{ | ||
// Arrange | ||
var incomes = User.GenerateSampleModels(10).Select(u => u.Income).ToArray(); | ||
|
||
// Act | ||
var expected = incomes.Max(); | ||
var actual = incomes.AsQueryable().Max(); | ||
|
||
// Assert | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Fact] | ||
public void Max_Selector() | ||
{ | ||
[Fact] | ||
public void Max() | ||
{ | ||
// Arrange | ||
var incomes = User.GenerateSampleModels(100).Select(u => u.Income); | ||
|
||
// Act | ||
var expected = incomes.Max(); | ||
var actual = incomes.AsQueryable().Max(); | ||
|
||
// Assert | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Fact] | ||
public void Max_Selector() | ||
{ | ||
// Arrange | ||
var users = User.GenerateSampleModels(100); | ||
|
||
// Act | ||
var expected = users.Max(u => u.Income); | ||
var result = users.AsQueryable().Max("Income"); | ||
|
||
// Assert | ||
Assert.Equal(expected, result); | ||
} | ||
// Arrange | ||
var users = User.GenerateSampleModels(10); | ||
|
||
// Act | ||
var expected = users.Max(u => u.Income); | ||
var result = users.AsQueryable().Max("Income"); | ||
|
||
// Assert | ||
Assert.Equal(expected, result); | ||
} | ||
|
||
[Fact] | ||
public void Max_Where_On_Int() | ||
{ | ||
// Arrange | ||
var users = User.GenerateSampleModels(10); | ||
|
||
// Act | ||
var typed = users | ||
.Where(u => users.Max(m => m.Income) == u.Income) | ||
.ToList(); | ||
var dynamic = users.AsQueryable() | ||
.Where("@0.Max(Income) == Income", users) | ||
.ToList(); | ||
|
||
// Assert | ||
dynamic.Should().BeEquivalentTo(typed); | ||
} | ||
|
||
[Fact] | ||
public void Max_Where_On_DateTime() | ||
{ | ||
// Arrange | ||
var users = User.GenerateSampleModels(10); | ||
|
||
// Act | ||
var typed = users | ||
.Where(u => users.Max(m => m.BirthDate) == u.BirthDate) | ||
.ToList(); | ||
var dynamic = users.AsQueryable() | ||
.Where("@0.Max(BirthDate) == BirthDate", users) | ||
.ToList(); | ||
|
||
// Assert | ||
dynamic.Should().BeEquivalentTo(typed); | ||
} | ||
|
||
[Fact] | ||
public void Max_Where_On_NullableDateTime() | ||
{ | ||
// Arrange | ||
var users = User.GenerateSampleModels(10); | ||
|
||
// Act | ||
var typed = users | ||
.Where(u => users.Max(m => m.EndDate) == u.EndDate) | ||
.ToList(); | ||
var dynamic = users.AsQueryable() | ||
.Where("@0.Max(EndDate) == EndDate", users) | ||
.ToList(); | ||
|
||
// Assert | ||
dynamic.Should().BeEquivalentTo(typed); | ||
} | ||
} | ||
} |