8000 Use Assert.Throws instead of home-grown · dotnet/SqlClient@232fefb · GitHub
[go: up one dir, main page]

Skip to content

Commit 232fefb

Browse files
MichelZbenrr101
authored andcommitted
Use Assert.Throws instead of home-grown
1 parent 4b6cefc commit 232fefb

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ConnectionExceptionTest.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,16 @@ public void TestConnectionStateWithErrorClass20()
3535
Assert.Equal(System.Data.ConnectionState.Open, conn.State);
3636

3737
server.Dispose();
38-
try
39-
{
40-
int result2 = cmd.ExecuteNonQuery();
41-
}
42-
catch (SqlException ex)
43-
{
44-
Assert.Equal(11, ex.Class);
45-
Assert.NotNull(ex.InnerException);
46-
SqlException innerEx = Assert.IsType<SqlException>(ex.InnerException);
47-
Assert.Equal(20, innerEx.Class);
48-
Assert.StartsWith("A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.", innerEx.Message);
49-
// Since the server is not accessible driver can close the close the connection
50-
// It is user responsibilty to maintain the connection.
51-
Assert.Equal(System.Data.ConnectionState.Closed, conn.State);
52-
}
38+
39+
var exception = Assert.Throws<SqlException>(() => cmd.ExecuteNonQuery());
40+
Assert.Equal(11, exception.Class);
41+
Assert.NotNull(exception.InnerException);
42+
SqlException innerEx = Assert.IsType<SqlException>(exception.InnerException);
43+
Assert.Equal(20, innerEx.Class);
44+
Assert.StartsWith("A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.", innerEx.Message);
45+
// Since the server is not accessible driver can close the close the connection
46+
// It is user responsibilty to maintain the connection.
47+
Assert.Equal(System.Data.ConnectionState.Closed, conn.State);
5348
}
5449

5550
[Fact]

0 commit comments

Comments
 (0)
0