@@ -79,6 +79,35 @@ public class Entity
79
79
""" ) . MatchMarkdownAsync ( ) ;
80
80
}
81
81
82
+ [ Fact ]
83
+ public async Task GenerateSource_BatchDataLoader_Nullable_Object_MatchesSnapshot ( )
84
+ {
85
+ await TestHelper . GetGeneratedSourceSnapshot (
86
+ """
87
+ using System.Collections.Generic;
88
+ using System.Threading;
89
+ using System.Threading.Tasks;
90
+ using HotChocolate;
91
+ using GreenDonut;
92
+
93
+ namespace TestNamespace;
94
+
95
+ internal static class TestClass
96
+ {
97
+ [DataLoader]
98
+ public static Task<IReadOnlyDictionary<int, Entity?>> GetEntityByIdAsync(
99
+ IReadOnlyList<int> entityIds,
100
+ CancellationToken cancellationToken)
101
+ => default!;
102
+ }
103
+
104
+ public class Entity
105
+ {
106
+ public int Id { get; set; }
107
+ }
108
+ """ ) . MatchMarkdownAsync ( ) ;
109
+ }
110
+
82
111
[ Fact ]
83
112
public async Task GenerateSource_BatchDataLoader_With_Group_MatchesSnapshot ( )
84
113
{
@@ -200,6 +229,96 @@ public class Entity
200
229
""" ) . MatchMarkdownAsync ( ) ;
201
230
}
202
231
232
+ [ Fact ]
233
+ public async Task GenerateSource_GroupedDataLoader_Nullable_Object_MatchesSnapshot ( )
234
+ {
235
+ await TestHelper . GetGeneratedSourceSnapshot (
236
+ """
237
+ using System.Collections.Generic;
238
+ using System.Linq;
239
+ using System.Threading;
240
+ using System.Threading.Tasks;
241
+ using HotChocolate;
242
+ using GreenDonut;
243
+
244
+ namespace TestNamespace;
245
+
246
+ internal static class TestClass
247
+ {
248
+ [DataLoader]
249
+ public static Task<ILookup<int, Entity?>> GetEntitiesByIdAsync(
250
+ IReadOnlyList<int> entityIds,
251
+ CancellationToken cancellationToken)
252
+ => default!;
253
+ }
254
+
255
+ public class Entity
256
+ {
257
+ public int Id { get; set; }
258
+ }
259
+ """ ) . MatchMarkdownAsync ( ) ;
260
+ }
261
+
262
+ [ Fact ]
263
+ public async Task GenerateSource_GroupedDataLoader_ValueType_MatchesSnapshot ( )
264
+ {
265
+ await TestHelper . GetGeneratedSourceSnapshot (
266
+ """
267
+ using System.Collections.Generic;
268
+ using System.Linq;
269
+ using System.Threading;
270
+ using System.Threading.Tasks;
271
+ using HotChocolate;
272
+ using GreenDonut;
273
+
274
+ namespace TestNamespace;
275
+
276
+ internal static class TestClass
277
+ {
278
+ [DataLoader]
279
+ public static Task<ILookup<int, long>> GetEntitiesByIdAsync(
280
+ IReadOnlyList<int> entityIds,
281
+ CancellationToken cancellationToken)
282
+ => default!;
283
+ }
284
+
285
+ public class Entity
286
+ {
287
+ public int Id { get; set; }
288
+ }
289
+ """ ) . MatchMarkdownAsync ( ) ;
290
+ }
291
+
292
+ [ Fact ]
293
+ public async Task GenerateSource_GroupedDataLoader_Nullable_ValueType_MatchesSnapshot ( )
294
+ {
295
+ await TestHelper . GetGeneratedSourceSnapshot (
296
+ """
297
+ using System.Collections.Generic;
298
+ using System.Linq;
299
+ using System.Threading;
300
+ using System.Threading.Tasks;
301
+ using HotChocolate;
302
+ using GreenDonut;
303
+
304
+ namespace TestNamespace;
305
+
306
+ internal static class TestClass
307
+ {
308
+ [DataLoader]
309
+ public static Task<ILookup<int, long?>> GetEntitiesByIdAsync(
310
+ IReadOnlyList<int> entityIds,
311
+ CancellationToken cancellationToken)
312
+ => default!;
313
+ }
314
+
315
+ public class Entity
316
+ {
317
+ public int Id { get; set; }
318
+ }
319
+ """ ) . MatchMarkdownAsync ( ) ;
320
+ }
321
+
203
322
[ Fact ]
204
323
public async Task GenerateSource_CacheDataLoader_MatchesSnapshot ( )
205
324
{
@@ -228,6 +347,90 @@ public class Entity
228
347
""" ) . MatchMarkdownAsync ( ) ;
229
348
}
230
349
350
+ [ Fact ]
351
+ public async Task GenerateSource_CacheDataLoader_Nullable_Object_MatchesSnapshot ( )
352
+ {
353
+ await TestHelper . GetGeneratedSourceSnapshot (
354
+ """
355
+ using System.Threading;
356
+ using System.Threading.Tasks;
357
+ using HotChocolate;
358
+ using GreenDonut;
359
+
360
+ namespace TestNamespace;
361
+
362
+ internal static class TestClass
363
+ {
364
+ [DataLoader]
365
+ public static Task<Entity?> GetEntityByIdAsync(
366
+ int entityId,
367
+ CancellationToken cancellationToken)
368
+ => default!;
369
+ }
370
+
371
+ public class Entity
372
+ {
373
+ public int Id { get; set; }
374
+ }
375
+ """ ) . MatchMarkdownAsync ( ) ;
376
+ }
377
+
378
+ [ Fact ]
379
+ public async Task GenerateSource_CacheDataLoader_ValueType_MatchesSnapshot ( )
380
+ {
381
+ await TestHelper . GetGeneratedSourceSnapshot (
382
+ """
383
+ using System.Threading;
384
+ using System.Threading.Tasks;
385
+ using HotChocolate;
386
+ using GreenDonut;
387
+
388
+ namespace TestNamespace;
389
+
390
+ internal static class TestClass
391
+ {
392
+ [DataLoader]
393
+ public static Task<long> GetEntityByIdAsync(
394
+ int entityId,
395
+ CancellationToken cancellationToken)
396
+ => default!;
397
+ }
398
+
399
+ public class Entity
400
+ {
401
+ public int Id { get; set; }
402
+ }
403
+ """ ) . MatchMarkdownAsync ( ) ;
404
+ }
405
+
406
+ [ Fact ]
407
+ public async Task GenerateSource_CacheDataLoader_Nullable_ValueType_MatchesSnapshot ( )
408
+ {
409
+ await TestHelper . GetGeneratedSourceSnapshot (
410
+ """
411
+ using System.Threading;
412
+ using System.Threading.Tasks;
413
+ using HotChocolate;
414
+ using GreenDonut;
415
+
416
+ namespace TestNamespace;
417
+
418
+ internal static class TestClass
419
+ {
420
+ [DataLoader]
421
+ public static Task<long?> GetEntityByIdAsync(
422
+ int entityId,
423
+ CancellationToken cancellationToken)
424
+ => default!;
425
+ }
426
+
427
+ public class Entity
428
+ {
429
+ public int Id { get; set; }
430
+ }
431
+ """ ) . MatchMarkdownAsync ( ) ;
432
+ }
433
+
231
434
[ Fact ]
232
435
public async Task GenerateSource_GenericBatchDataLoader_MatchesSnapshot ( )
233
436
{
@@ -324,7 +527,7 @@ public static Task<IDictionary<int, Entity2>> GetEntityByIdAsync(
324
527
CancellationToken cancellationToken)
325
528
=> default!;
326
529
327
- public static KeyValuePair<int, Entity2> CreateLookupKey(Entity1 key)
530
+ public static KeyValuePair<int, Entity2>? CreateLookupKey(Entity1 key)
328
531
=> default!;
329
532
}
330
533
0 commit comments