1
1
using System . Collections . Generic ;
2
+ using System . Threading ;
2
3
using System . Threading . Tasks ;
3
4
using Microsoft . AspNetCore . TestHost ;
4
5
using HotChocolate . AspNetCore . Utilities ;
6
+ using HotChocolate . Execution ;
7
+ using Microsoft . AspNetCore . Http ;
5
8
using Microsoft . Extensions . DependencyInjection ;
6
9
using Snapshooter ;
7
10
using Snapshooter . Xunit ;
@@ -68,8 +71,8 @@ public async Task Simple_IsAlive_Test_On_Non_GraphQL_Path()
68
71
69
72
// act
70
73
ClientQueryResult result = await server . PostAsync (
71
- new ClientQueryRequest { Query = "{ __typename }" } ,
72
- "/foo" ) ;
74
+ new ClientQueryRequest { Query = "{ __typename }" } ,
75
+ "/foo" ) ;
73
76
74
77
// assert
75
78
result . MatchSnapshot ( ) ;
@@ -135,10 +138,7 @@ await server.PostAsync(new ClientQueryRequest
135
138
name
136
139
}
137
140
}" ,
138
- Variables = new Dictionary < string , object >
139
- {
140
- { "episode" , "NEW_HOPE" }
141
- }
141
+ Variables = new Dictionary < string , object > { { "episode" , "NEW_HOPE" } }
142
142
} ) ;
143
143
144
144
// assert
@@ -161,10 +161,7 @@ query h($id: String!) {
161
161
name
162
162
}
163
163
}" ,
164
- Variables = new Dictionary < string , object >
165
- {
166
- { "id" , "1000" }
167
- }
164
+ Variables = new Dictionary < string , object > { { "id" , "1000" } }
168
165
} ) ;
169
166
170
167
// assert
@@ -224,8 +221,7 @@ mutation CreateReviewForEpisode(
224
221
"review" ,
225
222
new Dictionary < string , object >
226
223
{
227
- { "stars" , 5 } ,
228
- { "commentary" , "This is a great movie!" } ,
224
+ { "stars" , 5 } , { "commentary" , "This is a great movie!" } ,
229
225
}
230
226
}
231
227
}
@@ -260,8 +256,7 @@ mutation CreateReviewForEpisode(
260
256
"review" ,
261
257
new Dictionary < string , object >
262
258
{
263
- { "stars" , 5 } ,
264
- { "commentary" , "This is a great movie!" } ,
259
+ { "stars" , 5 } , { "commentary" , "This is a great movie!" } ,
265
260
}
266
261
}
267
262
}
@@ -390,10 +385,7 @@ await server.PostAsync(new ClientQueryRequest
390
385
name
391
386
}
392
387
}" ,
393
- Variables = new Dictionary < string , object >
394
- {
395
- { "episode" , "NEW_HOPE" }
396
- }
388
+ Variables = new Dictionary < string , object > { { "episode" , "NEW_HOPE" } }
397
389
} ) ;
398
390
399
391
// assert
@@ -463,11 +455,7 @@ await server.PostAsync(new ClientQueryRequest
463
455
"/arguments" ) ;
464
456
465
457
// assert
466
- new
467
- {
468
- double . MaxValue ,
469
- result
470
- } . MatchSnapshot ( ) ;
458
+ new { double . MaxValue , result } . MatchSnapshot ( ) ;
471
459
}
472
460
473
461
[ Fact ]
@@ -489,11 +477,7 @@ await server.PostAsync(new ClientQueryRequest
489
477
"/arguments" ) ;
490
478
491
479
// assert
492
- new
493
- {
494
- double . MinValue ,
495
- result
496
- } . MatchSnapshot ( ) ;
480
+ new { double . MinValue , result } . MatchSnapshot ( ) ;
497
481
}
498
482
499
483
[ Fact ]
@@ -515,11 +499,7 @@ await server.PostAsync(new ClientQueryRequest
515
499
"/arguments" ) ;
516
500
517
501
// assert
518
- new
519
- {
520
- decimal . MaxValue ,
521
- result
522
- } . MatchSnapshot ( ) ;
502
+ new { decimal . MaxValue , result } . MatchSnapshot ( ) ;
523
503
}
524
504
525
505
[ Fact ]
@@ -541,11 +521,7 @@ await server.PostAsync(new ClientQueryRequest
541
521
"/arguments" ) ;
542
522
543
523
// assert
544
- new
545
- {
546
- decimal . MinValue ,
547
- result
548
- } . MatchSnapshot ( ) ;
524
+ new { decimal . MinValue , result } . MatchSnapshot ( ) ;
549
525
}
550
526
551
527
[ Fact ]
@@ -778,5 +754,41 @@ query getHuman {
778
754
// assert
779
755
result . MatchSnapshot ( ) ;
780
756
}
757
+
758
+ [ Fact ]
759
+ public async Task Throw_Custom_GraphQL_Error ( )
760
+ {
761
+ // arrange
762
+ TestServer server = CreateStarWarsServer (
763
+ configureServices : s => s . AddGraphQLServer ( )
764
+ . AddHttpRequestInterceptor < ErrorRequestInterceptor > ( ) ) ;
765
+
766
+ // act
767
+ ClientQueryResult result =
768
+ await server . PostAsync ( new ClientQueryRequest
769
+ {
770
+ Query = @"
771
+ {
772
+ hero {
773
+ name
774
+ }
775
+ }"
776
+ } ) ;
777
+
778
+ // assert
779
+ result . MatchSnapshot ( ) ;
780
+ }
781
+
782
+ public class ErrorRequestInterceptor : DefaultHttpRequestInterceptor
783
+ {
784
+ public override ValueTask OnCreateAsync (
785
+ HttpContext context ,
786
+ IRequestExecutor requestExecutor ,
787
+ IQueryRequestBuilder requestBuilder ,
788
+ CancellationToken cancellationToken )
789
+ {
790
+ throw new GraphQLException ( "MyCustomError" ) ;
791
+ }
792
+ }
781
793
}
782
794
}
0 commit comments