Skip to content

Commit

Permalink
UnitTest changes and cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
ttossavainen committed Sep 10, 2024
1 parent 4ae5fbb commit 21f22c5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public async Task TestBulkInsert_FireTriggers()
CommandTimeoutSeconds = 60,
FireTriggers = true,
KeepIdentity = false,
NotifyAfter = new Random().Next(0, 1001),
NotifyAfter = 0,
ConvertEmptyPropertyValuesToNull = false,
KeepNulls = false,
TableLock = false,
Expand Down Expand Up @@ -128,7 +128,7 @@ public async Task TestBulkInsert_KeepIdentity()
CommandTimeoutSeconds = 60,
FireTriggers = false,
KeepIdentity = true,
NotifyAfter = new Random().Next(0, 1001),
NotifyAfter = 0,
ConvertEmptyPropertyValuesToNull = false,
KeepNulls = false,
TableLock = false,
Expand Down Expand Up @@ -167,7 +167,7 @@ public async Task TestBulkInsert_ConvertEmptyPropertyValuesToNull()
CommandTimeoutSeconds = 60,
FireTriggers = false,
KeepIdentity = false,
NotifyAfter = new Random().Next(0, 1001),
NotifyAfter = 0,
ConvertEmptyPropertyValuesToNull = true,
KeepNulls = false,
TableLock = false,
Expand Down Expand Up @@ -206,7 +206,7 @@ public async Task TestBulkInsert_KeepNulls()
CommandTimeoutSeconds = 60,
FireTriggers = false,
KeepIdentity = false,
NotifyAfter = new Random().Next(0, 1001),
NotifyAfter = 0,
ConvertEmptyPropertyValuesToNull = false,
KeepNulls = true,
TableLock = false,
Expand Down Expand Up @@ -245,7 +245,7 @@ public async Task TestBulkInsert_TableLock()
CommandTimeoutSeconds = 60,
FireTriggers = false,
KeepIdentity = false,
NotifyAfter = new Random().Next(0, 1001),
NotifyAfter = 0,
ConvertEmptyPropertyValuesToNull = false,
KeepNulls = false,
TableLock = true,
Expand Down Expand Up @@ -285,7 +285,7 @@ public async Task TestBulkInsert_All()
CommandTimeoutSeconds = 60,
FireTriggers = true,
KeepIdentity = true,
NotifyAfter = new Random().Next(0, 1001),
NotifyAfter = 0,
ConvertEmptyPropertyValuesToNull = true,
KeepNulls = true,
TableLock = true,
Expand Down Expand Up @@ -324,7 +324,46 @@ public async Task TestBulkInsert_NotifyAfterZero()
CommandTimeoutSeconds = 60,
FireTriggers = false,
KeepIdentity = false,
NotifyAfter = 0,
NotifyAfter = -1,
ConvertEmptyPropertyValuesToNull = false,
KeepNulls = true,
TableLock = false,
};

var result = await MicrosoftSQL.BulkInsert(_input, options, default);
Assert.IsTrue(result.Success);
Assert.AreEqual(0, result.Count);
Assert.AreEqual(3, GetRowCount());

await MicrosoftSQL.BulkInsert(_input, options, default);
Assert.AreEqual(6, GetRowCount());

CleanUp();
}
}

[TestMethod]
public async Task TestBulkInsert_NotifyAfterTooMuch()
{
var transactionLevels = new List<SqlTransactionIsolationLevel>() {
SqlTransactionIsolationLevel.Unspecified,
SqlTransactionIsolationLevel.Serializable,
SqlTransactionIsolationLevel.None,
SqlTransactionIsolationLevel.ReadUncommitted,
SqlTransactionIsolationLevel.ReadCommitted
};

foreach (var transactionLevel in transactionLevels)
{
Init();

var options = new Options()
{
SqlTransactionIsolationLevel = transactionLevel,
CommandTimeoutSeconds = 60,
FireTriggers = false,
KeepIdentity = false,
NotifyAfter = 4,
ConvertEmptyPropertyValuesToNull = false,
KeepNulls = true,
TableLock = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static async Task<long> ExecuteHandler(Options options, string tableName
var rowCount = dataSet.Tables[0].Rows.Count;
sqlBulkCopy.NotifyAfter = rowCount > 0 ? Math.Max(1, rowCount / 10) : 1;
}
if (options.NotifyAfter > 0)
else if (options.NotifyAfter > 0)
sqlBulkCopy.NotifyAfter = options.NotifyAfter;
else
sqlBulkCopy.NotifyAfter = 0;
Expand Down

0 comments on commit 21f22c5

Please sign in to comment.