Skip to content

Commit

Permalink
Test | Replacing try/catch with xUnit Throws. (#2054)
Browse files Browse the repository at this point in the history
  • Loading branch information
Javad authored Jun 8, 2023
1 parent 288a70c commit e3787ff
Showing 1 changed file with 7 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void TransientFaultTest(uint errorCode)
[InlineData(42108)]
[InlineData(42109)]
[PlatformSpecific(TestPlatforms.Windows)]
public async Task TransientFaultDisabledTestAsync(uint errorCode)
public void TransientFaultDisabledTestAsync(uint errorCode)
{
using TransientFaultTDSServer server = TransientFaultTDSServer.StartTestServer(true, true, errorCode);
SqlConnectionStringBuilder builder = new()
Expand All @@ -99,17 +99,9 @@ public async Task TransientFaultDisabledTestAsync(uint errorCode)
};

using SqlConnection connection = new(builder.ConnectionString);
try
{
await connection.OpenAsync();
Assert.False(true, "Connection should not have opened.");
}
catch (SqlException e)
{
// FATAL Error, should result in closed connection.
Assert.Equal(20, e.Class);
Assert.Equal(ConnectionState.Closed, connection.State);
}
Task<SqlException> e = Assert.ThrowsAsync<SqlException>(async () => await connection.OpenAsync());
Assert.Equal(20, e.Result.Class);
Assert.Equal(ConnectionState.Closed, connection.State);
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArmProcess))]
Expand All @@ -129,17 +121,9 @@ public void TransientFaultDisabledTest(uint errorCode)
};

using SqlConnection connection = new(builder.ConnectionString);
try
{
connection.Open();
Assert.False(true, "Connection should not have opened.");
}
catch (SqlException e)
{
// FATAL Error, should result in closed connection.
Assert.Equal(20, e.Class);
Assert.Equal(ConnectionState.Closed, connection.State);
}
SqlException e = Assert.Throws<SqlException>(() => connection.Open());
Assert.Equal(20, e.Class);
Assert.Equal(ConnectionState.Closed, connection.State);
}

[Fact]
Expand Down

0 comments on commit e3787ff

Please sign in to comment.