-
-
Notifications
You must be signed in to change notification settings - Fork 725
/
ObjectFieldExpressionTests.cs
86 lines (76 loc) · 2.24 KB
/
ObjectFieldExpressionTests.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System.Collections.Generic;
using System.Linq;
using HotChocolate.Execution;
using Snapshooter;
using Snapshooter.Xunit;
using Xunit;
#nullable enable
namespace HotChocolate.Types
{
public class ObjectFieldExpressionTests
{
[Fact]
public void Infer_Field_Types_From_Expression()
{
SchemaBuilder.New()
.AddQueryType<Foo>(d =>
{
d.Name("Query");
d.Field(t => t.Bar.Text);
#if !NETCOREAPP2_1 && !NETCOREAPP3_1
d.Field(t => t.Bars.Select(t => t.Text)).Name("texts");
#endif
})
.Create()
.ToString()
#if NETCOREAPP2_1 || NETCOREAPP3_1
.MatchSnapshot(new SnapshotNameExtension("NETCOREAPP2_1"));
#else
.MatchSnapshot();
#endif
}
[Fact]
public void Execute_Expression_Fields()
{
SchemaBuilder.New()
.AddQueryType<Foo>(d =>
{
d.Name("Query");
d.Field(t => t.Bar.Text);
d.Field(t => t.Bars.Select(t => t.Text)).Name("texts");
d.Field(t => t.Bars.Select(t => t.Text).FirstOrDefault()).Name("firstText");
})
.Create()
.MakeExecutable()
.Execute("{ text texts firstText }")
.ToJson()
.MatchSnapshot();
}
[Fact]
public void Execute_Complex_Expression_Fields()
{
SchemaBuilder.New()
.AddQueryType<Foo>(d =>
{
d.Name("Query");
d.Field(t => t.Bar.Count + t.Bar.Text.Length).Name("calc");
})
.Create()
.MakeExecutable()
.Execute("{ calc }")
.ToJson()
.MatchSnapshot();
}
public class Foo
{
public IEnumerable<Bar> Bars => new[] { new Bar() };
public Bar Bar => new Bar();
public string Field = "ABC";
}
public class Bar
{
public string Text { get; } = "Hello";
public int Count { get; } = 1;
}
}
}