@@ -83,14 +83,8 @@ public void
8383 session . Store ( secondDocument ) ;
8484
8585 //3. Unique Exception Was thrown
86- try
87- {
88- session . SaveChanges ( ) ;
89- }
90- catch ( DocumentAlreadyExistsException exception )
91- {
92- ( ( PostgresException ) exception . InnerException ) ? . SqlState . ShouldBe ( UniqueSqlState ) ;
93- }
86+ var exception = Should . Throw < DocumentAlreadyExistsException > ( ( ) => session . SaveChanges ( ) ) ;
87+ ( ( PostgresException ) exception . InnerException ) ? . SqlState . ShouldBe ( UniqueSqlState ) ;
9488 }
9589
9690 [ Fact ]
@@ -109,14 +103,8 @@ public void
109103 session . Store ( secondDocument ) ;
110104
111105 //3. Unique Exception Was thrown
112- try
113- {
114- session . SaveChanges ( ) ;
115- }
116- catch ( DocumentAlreadyExistsException exception )
117- {
118- ( ( PostgresException ) exception . InnerException ) ? . SqlState . ShouldBe ( UniqueSqlState ) ;
119- }
106+ var exception = Should . Throw < DocumentAlreadyExistsException > ( ( ) => session . SaveChanges ( ) ) ;
107+ ( ( PostgresException ) exception . InnerException ) ? . SqlState . ShouldBe ( UniqueSqlState ) ;
120108 }
121109
122110 [ Fact ]
@@ -139,14 +127,8 @@ public void
139127 session . Events . Append ( secondEvent . UserId , secondEvent ) ;
140128
141129 //3. Unique Exception Was thrown
142- try
143- {
144- session . SaveChanges ( ) ;
145- }
146- catch ( MartenCommandException exception )
147- {
148- ( ( PostgresException ) exception . InnerException ) ? . SqlState . ShouldBe ( UniqueSqlState ) ;
149- }
130+ var exception = Should . Throw < MartenCommandException > ( ( ) => session . SaveChanges ( ) ) ;
131+ ( ( PostgresException ) exception . InnerException ) ? . SqlState . ShouldBe ( UniqueSqlState ) ;
150132 }
151133
152134 [ Fact ]
@@ -166,13 +148,7 @@ public void
166148 session . Events . Append ( secondEvent . UserId , secondEvent ) ;
167149
168150 //3. Unique Exception Was thrown
169- try
170- {
171- session . SaveChanges ( ) ;
172- }
173- catch ( DocumentAlreadyExistsException exception )
174- {
175- ( ( PostgresException ) exception . InnerException ) ? . SqlState . ShouldBe ( UniqueSqlState ) ;
176- }
151+ var exception = Should . Throw < DocumentAlreadyExistsException > ( ( ) => session . SaveChanges ( ) ) ;
152+ ( ( PostgresException ) exception . InnerException ) ? . SqlState . ShouldBe ( UniqueSqlState ) ;
177153 }
178154}
0 commit comments