Skip to content

Commit 59d5401

Browse files
committed
In DatabaseFixture for tests: drop test table only if it exists and do not silently catch exceptions.
1 parent b7a9f29 commit 59d5401

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

test/Serilog.Sinks.MSSqlServer.Tests/TestUtils/DatabaseFixture.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,11 @@ public void Dispose()
4646

4747
public static void DropTable(string tableName = null)
4848
{
49-
try
49+
using (var conn = new SqlConnection(LogEventsConnectionString))
5050
{
51-
using (var conn = new SqlConnection(LogEventsConnectionString))
52-
{
53-
conn.Execute($"DROP TABLE {(string.IsNullOrEmpty(tableName) ? LogTableName : tableName)};");
54-
}
51+
var actualTableName = string.IsNullOrEmpty(tableName) ? LogTableName : tableName;
52+
conn.Execute($"IF OBJECT_ID('{actualTableName}', 'U') IS NOT NULL DROP TABLE {actualTableName};");
5553
}
56-
catch { }
5754
}
5855

5956
private static void DeleteDatabase()

0 commit comments

Comments
 (0)