-
-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathExpressionTests.Sum.cs
More file actions
57 lines (46 loc) · 1.52 KB
/
ExpressionTests.Sum.cs
File metadata and controls
57 lines (46 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.Linq.Dynamic.Core.Tests.Helpers.Models;
using Xunit;
namespace System.Linq.Dynamic.Core.Tests;
public partial class ExpressionTests
{
[Fact]
public void ExpressionTests_Sum()
{
// Arrange
int[] initValues = [1, 2, 3, 4, 5];
var qry = initValues.AsQueryable().Select(x => new { strValue = "str", intValue = x }).GroupBy(x => x.strValue);
// Act
var result = qry.Select("Sum(intValue)").AsDynamicEnumerable().ToArray()[0];
// Assert
Assert.Equal(15, result);
}
[Fact]
public void ExpressionTests_Sum_LowerCase()
{
// Arrange
int[] initValues = [1, 2, 3, 4, 5];
var qry = initValues.AsQueryable().Select(x => new { strValue = "str", intValue = x }).GroupBy(x => x.strValue);
// Act
var result = qry.Select("sum(intValue)").AsDynamicEnumerable().ToArray()[0];
// Assert
Assert.Equal(15, result);
}
[Fact]
public void ExpressionTests_Sum2()
{
// Arrange
var initValues = new[]
{
new SimpleValuesModel { FloatValue = 1 },
new SimpleValuesModel { FloatValue = 2 },
new SimpleValuesModel { FloatValue = 3 },
};
var qry = initValues.AsQueryable();
// Act
var result = qry.Select("FloatValue").Sum();
var result2 = ((IQueryable<float>)qry.Select("FloatValue")).Sum();
// Assert
Assert.Equal(6.0f, result);
Assert.Equal(6.0f, result2);
}
}