@@ -311,6 +311,33 @@ public void Test_Guard_IsTrue_Fail_WithMessage()
311
311
Assert . Fail ( ) ;
312
312
}
313
313
314
+ #if NET6_0_OR_GREATER
315
+ [ TestMethod ]
316
+ public void Test_Guard_IsTrue_WithHandler_Ok ( )
317
+ {
318
+ Guard . IsTrue ( true , nameof ( Test_Guard_IsTrue_Ok ) , $ "This is an interpolated message: { DateTime . Now . Year } , { "hello" . AsSpan ( ) } ") ;
319
+ }
320
+
321
+ [ TestMethod ]
322
+ public void Test_Guard_IsTrue_WithHandler_Fail ( )
323
+ {
324
+ try
325
+ {
326
+ Guard . IsTrue ( false , nameof ( Test_Guard_IsTrue_WithHandler_Fail ) , $ "This is an interpolated message: { DateTime . Now . Year } , { "hello" . AsSpan ( ) } ") ;
327
+ }
328
+ catch ( ArgumentException e )
329
+ {
330
+ Assert . IsTrue ( e . Message . Contains ( $ "This is an interpolated message: { DateTime . Now . Year } , { "hello" . AsSpan ( ) } ") ) ;
331
+
332
+ return ;
333
+ }
334
+
335
+ // Compiler detects this is unreachable from attribute,
336
+ // but we leave the assertion to double check that's valid
337
+ Assert . Fail ( ) ;
338
+ }
339
+ #endif
340
+
314
341
[ TestMethod ]
315
342
public void Test_Guard_IsFalse_Ok ( )
316
343
{
@@ -342,6 +369,33 @@ public void Test_Guard_IsFalse_Fail_WithMessage()
342
369
Assert . Fail ( ) ;
343
370
}
344
371
372
+ #if NET6_0_OR_GREATER
373
+ [ TestMethod ]
374
+ public void Test_Guard_IsFalse_WithHandler_Ok ( )
375
+ {
376
+ Guard . IsFalse ( false , nameof ( Test_Guard_IsFalse_WithHandler_Ok ) , $ "This is an interpolated message: { DateTime . Now . Year } , { "hello" . AsSpan ( ) } ") ;
377
+ }
378
+
379
+ [ TestMethod ]
380
+ public void Test_Guard_IsFalse_WithHandler_Fail ( )
381
+ {
382
+ try
383
+ {
384
+ Guard . IsFalse ( true , nameof ( Test_Guard_IsFalse_WithHandler_Fail ) , $ "This is an interpolated message: { DateTime . Now . Year } , { "hello" . AsSpan ( ) } ") ;
385
+ }
386
+ catch ( ArgumentException e )
387
+ {
388
+ Assert . IsTrue ( e . Message . Contains ( $ "This is an interpolated message: { DateTime . Now . Year } , { "hello" . AsSpan ( ) } ") ) ;
389
+
390
+ return ;
391
+ }
392
+
393
+ // Compiler detects this is unreachable from attribute,
394
+ // but we leave the assertion to double check that's valid
395
+ Assert . Fail ( ) ;
396
+ }
397
+ #endif
398
+
345
399
[ TestMethod ]
346
400
public void Test_Guard_IsLessThan_Ok ( )
347
401
{
0 commit comments