forked from ravendb/ravendb
/
CanPassTypesProperlyToAggregation.cs
52 lines (44 loc) · 2.69 KB
/
CanPassTypesProperlyToAggregation.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Raven.Client.Document;
using Raven.Client.Indexes;
using Raven.Database.Indexing;
using Xunit;
namespace Raven.Tests.Bugs
{
public class CanPassTypesProperlyToAggregation
{
[Fact]
public void WillGenerateDecimalCast()
{
Expression<Func<IEnumerable<Coin>, IEnumerable<object>>> query = x => from y in x
group y by y.Denomination
into g
select
new
{
Denomination = g.Key,
Cost = g.Sum(z => z.Cost)
};
var code = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode<Coin>(query, new DocumentConvention(), "docs", false);
Assert.Equal("docs\r\n\t.GroupBy(y => y.Denomination)\r\n\t.Select(g => new {Denomination = g.Key, Cost = g.Sum(z => ((double)z.Cost))})", code);
}
[Fact]
public void WillProperlyCompileWhenUsingToString()
{
Expression<Func<IEnumerable<Coin>, IEnumerable<object>>> query = x => from y in x
group y by y.Denomination
into g
select
new
{
Denomination = g.Key,
Cost = g.First().Cost.ToString()
};
var code = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode<Coin>(query, new DocumentConvention(), "docs", false);
Assert.Equal("docs\r\n\t.GroupBy(y => y.Denomination)\r\n\t.Select(g => new {Denomination = g.Key, Cost = ((double)g.First().Cost).ToString()})", code);
}
}
}