diff --git a/Frends.MicrosoftSQL.BulkInsert/Frends.MicrosoftSQL.BulkInsert.Tests/UnitTests.cs b/Frends.MicrosoftSQL.BulkInsert/Frends.MicrosoftSQL.BulkInsert.Tests/UnitTests.cs index 09fff03..2da0739 100644 --- a/Frends.MicrosoftSQL.BulkInsert/Frends.MicrosoftSQL.BulkInsert.Tests/UnitTests.cs +++ b/Frends.MicrosoftSQL.BulkInsert/Frends.MicrosoftSQL.BulkInsert.Tests/UnitTests.cs @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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.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, diff --git a/Frends.MicrosoftSQL.BulkInsert/Frends.MicrosoftSQL.BulkInsert/BulkInsert.cs b/Frends.MicrosoftSQL.BulkInsert/Frends.MicrosoftSQL.BulkInsert/BulkInsert.cs index d825d08..e14ee7f 100644 --- a/Frends.MicrosoftSQL.BulkInsert/Frends.MicrosoftSQL.BulkInsert/BulkInsert.cs +++ b/Frends.MicrosoftSQL.BulkInsert/Frends.MicrosoftSQL.BulkInsert/BulkInsert.cs @@ -128,7 +128,7 @@ private static async Task 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;