@@ -29,79 +29,46 @@ public void TearDown()
2929 }
3030
3131 [ TestMethod ]
32- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
3332 public void Open_Connection_Without_Connection_String ( )
3433 {
3534 using var connection = new JetConnection ( ) ;
36- connection . Open ( ) ;
35+ Assert . Throws < InvalidOperationException > ( ( ) => connection . Open ( ) ) ;
3736 }
3837
3938 [ TestMethod ]
40- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
4139 public void ExecuteReader_From_Closed_Connection ( )
4240 {
4341 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) , Helpers . DataAccessProviderFactory ) ;
44- try
45- {
46- using var command = connection . CreateCommand ( $ "select * from `{ JetConnection . DefaultDualTableName } `") ;
47- command . ExecuteReader ( ) ;
48- }
49- catch ( Exception e )
50- {
51- Assert . AreEqual ( "\" ExecuteReader\" requires a connection in Open state. Current connection state is Closed" , e . Message ) ;
52- throw ;
53- }
42+ using var command = connection . CreateCommand ( $ "select * from `{ JetConnection . DefaultDualTableName } `") ;
43+ var ex = Assert . Throws < InvalidOperationException > ( ( ) => command . ExecuteReader ( ) ) ;
44+ Assert . AreEqual ( "\" ExecuteReader\" requires a connection in Open state. Current connection state is Closed" , ex . Message ) ;
5445 }
5546
5647 [ TestMethod ]
57- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
5848 public void ExecuteNonQuery_From_Closed_Connection ( )
5949 {
6050 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) , Helpers . DataAccessProviderFactory ) ;
61- try
62- {
63- using var command = connection . CreateCommand ( $ "select * from `{ JetConnection . DefaultDualTableName } `") ;
64- command . ExecuteNonQuery ( ) ;
65- }
66- catch ( Exception e )
67- {
68- Assert . AreEqual ( "\" ExecuteNonQuery\" requires a connection in Open state. Current connection state is Closed" , e . Message ) ;
69- throw ;
70- }
51+ using var command = connection . CreateCommand ( $ "select * from `{ JetConnection . DefaultDualTableName } `") ;
52+ var ex = Assert . Throws < InvalidOperationException > ( ( ) => command . ExecuteNonQuery ( ) ) ;
53+ Assert . AreEqual ( "\" ExecuteNonQuery\" requires a connection in Open state. Current connection state is Closed" , ex . Message ) ;
7154 }
7255
7356 [ TestMethod ]
74- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
7557 public void ExecuteScalar_From_Closed_Connection ( )
7658 {
7759 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) , Helpers . DataAccessProviderFactory ) ;
78- try
79- {
80- using var command = connection . CreateCommand ( $ "select * from `{ JetConnection . DefaultDualTableName } `") ;
81- command . ExecuteScalar ( ) ;
82- }
83- catch ( Exception e )
84- {
85- Assert . AreEqual ( "\" ExecuteScalar\" requires a connection in Open state. Current connection state is Closed" , e . Message ) ;
86- throw ;
87- }
60+ using var command = connection . CreateCommand ( $ "select * from `{ JetConnection . DefaultDualTableName } `") ;
61+ var ex = Assert . Throws < InvalidOperationException > ( ( ) => command . ExecuteScalar ( ) ) ;
62+ Assert . AreEqual ( "\" ExecuteScalar\" requires a connection in Open state. Current connection state is Closed" , ex . Message ) ;
8863 }
8964
9065 [ TestMethod ]
91- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
9266 public void Prepare_From_Closed_Connection ( )
9367 {
9468 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) , Helpers . DataAccessProviderFactory ) ;
95- try
96- {
97- using var command = connection . CreateCommand ( $ "select * from `{ JetConnection . DefaultDualTableName } `") ;
98- command . Prepare ( ) ;
99- }
100- catch ( Exception e )
101- {
102- Assert . AreEqual ( "\" Prepare\" requires a connection in Open state. Current connection state is Closed" , e . Message ) ;
103- throw ;
104- }
69+ using var command = connection . CreateCommand ( $ "select * from `{ JetConnection . DefaultDualTableName } `") ;
70+ var ex = Assert . Throws < InvalidOperationException > ( ( ) => command . Prepare ( ) ) ;
71+ Assert . AreEqual ( "\" Prepare\" requires a connection in Open state. Current connection state is Closed" , ex . Message ) ;
10572 }
10673
10774 [ TestMethod ]
@@ -118,28 +85,25 @@ public void GetDataReader_From_Open_Connection()
11885 }
11986
12087 [ TestMethod ]
121- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
12288 public void GetTransaction_From_Closed_Connection ( )
12389 {
12490 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) ) ;
125- using var transaction = connection . BeginTransaction ( ) ;
91+ Assert . Throws < InvalidOperationException > ( ( ) => connection . BeginTransaction ( ) ) ;
12692 }
12793
12894 [ TestMethod ]
129- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
13095 public void Change_Database_From_Closed_Connection ( )
13196 {
13297 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) ) ;
133- connection . ChangeDatabase ( "abcd" ) ;
98+ Assert . Throws < InvalidOperationException > ( ( ) => connection . ChangeDatabase ( "abcd" ) ) ;
13499 }
135100
136101 [ TestMethod ]
137- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
138102 public void Change_Database_From_Open_Connection ( )
139103 {
140104 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) ) ;
141105 connection . Open ( ) ;
142- connection . ChangeDatabase ( "abcd" ) ;
106+ Assert . Throws < InvalidOperationException > ( ( ) => connection . ChangeDatabase ( "abcd" ) ) ;
143107 }
144108
145109 [ TestMethod ]
@@ -150,12 +114,11 @@ public void Change_ConnectionString_From_Closed_Connection()
150114 }
151115
152116 [ TestMethod ]
153- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
154117 public void Change_ConnectionString_From_Open_Connection ( )
155118 {
156119 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) ) ;
157120 connection . Open ( ) ;
158- connection . ConnectionString = DummyStoreName ;
121+ Assert . Throws < InvalidOperationException > ( ( ) => connection . ConnectionString = DummyStoreName ) ;
159122 }
160123
161124 [ TestMethod ]
@@ -217,23 +180,22 @@ public void Read_ConnectionString_From_Open_Connection()
217180 public void Read_Database_From_Closed_Connection ( )
218181 {
219182 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) ) ;
220- Assert . IsTrue ( connection . Database == string . Empty ) ;
183+ Assert . AreEqual ( string . Empty , connection . Database ) ;
221184 }
222185
223186 [ TestMethod ]
224187 public void Read_Database_From_Open_Connection ( )
225188 {
226189 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) ) ;
227190 connection . Open ( ) ;
228- Assert . IsTrue ( connection . Database == string . Empty ) ;
191+ Assert . AreEqual ( string . Empty , connection . Database ) ;
229192 }
230193
231194 [ TestMethod ]
232- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
233195 public void Read_ServerVersion_From_Closed_Connection ( )
234196 {
235197 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) ) ;
236- Assert . IsTrue ( connection . ServerVersion == string . Empty ) ;
198+ Assert . Throws < InvalidOperationException > ( ( ) => _ = connection . ServerVersion ) ;
237199 }
238200
239201 [ TestMethod ]
@@ -249,7 +211,7 @@ public void Read_Database_From_Disposed_Connection()
249211 {
250212 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) ) ;
251213 connection . Dispose ( ) ;
252- Assert . IsTrue ( connection . Database == string . Empty ) ;
214+ Assert . AreEqual ( string . Empty , connection . Database ) ;
253215 }
254216
255217 [ TestMethod ]
@@ -335,7 +297,7 @@ public void Read_Connection_String_After_Dispose()
335297 }
336298
337299 [ TestMethod ]
338- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
300+ // [ExpectedException(typeof(InvalidOperationException))]
339301 public void OpenSeveralTimes ( )
340302 {
341303 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) ) ;
@@ -410,11 +372,10 @@ public void GetSchema_From_Open_Connection()
410372 }
411373
412374 [ TestMethod ]
413- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
414375 public void GetSchema_From_Closed_Connection ( )
415376 {
416377 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) ) ;
417- connection . GetSchema ( ) ;
378+ Assert . Throws < InvalidOperationException > ( ( ) => connection . GetSchema ( ) ) ;
418379 }
419380
420381 [ TestMethod ]
@@ -488,7 +449,6 @@ public void Transaction_Execute_Close_Open()
488449 }
489450
490451 [ TestMethod ]
491- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
492452 public void Transaction_Execute_Close_Open_Commit ( )
493453 {
494454 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) ) ;
@@ -505,7 +465,7 @@ public void Transaction_Execute_Close_Open_Commit()
505465 connection . Close ( ) ;
506466 JetConnection . ClearAllPools ( ) ;
507467 connection . Open ( ) ;
508- transaction . Commit ( ) ;
468+ Assert . Throws < InvalidOperationException > ( ( ) => transaction . Commit ( ) ) ;
509469
510470 using ( var command = connection . CreateCommand ( "select count(*) from SimpleTable" ) )
511471 {
@@ -539,7 +499,6 @@ public void Transaction_Execute_Close_Open_Transaction()
539499 }
540500
541501 [ TestMethod ]
542- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
543502 public void Transaction_Transaction ( )
544503 {
545504 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) ) ;
@@ -550,15 +509,8 @@ public void Transaction_Transaction()
550509 command . Transaction = firstTransaction ;
551510 command . ExecuteScalar ( ) ;
552511
553- try
554- {
555- using var secondTransaction = connection . BeginTransaction ( ) ;
556- }
557- catch ( Exception e )
558- {
559- Assert . AreEqual ( "JetConnection does not support parallel transactions" , e . Message ) ;
560- throw ;
561- }
512+ var ex = Assert . Throws < InvalidOperationException > ( ( ) => connection . BeginTransaction ( ) ) ;
513+ Assert . AreEqual ( "JetConnection does not support parallel transactions" , ex . Message ) ;
562514 }
563515
564516 [ TestMethod ]
@@ -620,7 +572,6 @@ public void Transaction_Rollback_Transaction()
620572 }
621573
622574 [ TestMethod ]
623- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
624575 public void Transaction_Execute_Commit_Execute_Transaction ( )
625576 {
626577 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) ) ;
@@ -640,11 +591,10 @@ public void Transaction_Execute_Commit_Execute_Transaction()
640591 command . Transaction = transaction ;
641592 command . ExecuteScalar ( ) ;
642593 }
643- transaction . Commit ( ) ;
594+ Assert . Throws < InvalidOperationException > ( ( ) => transaction . Commit ( ) ) ;
644595 }
645596
646597 [ TestMethod ]
647- [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
648598 public void Transaction_Execute_Commit_Commit ( )
649599 {
650600 using var connection = new JetConnection ( JetConnection . GetConnectionString ( StoreName , Helpers . DataAccessProviderFactory ) ) ;
@@ -655,7 +605,7 @@ public void Transaction_Execute_Commit_Commit()
655605 command . Transaction = transaction ;
656606 command . ExecuteScalar ( ) ;
657607 transaction . Commit ( ) ;
658- transaction . Commit ( ) ;
608+ Assert . Throws < InvalidOperationException > ( ( ) => transaction . Commit ( ) ) ;
659609 }
660610 }
661611}
0 commit comments