@@ -4,15 +4,11 @@ public class AsyncMatchExpressionTests
44{
55 [ Fact ( DisplayName = "AsyncMatch.Create should never return null" ) ]
66 public void MatchCreateShouldNeverReturnNull ( ) =>
7- AsyncMatch . Create < int , string > ( )
8- . Should ( )
9- . NotBeNull ( ) ;
7+ Assert . NotNull ( AsyncMatch . Create < int , string > ( ) ) ;
108
119 [ Property ( DisplayName = "AsyncMatch.Create with fall-through should never return null" ) ]
1210 public void MatchCreateWithFallthroughShouldNeverReturnNull ( bool fallthroughByDefault ) =>
13- AsyncMatch . Create < int , string > ( fallthroughByDefault )
14- . Should ( )
15- . NotBeNull ( ) ;
11+ Assert . NotNull ( AsyncMatch . Create < int , string > ( fallthroughByDefault ) ) ;
1612
1713 [ Property ( DisplayName = "Match should match patterns correctly with async pattern and async action" ) ]
1814 public async Task < Property > MatchShouldMatchPatternsCorrectlyWithAsyncPatternAndAsyncAction (
@@ -144,16 +140,18 @@ public async Task MatchShouldThrowIfNoMatchFound(Func<string, Task<bool>> predic
144140 {
145141 var pattern = AsyncPattern . CreatePattern ( predicate ) ;
146142
147- var action = ( ) => AsyncMatch . Create < string , bool > ( )
148- . Case ( pattern , _ => true )
149- . ExecuteAsync ( value ) ;
143+ Task action ( ) =>
144+ AsyncMatch . Create < string , bool > ( )
145+ . Case ( pattern , _ => true )
146+ . ExecuteAsync ( value ) ;
150147
151148 if ( ( await pattern . MatchAsync ( value ) ) . IsSuccessful )
152149 {
153- await action . Should ( ) . NotThrowAsync < MatchException > ( ) ;
150+ var exception = await Record . ExceptionAsync ( action ) ;
151+ Assert . Null ( exception ) ;
154152 } else
155153 {
156- await action . Should ( ) . ThrowAsync < MatchException > ( ) ;
154+ await Assert . ThrowsAsync < MatchException > ( action ) ;
157155 }
158156 }
159157
@@ -162,11 +160,13 @@ public async Task NonStrictMatchShouldNotThrowIfNoMatchFound(Func<string, Task<b
162160 {
163161 var pattern = AsyncPattern . CreatePattern ( predicate ) ;
164162
165- var action = ( ) => AsyncMatch . Create < string , bool > ( )
166- . Case ( pattern , _ => true )
167- . ExecuteNonStrictAsync ( value ) ;
163+ Task action ( ) =>
164+ AsyncMatch . Create < string , bool > ( )
165+ . Case ( pattern , _ => true )
166+ . ExecuteNonStrictAsync ( value ) ;
168167
169- await action . Should ( ) . NotThrowAsync < MatchException > ( ) ;
168+ var exception = await Record . ExceptionAsync ( action ) ;
169+ Assert . Null ( exception ) ;
170170 }
171171
172172 [ Property ( DisplayName = "Match with fall-through should match patterns correctly" ) ]
@@ -439,16 +439,18 @@ public async Task MatchToFunctionShouldThrowIfNoMatchFound(Func<string, Task<boo
439439 {
440440 var pattern = AsyncPattern . CreatePattern ( predicate ) ;
441441
442- var action = ( ) => AsyncMatch . Create < string , bool > ( )
443- . Case ( pattern , _ => true )
444- . ToFunction ( ) ( value ) ;
442+ Task action ( ) =>
443+ AsyncMatch . Create < string , bool > ( )
444+ . Case ( pattern , _ => true )
445+ . ToFunction ( ) ( value ) ;
445446
446447 if ( ( await pattern . MatchAsync ( value ) ) . IsSuccessful )
447448 {
448- await action . Should ( ) . NotThrowAsync < MatchException > ( ) ;
449+ var exception = await Record . ExceptionAsync ( action ) ;
450+ Assert . Null ( exception ) ;
449451 } else
450452 {
451- await action . Should ( ) . ThrowAsync < MatchException > ( ) ;
453+ await Assert . ThrowsAsync < MatchException > ( action ) ;
452454 }
453455 }
454456
@@ -459,11 +461,13 @@ public async Task NonStrictMatchToFunctionShouldNotThrowIfNoMatchFound(
459461 {
460462 var pattern = AsyncPattern . CreatePattern ( predicate ) ;
461463
462- var action = ( ) => AsyncMatch . Create < string , bool > ( )
463- . Case ( pattern , _ => true )
464- . ToNonStrictFunction ( ) ( value ) ;
464+ Task action ( ) =>
465+ AsyncMatch . Create < string , bool > ( )
466+ . Case ( pattern , _ => true )
467+ . ToNonStrictFunction ( ) ( value ) ;
465468
466- await action . Should ( ) . NotThrowAsync < MatchException > ( ) ;
469+ var exception = await Record . ExceptionAsync ( action ) ;
470+ Assert . Null ( exception ) ;
467471 }
468472
469473 [ Property ( DisplayName = "ToFunction with fall-through should match patterns correctly" ) ]
@@ -652,117 +656,77 @@ public async Task<Property> MatchToFunctionWithFallthroughShouldReturnEmptyEnume
652656 }
653657
654658 [ Fact ( DisplayName = "Match should throw if async pattern is null" ) ]
655- public void MatchShouldThrowIfAsyncPatternIsNull ( )
656- {
657- var action = ( ) => AsyncMatch . Create < string , bool > ( )
658- . Case ( ( IAsyncPattern < string , string > ) null , _ => true ) ;
659-
660- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
661- }
659+ public void MatchShouldThrowIfAsyncPatternIsNull ( ) =>
660+ Assert . Throws < ArgumentNullException > ( ( ) =>
661+ AsyncMatch . Create < string , bool > ( ) . Case ( ( IAsyncPattern < string , string > ) null , _ => true ) ) ;
662662
663663 [ Fact ( DisplayName = "Match should throw if sync pattern is null with async action" ) ]
664- public void MatchShouldThrowIfSyncPatternIsNullWithAsyncAction ( )
665- {
666- var action = ( ) => AsyncMatch . Create < string , bool > ( )
667- . Case ( ( IPattern < string , string > ) null , _ => Task . FromResult ( true ) ) ;
668-
669- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
670- }
664+ public void MatchShouldThrowIfSyncPatternIsNullWithAsyncAction ( ) =>
665+ Assert . Throws < ArgumentNullException > ( ( ) =>
666+ AsyncMatch . Create < string , bool > ( ) . Case ( ( IPattern < string , string > ) null , _ => Task . FromResult ( true ) ) ) ;
671667
672668 [ Fact ( DisplayName = "Match should throw if async pattern is null with async action" ) ]
673- public void MatchShouldThrowIfAsyncPatternIsNullWithAsyncAction ( )
674- {
675- var action = ( ) => AsyncMatch . Create < string , bool > ( )
676- . Case ( ( IAsyncPattern < string , string > ) null , _ => Task . FromResult ( true ) ) ;
677-
678- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
679- }
669+ public void MatchShouldThrowIfAsyncPatternIsNullWithAsyncAction ( ) =>
670+ Assert . Throws < ArgumentNullException > ( ( ) => AsyncMatch . Create < string , bool > ( )
671+ . Case ( ( IAsyncPattern < string , string > ) null , _ => Task . FromResult ( true ) ) ) ;
680672
681673 [ Fact ( DisplayName = "Match should throw if sync pattern is null with sync action" ) ]
682- public void MatchShouldThrowIfSyncPatternIsNullWithSyncAction ( )
683- {
684- var action = ( ) => AsyncMatch . Create < string , bool > ( )
685- . Case ( ( IPattern < string , string > ) null , _ => true ) ;
686-
687- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
688- }
674+ public void MatchShouldThrowIfSyncPatternIsNullWithSyncAction ( ) =>
675+ Assert . Throws < ArgumentNullException > ( ( ) =>
676+ AsyncMatch . Create < string , bool > ( ) . Case ( ( IPattern < string , string > ) null , _ => true ) ) ;
689677
690678 [ Property ( DisplayName = "Match should throw if case function is null with sync action" ) ]
691679 public void MatchShouldThrowIfCaseFunctionIsNullWithSyncAction ( Func < string , Task < bool > > predicate )
692680 {
693681 var pattern = AsyncPattern . CreatePattern ( predicate ) ;
694-
695- var action = ( ) => AsyncMatch . Create < string , bool > ( )
696- . Case ( pattern , ( Func < string , Task < bool > > ) null ) ;
697-
698- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
682+ Assert . Throws < ArgumentNullException > ( ( ) =>
683+ AsyncMatch . Create < string , bool > ( ) . Case ( pattern , ( Func < string , Task < bool > > ) null ) ) ;
699684 }
700685
701686 [ Fact ( DisplayName = "Match Should throw if case type async function is null" ) ]
702- public void MatchShouldThrowIfCaseTypeAsyncFunctionIsNull ( )
703- {
704- var action = ( ) => AsyncMatch . Create < string , bool > ( )
705- . Case ( ( Func < string , Task < bool > > ) null ) ;
706-
707- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
708- }
687+ public void MatchShouldThrowIfCaseTypeAsyncFunctionIsNull ( ) =>
688+ Assert . Throws < ArgumentNullException > ( ( ) =>
689+ AsyncMatch . Create < string , bool > ( ) . Case ( ( Func < string , Task < bool > > ) null ) ) ;
709690
710691 [ Fact ( DisplayName = "Match should throw if case type sync function is null" ) ]
711- public void MatchShouldThrowIfCaseTypeSyncFunctionIsNull ( )
712- {
713- var action = ( ) => AsyncMatch . Create < string , bool > ( )
714- . Case ( ( Func < string , bool > ) null ) ;
715-
716- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
717- }
692+ public void MatchShouldThrowIfCaseTypeSyncFunctionIsNull ( ) =>
693+ Assert . Throws < ArgumentNullException > ( ( ) =>
694+ AsyncMatch . Create < string , bool > ( ) . Case ( ( Func < string , bool > ) null ) ) ;
718695
719696 [ Property ( DisplayName = "Match should throw if async pattern with fall-through is null with async action" ) ]
720697 public void MatchShouldThrowIfAsyncPatternWithFallthroughIsNullWithAsyncAction ( bool fallthrough )
721698 {
722- var action = ( ) => AsyncMatch . Create < string , bool > ( )
723- . Case ( ( IAsyncPattern < string , string > ) null , fallthrough , _ => Task . FromResult ( true ) ) ;
724-
725- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
699+ Assert . Throws < ArgumentNullException > ( ( ) =>
700+ AsyncMatch . Create < string , bool > ( )
701+ . Case ( ( IAsyncPattern < string , string > ) null , fallthrough , _ => Task . FromResult ( true ) ) ) ;
726702 }
727703
728704 [ Property ( DisplayName = "Match should throw if async pattern with fall-through is null with sync action" ) ]
729- public void MatchShouldThrowIfAsyncPatternWithFallthroughIsNullWithSyncAction ( bool fallthrough )
730- {
731- var action = ( ) => AsyncMatch . Create < string , bool > ( )
732- . Case ( ( IAsyncPattern < string , string > ) null , fallthrough , _ => true ) ;
733-
734- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
735- }
705+ public void MatchShouldThrowIfAsyncPatternWithFallthroughIsNullWithSyncAction ( bool fallthrough ) =>
706+ Assert . Throws < ArgumentNullException > ( ( ) =>
707+ AsyncMatch . Create < string , bool > ( ) . Case ( ( IAsyncPattern < string , string > ) null , fallthrough , _ => true ) ) ;
736708
737709 [ Property ( DisplayName = "Match should throw if sync pattern with fall-through is null with async action" ) ]
738710 public void MatchShouldThrowIfSyncPatternWithFallthroughIsNullWithAsyncAction ( bool fallthrough )
739711 {
740- var action = ( ) => AsyncMatch . Create < string , bool > ( )
741- . Case ( ( IPattern < string , string > ) null , fallthrough , _ => Task . FromResult ( true ) ) ;
742-
743- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
712+ Assert . Throws < ArgumentNullException > ( ( ) =>
713+ AsyncMatch . Create < string , bool > ( )
714+ . Case ( ( IPattern < string , string > ) null , fallthrough , _ => Task . FromResult ( true ) ) ) ;
744715 }
745716
746717 [ Property ( DisplayName = "Match should throw if sync pattern with fall-through is null with sync action" ) ]
747- public void MatchShouldThrowIfSyncPatternWithFallthroughIsNullWithSyncAction ( bool fallthrough )
748- {
749- var action = ( ) => AsyncMatch . Create < string , bool > ( )
750- . Case ( ( IPattern < string , string > ) null , fallthrough , _ => true ) ;
751-
752- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
753- }
718+ public void MatchShouldThrowIfSyncPatternWithFallthroughIsNullWithSyncAction ( bool fallthrough ) =>
719+ Assert . Throws < ArgumentNullException > ( ( ) =>
720+ AsyncMatch . Create < string , bool > ( ) . Case ( ( IPattern < string , string > ) null , fallthrough , _ => true ) ) ;
754721
755722 [ Property ( DisplayName = "Match should throw if case async function with fall-through is null with async pattern" ) ]
756723 public void MatchShouldThrowIfCaseAsyncFunctionWithFallthroughIsNullWithAsyncPattern (
757724 Func < string , Task < bool > > predicate ,
758725 bool fallthrough )
759726 {
760727 var pattern = AsyncPattern . CreatePattern ( predicate ) ;
761-
762- var action = ( ) => AsyncMatch . Create < string , bool > ( )
763- . Case ( pattern , fallthrough , ( Func < string , Task < bool > > ) null ) ;
764-
765- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
728+ Assert . Throws < ArgumentNullException > ( ( ) =>
729+ AsyncMatch . Create < string , bool > ( ) . Case ( pattern , fallthrough , ( Func < string , Task < bool > > ) null ) ) ;
766730 }
767731
768732 [ Property ( DisplayName = "Match should throw if case sync function with fall-through is null with async pattern" ) ]
@@ -771,11 +735,8 @@ public void MatchShouldThrowIfCaseSyncFunctionWithFallthroughIsNullWithAsyncPatt
771735 bool fallthrough )
772736 {
773737 var pattern = AsyncPattern . CreatePattern ( predicate ) ;
774-
775- var action = ( ) => AsyncMatch . Create < string , bool > ( )
776- . Case ( pattern , fallthrough , ( Func < string , bool > ) null ) ;
777-
778- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
738+ Assert . Throws < ArgumentNullException > ( ( ) =>
739+ AsyncMatch . Create < string , bool > ( ) . Case ( pattern , fallthrough , ( Func < string , bool > ) null ) ) ;
779740 }
780741
781742 [ Property ( DisplayName = "Match should throw if case async function with fallthrough is null with sync pattern" ) ]
@@ -784,11 +745,8 @@ public void MatchShouldThrowIfCaseAsyncFunctionWithFallthroughIsNullWithSyncPatt
784745 bool fallthrough )
785746 {
786747 var pattern = Pattern . CreatePattern ( predicate ) ;
787-
788- var action = ( ) => AsyncMatch . Create < string , bool > ( )
789- . Case ( pattern , fallthrough , ( Func < string , Task < bool > > ) null ) ;
790-
791- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
748+ Assert . Throws < ArgumentNullException > ( ( ) =>
749+ AsyncMatch . Create < string , bool > ( ) . Case ( pattern , fallthrough , ( Func < string , Task < bool > > ) null ) ) ;
792750 }
793751
794752 [ Property ( DisplayName = "Match should throw if case sync function with fallthrough is null with sync pattern" ) ]
@@ -797,28 +755,17 @@ public void MatchShouldThrowIfCaseSyncFunctionWithFallthroughIsNullWithSyncPatte
797755 bool fallthrough )
798756 {
799757 var pattern = Pattern . CreatePattern ( predicate ) ;
800-
801- var action = ( ) => AsyncMatch . Create < string , bool > ( )
802- . Case ( pattern , fallthrough , ( Func < string , bool > ) null ) ;
803-
804- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
758+ Assert . Throws < ArgumentNullException > ( ( ) =>
759+ AsyncMatch . Create < string , bool > ( ) . Case ( pattern , fallthrough , ( Func < string , bool > ) null ) ) ;
805760 }
806761
807762 [ Property ( DisplayName = "Match should throw if case type async function with fall-through is null" ) ]
808- public void MatchShouldThrowIfCaseTypeAsyncFunctionWithFallthroughIsNull ( bool fallthrough )
809- {
810- var action = ( ) => AsyncMatch . Create < string , bool > ( )
811- . Case ( fallthrough , ( Func < string , Task < bool > > ) null ) ;
812-
813- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
814- }
763+ public void MatchShouldThrowIfCaseTypeAsyncFunctionWithFallthroughIsNull ( bool fallthrough ) =>
764+ Assert . Throws < ArgumentNullException > ( ( ) =>
765+ AsyncMatch . Create < string , bool > ( ) . Case ( fallthrough , ( Func < string , Task < bool > > ) null ) ) ;
815766
816767 [ Property ( DisplayName = "Match should throw if case type sync function with fallthrough is null" ) ]
817- public void MatchShouldThrowIfCaseTypeSyncFunctionWithFallthroughIsNull ( bool fallthrough )
818- {
819- var action = ( ) => AsyncMatch . Create < string , bool > ( )
820- . Case ( fallthrough , ( Func < string , bool > ) null ) ;
821-
822- action . Should ( ) . Throw < ArgumentNullException > ( ) ;
823- }
768+ public void MatchShouldThrowIfCaseTypeSyncFunctionWithFallthroughIsNull ( bool fallthrough ) =>
769+ Assert . Throws < ArgumentNullException > ( ( ) =>
770+ AsyncMatch . Create < string , bool > ( ) . Case ( fallthrough , ( Func < string , bool > ) null ) ) ;
824771}
0 commit comments