@@ -309,6 +309,71 @@ public void NullObject()
309
309
}
310
310
}
311
311
312
+ public class IsNotType_Generic_InexactMatch
313
+ {
314
+ [ Fact ]
315
+ public void NullObject ( )
316
+ {
317
+ Assert . IsNotType < object > ( null , exactMatch : false ) ;
318
+ }
319
+
320
+ [ Fact ]
321
+ public void SameType ( )
322
+ {
323
+ var ex = new InvalidCastException ( ) ;
324
+
325
+ var result = Record . Exception ( ( ) => Assert . IsNotType < InvalidCastException > ( ex , exactMatch : false ) ) ;
326
+
327
+ Assert . IsType < IsNotTypeException > ( result ) ;
328
+ Assert . Equal < object > (
329
+ "Assert.IsNotType() Failure: Value is a compatible type" + Environment . NewLine +
330
+ "Expected: typeof(System.InvalidCastException)" + Environment . NewLine +
331
+ "Actual: typeof(System.InvalidCastException)" ,
332
+ result . Message
333
+ ) ;
334
+ }
335
+
336
+ [ Fact ]
337
+ public void BaseType ( )
338
+ {
339
+ var ex = new InvalidCastException ( ) ;
340
+
341
+ var result = Record . Exception ( ( ) => Assert . IsNotType < Exception > ( ex , exactMatch : false ) ) ;
342
+
343
+ Assert . IsType < IsNotTypeException > ( result ) ;
344
+ Assert . Equal < object > (
345
+ "Assert.IsNotType() Failure: Value is a compatible type" + Environment . NewLine +
346
+ "Expected: typeof(System.Exception)" + Environment . NewLine +
347
+ "Actual: typeof(System.InvalidCastException)" ,
348
+ result . Message
349
+ ) ;
350
+ }
351
+
352
+ [ Fact ]
353
+ public void Interface ( )
354
+ {
355
+ var ex = new DisposableClass ( ) ;
356
+
357
+ #pragma warning disable xUnit2018 // TODO: Temporary until xUnit2018 is updated for the new signatures
358
+ var result = Record . Exception ( ( ) => Assert . IsNotType < IDisposable > ( ex , exactMatch : false ) ) ;
359
+ #pragma warning restore xUnit2018
360
+
361
+ Assert . IsType < IsNotTypeException > ( result ) ;
362
+ Assert . Equal < object > (
363
+ "Assert.IsNotType() Failure: Value is a compatible type" + Environment . NewLine +
364
+ "Expected: typeof(System.IDisposable)" + Environment . NewLine +
365
+ "Actual: typeof(TypeAssertsTests+DisposableClass)" ,
366
+ result . Message
367
+ ) ;
368
+ }
369
+
370
+ [ Fact ]
371
+ public void IncompatibleType ( )
372
+ {
373
+ Assert . IsNotType < InvalidCastException > ( new InvalidOperationException ( ) , exactMatch : false ) ;
374
+ }
375
+ }
376
+
312
377
#pragma warning disable xUnit2007 // Do not use typeof expression to check the type
313
378
314
379
public class IsNotType_NonGeneric
@@ -342,6 +407,69 @@ public void NullObject()
342
407
}
343
408
}
344
409
410
+ public class IsNotType_NonGeneric_InexactMatch
411
+ {
412
+ [ Fact ]
413
+ public void NullObject ( )
414
+ {
415
+ Assert . IsNotType ( typeof ( object ) , null , exactMatch : false ) ;
416
+ }
417
+
418
+ [ Fact ]
419
+ public void SameType ( )
420
+ {
421
+ var ex = new InvalidCastException ( ) ;
422
+
423
+ var result = Record . Exception ( ( ) => Assert . IsNotType ( typeof ( InvalidCastException ) , ex , exactMatch : false ) ) ;
424
+
425
+ Assert . IsType < IsNotTypeException > ( result ) ;
426
+ Assert . Equal (
427
+ "Assert.IsNotType() Failure: Value is a compatible type" + Environment . NewLine +
428
+ "Expected: typeof(System.InvalidCastException)" + Environment . NewLine +
429
+ "Actual: typeof(System.InvalidCastException)" ,
430
+ result . Message
431
+ ) ;
432
+ }
433
+
434
+ [ Fact ]
435
+ public void BaseType ( )
436
+ {
437
+ var ex = new InvalidCastException ( ) ;
438
+
439
+ var result = Record . Exception ( ( ) => Assert . IsNotType ( typeof ( Exception ) , ex , exactMatch : false ) ) ;
440
+
441
+ Assert . IsType < IsNotTypeException > ( result ) ;
442
+ Assert . Equal (
443
+ "Assert.IsNotType() Failure: Value is a compatible type" + Environment . NewLine +
444
+ "Expected: typeof(System.Exception)" + Environment . NewLine +
445
+ "Actual: typeof(System.InvalidCastException)" ,
446
+ result . Message
447
+ ) ;
448
+ }
449
+
450
+ [ Fact ]
451
+ public void Interface ( )
452
+ {
453
+ var ex = new DisposableClass ( ) ;
454
+
455
+ var result = Record . Exception ( ( ) => Assert . IsNotType ( typeof ( IDisposable ) , ex , exactMatch : false ) ) ;
456
+
457
+ Assert . IsType < IsNotTypeException > ( result ) ;
458
+ Assert . Equal (
459
+ "Assert.IsNotType() Failure: Value is a compatible type" + Environment . NewLine +
460
+ "Expected: typeof(System.IDisposable)" + Environment . NewLine +
461
+ "Actual: typeof(TypeAssertsTests+DisposableClass)" ,
462
+ result . Message
463
+ ) ;
464
+ }
465
+
466
+ [ Fact ]
467
+ public void IncompatibleType ( )
468
+ {
469
+ Assert . IsNotType ( typeof ( InvalidCastException ) , new InvalidOperationException ( ) , exactMatch : false ) ;
470
+ }
471
+ }
472
+
345
473
#pragma warning restore xUnit2007 // Do not use typeof expression to check the type
346
474
347
475
public class IsType_Generic : TypeAssertsTests
@@ -415,6 +543,76 @@ public void NullObject()
415
543
}
416
544
}
417
545
546
+ public class IsType_Generic_InexactMatch
547
+ {
548
+ [ Fact ]
549
+ public void NullObject ( )
550
+ {
551
+ var result = Record . Exception ( ( ) => Assert . IsType < object > ( null , exactMatch : false ) ) ;
552
+
553
+ Assert . IsType < IsTypeException > ( result ) ;
554
+ Assert . Equal (
555
+ "Assert.IsType() Failure: Value is null" + Environment . NewLine +
556
+ "Expected: typeof(object)" + Environment . NewLine +
557
+ "Actual: null" ,
558
+ result . Message
559
+ ) ;
560
+ }
561
+
562
+ [ Fact ]
563
+ public void SameType ( )
564
+ {
565
+ var ex = new InvalidCastException ( ) ;
566
+
567
+ Assert . IsType < InvalidCastException > ( ex , exactMatch : false ) ;
568
+ }
569
+
570
+ [ Fact ]
571
+ public void BaseType ( )
572
+ {
573
+ var ex = new InvalidCastException ( ) ;
574
+
575
+ Assert . IsType < Exception > ( ex , exactMatch : false ) ;
576
+ }
577
+
578
+ [ Fact ]
579
+ public void Interface ( )
580
+ {
581
+ var ex = new DisposableClass ( ) ;
582
+
583
+ #pragma warning disable xUnit2018 // TODO: Temporary until xUnit2018 is updated for the new signatures
584
+ Assert . IsType < IDisposable > ( ex , exactMatch : false ) ;
585
+ #pragma warning restore xUnit2018
586
+ }
587
+
588
+ [ Fact ]
589
+ public void ReturnsCastObject ( )
590
+ {
591
+ var ex = new InvalidCastException ( ) ;
592
+
593
+ var result = Assert . IsType < InvalidCastException > ( ex , exactMatch : false ) ;
594
+
595
+ Assert . Same ( ex , result ) ;
596
+ }
597
+
598
+ [ Fact ]
599
+ public void IncompatibleType ( )
600
+ {
601
+ var result =
602
+ Record . Exception (
603
+ ( ) => Assert . IsType < InvalidCastException > ( new InvalidOperationException ( ) , exactMatch : false )
604
+ ) ;
605
+
606
+ Assert . IsType < IsTypeException > ( result ) ;
607
+ Assert . Equal (
608
+ "Assert.IsType() Failure: Value is an incompatible type" + Environment . NewLine +
609
+ "Expected: typeof(System.InvalidCastException)" + Environment . NewLine +
610
+ "Actual: typeof(System.InvalidOperationException)" ,
611
+ result . Message
612
+ ) ;
613
+ }
614
+ }
615
+
418
616
#pragma warning disable xUnit2007 // Do not use typeof expression to check the type
419
617
420
618
public class IsType_NonGeneric : TypeAssertsTests
@@ -480,6 +678,74 @@ public void NullObjectThrows()
480
678
}
481
679
}
482
680
681
+ public class IsType_NonGeneric_InexactMatch
682
+ {
683
+ [ Fact ]
684
+ public void NullObject ( )
685
+ {
686
+ var result = Record . Exception ( ( ) => Assert . IsType ( typeof ( object ) , null , exactMatch : false ) ) ;
687
+
688
+ Assert . IsType < IsTypeException > ( result ) ;
689
+ Assert . Equal (
690
+ "Assert.IsType() Failure: Value is null" + Environment . NewLine +
691
+ "Expected: typeof(object)" + Environment . NewLine +
692
+ "Actual: null" ,
693
+ result . Message
694
+ ) ;
695
+ }
696
+
697
+ [ Fact ]
698
+ public void SameType ( )
699
+ {
700
+ var ex = new InvalidCastException ( ) ;
701
+
702
+ Assert . IsType ( typeof ( InvalidCastException ) , ex , exactMatch : false ) ;
703
+ }
704
+
705
+ [ Fact ]
706
+ public void BaseType ( )
707
+ {
708
+ var ex = new InvalidCastException ( ) ;
709
+
710
+ Assert . IsType ( typeof ( Exception ) , ex , exactMatch : false ) ;
711
+ }
712
+
713
+ [ Fact ]
714
+ public void Interface ( )
715
+ {
716
+ var ex = new DisposableClass ( ) ;
717
+
718
+ Assert . IsType ( typeof ( IDisposable ) , ex , exactMatch : false ) ;
719
+ }
720
+
721
+ [ Fact ]
722
+ public void ReturnsCastObject ( )
723
+ {
724
+ var ex = new InvalidCastException ( ) ;
725
+
726
+ var result = Assert . IsType < InvalidCastException > ( ex , exactMatch : false ) ;
727
+
728
+ Assert . Same ( ex , result ) ;
729
+ }
730
+
731
+ [ Fact ]
732
+ public void IncompatibleType ( )
733
+ {
734
+ var result =
735
+ Record . Exception (
736
+ ( ) => Assert . IsType ( typeof ( InvalidCastException ) , new InvalidOperationException ( ) , exactMatch : false )
737
+ ) ;
738
+
739
+ Assert . IsType < IsTypeException > ( result ) ;
740
+ Assert . Equal (
741
+ "Assert.IsType() Failure: Value is an incompatible type" + Environment . NewLine +
742
+ "Expected: typeof(System.InvalidCastException)" + Environment . NewLine +
743
+ "Actual: typeof(System.InvalidOperationException)" ,
744
+ result . Message
745
+ ) ;
746
+ }
747
+ }
748
+
483
749
#pragma warning restore xUnit2007 // Do not use typeof expression to check the type
484
750
485
751
class DisposableClass : IDisposable
0 commit comments