-
-
Notifications
You must be signed in to change notification settings - Fork 725
/
StringTypeTests.cs
196 lines (159 loc) · 4.58 KB
/
StringTypeTests.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
using System;
using HotChocolate.Language;
using Xunit;
namespace HotChocolate.Types
{
public class StringTypeTests
{
[Fact]
public void EnsureStringTypeKindIsCorret()
{
// arrange
var type = new StringType();
// act
TypeKind kind = type.Kind;
// assert
Assert.Equal(TypeKind.Scalar, type.Kind);
}
[Fact]
public void IsInstanceOfType_ValueNode()
{
// arrange
var type = new StringType();
var input = new StringValueNode("123456");
// act
bool result = type.IsInstanceOfType(input);
// assert
Assert.True(result);
}
[Fact]
public void IsInstanceOfType_NullValueNode()
{
// arrange
var type = new StringType();
NullValueNode input = NullValueNode.Default;
// act
bool result = type.IsInstanceOfType(input);
// assert
Assert.True(result);
}
[Fact]
public void IsInstanceOfType_Wrong_ValueNode()
{
// arrange
var type = new StringType();
var input = new IntValueNode(123456);
// act
bool result = type.IsInstanceOfType(input);
// assert
Assert.False(result);
}
[Fact]
public void IsInstanceOfType_Null_Throws()
{
// arrange
var type = new StringType();
// act
// assert
Assert.Throws<ArgumentNullException>(() => type.IsInstanceOfType(null));
}
[Fact]
public void Serialize_Type()
{
// arrange
var type = new StringType();
string input = "123456";
// act
object serializedValue = type.Serialize(input);
// assert
Assert.IsType<string>(serializedValue);
Assert.Equal("123456", serializedValue);
}
[Fact]
public void Serialize_Null()
{
// arrange
var type = new StringType();
// act
object serializedValue = type.Serialize(null);
// assert
Assert.Null(serializedValue);
}
[Fact]
public void Serialize_Wrong_Type_Throws()
{
// arrange
var type = new StringType();
object input = 123456;
// act
// assert
Assert.Throws<SerializationException>(
() => type.Serialize(input));
}
[Fact]
public void ParseLiteral_ValueNode()
{
// arrange
var type = new StringType();
var input = new StringValueNode("123456");
// act
object output = type.ParseLiteral(input);
// assert
Assert.IsType<string>(output);
Assert.Equal("123456", output);
}
[Fact]
public void ParseLiteral_NullValueNode()
{
// arrange
var type = new StringType();
NullValueNode input = NullValueNode.Default;
// act
object output = type.ParseLiteral(input);
// assert
Assert.Null(output);
}
[Fact]
public void ParseLiteral_Wrong_ValueNode_Throws()
{
// arrange
var type = new StringType();
var input = new IntValueNode(123456);
// act
// assert
Assert.Throws<SerializationException>(
() => type.ParseLiteral(input));
}
[Fact]
public void ParseLiteral_Null_Throws()
{
// arrange
var type = new StringType();
// act
// assert
Assert.Throws<ArgumentNullException>(() => type.ParseLiteral(null));
}
[Fact]
public void ParseValue_Wrong_Value_Throws()
{
// arrange
var type = new StringType();
object input = 123456;
// act
// assert
Assert.Throws<SerializationException>(
() => type.ParseValue(input));
}
[Fact]
public void ParseValue_Null()
{
// arrange
var type = new StringType();
object input = null;
// act
object output = type.ParseValue(input);
// assert
Assert.IsType<NullValueNode>(output);
}
}
}