diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/Interfaces/ITraceForDbConnectionTest.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/Interfaces/ITraceForDbConnectionTest.cs index 3614ac20..93c8bd60 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/Interfaces/ITraceForDbConnectionTest.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/Interfaces/ITraceForDbConnectionTest.cs @@ -1621,6 +1621,24 @@ public void TestDbConnectionTraceForAfterMaxViaTableName() #region MaxAsync + [TestMethod] + public void TestDbConnectionTraceForBeforeMaxAsync() + { + // Prepare + var trace = new Mock(); + var connection = new TraceDbConnection(); + + // Act + connection.MaxAsync(trace: trace.Object, + field: e => e.Id, + where: (object)null).Wait(); + + // Assert + trace.Verify(t => + t.BeforeExecutionAsync(It.IsAny(), + It.IsAny()), Times.Exactly(1)); + } + [TestMethod] public void TestDbConnectionTraceForAfterMaxAsync() { diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/Trace/CancellableTraceLogTest.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/Trace/CancellableTraceLogTest.cs index 44ecc8ca..769a9de8 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/Trace/CancellableTraceLogTest.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/Trace/CancellableTraceLogTest.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using RepoDb.Exceptions; +using RepoDb.Extensions; using RepoDb.Interfaces; using RepoDb.UnitTests.CustomObjects; using System; @@ -23,11 +24,16 @@ public static void ClassInitialize(TestContext context) private class TraceDbConnection : CustomDbConnection { } - private class CancelTrace : ITrace + private class TraceEntity + { + public int Id { get; set; } + public string Name { get; set; } + } + + private class ErroneousCancellationTrace : ITrace { public void AfterExecution(ResultTraceLog log) { - // Do nothing } public Task AfterExecutionAsync(ResultTraceLog log, @@ -49,9 +55,46 @@ public Task BeforeExecutionAsync(CancellableTraceLog log, } } + private class SilentCancellationTrace : ITrace + { + public void AfterExecution(ResultTraceLog log) + { + AfterExecutionInvocationCount++; + } + + public Task AfterExecutionAsync(ResultTraceLog log, + CancellationToken cancellationToken = default) + { + AfterExecutionInvocationCount++; + return Task.CompletedTask; + } + + public void BeforeExecution(CancellableTraceLog log) + { + log.Cancel(false); + BeforeExecutionInvocationCount++; + } + + public Task BeforeExecutionAsync(CancellableTraceLog log, + CancellationToken cancellationToken = default) + { + log.Cancel(false); + BeforeExecutionInvocationCount++; + return Task.CompletedTask; + } + + #region Properties + + public int BeforeExecutionInvocationCount { get; private set; } + + public int AfterExecutionInvocationCount { get; private set; } + + #endregion + } + #endregion - #region Methods + #region Cancelled #region ExecuteNonQuery @@ -63,7 +106,7 @@ public void ThrowExceptionOnExecuteNonQueryCancelledOperation() // Act connection - .ExecuteNonQuery("", trace: new CancelTrace()); + .ExecuteNonQuery("", trace: new ErroneousCancellationTrace()); } [TestMethod, ExpectedException(typeof(AggregateException))] @@ -74,7 +117,7 @@ public void ThrowExceptionOnExecuteNonQueryAsyncCancelledOperation() // Act connection - .ExecuteNonQueryAsync("", trace: new CancelTrace()) + .ExecuteNonQueryAsync("", trace: new ErroneousCancellationTrace()) .Wait(); } @@ -90,7 +133,7 @@ public void ThrowExceptionOnExecuteQueryCancelledOperation() // Act connection - .ExecuteQuery("", trace: new CancelTrace()); + .ExecuteQuery("", trace: new ErroneousCancellationTrace()); } [TestMethod, ExpectedException(typeof(AggregateException))] @@ -101,7 +144,7 @@ public void ThrowExceptionOnExecuteQueryAsyncCancelledOperation() // Act connection - .ExecuteQueryAsync("", trace: new CancelTrace()) + .ExecuteQueryAsync("", trace: new ErroneousCancellationTrace()) .Wait(); } @@ -117,7 +160,7 @@ public void ThrowExceptionOnExecuteScalarCancelledOperation() // Act connection - .ExecuteScalar("", trace: new CancelTrace()); + .ExecuteScalar("", trace: new ErroneousCancellationTrace()); } [TestMethod, ExpectedException(typeof(AggregateException))] @@ -128,7 +171,7 @@ public void ThrowExceptionOnExecuteScalarAsyncCancelledOperation() // Act connection - .ExecuteScalarAsync("", trace: new CancelTrace()) + .ExecuteScalarAsync("", trace: new ErroneousCancellationTrace()) .Wait(); } @@ -144,7 +187,7 @@ public void ThrowExceptionOnExecuteQueryMultipleCancelledOperation() // Act connection - .ExecuteQueryMultiple("", trace: new CancelTrace()); + .ExecuteQueryMultiple("", trace: new ErroneousCancellationTrace()); } [TestMethod, ExpectedException(typeof(AggregateException))] @@ -155,7 +198,7 @@ public void ThrowExceptionExecuteQueryMultipleAsyncCancelledOperation() // Act connection - .ExecuteQueryMultipleAsync("", trace: new CancelTrace()) + .ExecuteQueryMultipleAsync("", trace: new ErroneousCancellationTrace()) .Wait(); } @@ -171,7 +214,7 @@ public void ThrowExceptionOnAverageCancelledOperation() // Act connection - .Average("", (Field)null, (object)null, trace: new CancelTrace()); + .Average("", (Field)null, (object)null, trace: new ErroneousCancellationTrace()); } [TestMethod, ExpectedException(typeof(AggregateException))] @@ -182,7 +225,7 @@ public void ThrowExceptionOnAverageAsyncCancelledOperation() // Act connection - .AverageAsync("", (Field)null, (object)null, trace: new CancelTrace()) + .AverageAsync("", (Field)null, (object)null, trace: new ErroneousCancellationTrace()) .Wait(); } @@ -198,7 +241,7 @@ public void ThrowExceptionOnAverageAllCancelledOperation() // Act connection - .AverageAll("", (Field)null, trace: new CancelTrace()); + .AverageAll("", (Field)null, trace: new ErroneousCancellationTrace()); } [TestMethod, ExpectedException(typeof(AggregateException))] @@ -209,12 +252,2970 @@ public void ThrowExceptionOnAverageAllAsyncCancelledOperation() // Act connection - .AverageAllAsync("", (Field)null, trace: new CancelTrace()) + .AverageAllAsync("", (Field)null, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region BatchQuery + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnBatchQueryCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .BatchQuery("", 0, 100, null, (object)null, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnBatchQueryAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .BatchQueryAsync("", 0, 100, null, (object)null, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region Count + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnCountCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .Count("", (Field)null, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnCountAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .CountAsync("", (Field)null, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region CountAll + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnCountAllCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .CountAll("", trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnCountAllAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .CountAllAsync("", trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region Delete + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnDeleteCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .Delete("", (Field)null, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnDeleteAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .DeleteAsync("", (Field)null, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region DeleteAll + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnDeleteAllCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .DeleteAll("", trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnDeleteAllAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .DeleteAllAsync("", trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region Exists + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnExistsCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .Exists("", (Field)null, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnExistsAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .ExistsAsync("", (Field)null, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region Insert + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnInsertCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .Insert("", null, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnInsertAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .InsertAsync("", null, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region InsertAll + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnInsertAllCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + var entities = new[] + { + new { Id = 1 } + }; + + + // Act + connection + .InsertAll("", entities, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnInsertAllMultipleEntitiesCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + var entities = new[] + { + new { Id = 1 } + }; + + // Act + connection + .InsertAll("", entities, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnInsertAllAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + var entities = new[] + { + new { Id = 1 }, + new { Id = 2 }, + new { Id = 3 } + }; + + // Act + connection + .InsertAllAsync("", entities, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnInsertAllAsyncMultipleEntitiesCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + var entities = new[] + { + new { Id = 1 }, + new { Id = 2 }, + new { Id = 3 } + }; + + // Act + connection + .InsertAllAsync("", entities, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region Max + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnMaxCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .Max("", (Field)null, (object)null, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnMaxAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .MaxAsync("", (Field)null, (object)null, trace: new ErroneousCancellationTrace()) .Wait(); } #endregion + #region MaxAll + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnMaxAllCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .MaxAll("", (Field)null, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnMaxAllAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .MaxAllAsync("", (Field)null, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region Merge + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnMergeCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .Merge("", new { Id = 1 }, (Field)null, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnMergeAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .MergeAsync("", new { Id = 1 }, (Field)null, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region MergeAll + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnMergeAllCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + var entities = new[] + { + new { Id = 1 } + }; + + // Act + connection + .MergeAll("", entities, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnMergeAllAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + var entities = new[] + { + new { Id = 1 } + }; + + // Act + connection + .MergeAllAsync("", entities, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnMergeAllMultipleEntitiesCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + var entities = new[] + { + new { Id = 1 }, + new { Id = 2 }, + new { Id = 3 } + }; + + // Act + connection + .MergeAll("", entities, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnMergeAllMultipleEntitiesAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + var entities = new[] + { + new { Id = 1 }, + new { Id = 2 }, + new { Id = 3 } + }; + + // Act + connection + .MergeAllAsync("", entities, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region Min + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnMinCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .Min("", (Field)null, (object)null, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnMinAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .MinAsync("", (Field)null, (object)null, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region MaxAll + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnMinAllCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .MinAll("", (Field)null, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnMinAllAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .MinAllAsync("", (Field)null, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region Query + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnQueryCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .Query("", (QueryField)null, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnQueryAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .QueryAsync("", (QueryField)null, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region QueryAll + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnQueryAllCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .QueryAll("", trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnQueryAllAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .QueryAllAsync("", trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region QueryMultiple + + #region T2 + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnQueryMultipleForT2CancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .QueryMultiple("", (QueryField)null, + "", (QueryField)null, + trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnQueryMultipleForT2AsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .QueryMultipleAsync("", (QueryField)null, + "", (QueryField)null, + trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region T3 + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnQueryMultipleForT3CancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .QueryMultiple("", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnQueryMultipleForT3AsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .QueryMultipleAsync("", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region T4 + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnQueryMultipleForT4CancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .QueryMultiple("", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnQueryMultipleForT4AsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .QueryMultipleAsync("", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region T5 + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnQueryMultipleForT5CancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .QueryMultiple("", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnQueryMultipleForT5AsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .QueryMultipleAsync("", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region T6 + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnQueryMultipleForT6CancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .QueryMultiple("", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnQueryMultipleForT6AsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .QueryMultipleAsync("", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region T7 + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnQueryMultipleForT7CancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .QueryMultiple("", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnQueryMultipleForT7AsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .QueryMultipleAsync("", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + "", (QueryField)null, + trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #endregion + + #region Sum + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnSumCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .Sum("", (Field)null, (object)null, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnSumAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .SumAsync("", (Field)null, (object)null, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region SumAll + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnSumAllCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .SumAll("", (Field)null, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnSumAllAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .SumAllAsync("", (Field)null, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region Truncate + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnTruncateCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .Truncate("", trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnTruncateAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .TruncateAsync("", trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region Update + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnUpdateCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .Update("", new { Id = 1 }, (Field)null, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnUpdateAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + + // Act + connection + .UpdateAsync("", new { Id = 1 }, (Field)null, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #region UpdateAll + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnUpdateAllCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + var entities = new[] + { + new { Id = 1 } + }; + + // Act + connection + .UpdateAll("", entities, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnUpdateAllAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + var entities = new[] + { + new { Id = 1 } + }; + + // Act + connection + .UpdateAllAsync("", entities, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + [TestMethod, ExpectedException(typeof(CancelledExecutionException))] + public void ThrowExceptionOnUpdateAllMultipleEntitiesCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + var entities = new[] + { + new { Id = 1 }, + new { Id = 2 }, + new { Id = 3 } + }; + + // Act + connection + .UpdateAll("", entities, trace: new ErroneousCancellationTrace()); + } + + [TestMethod, ExpectedException(typeof(AggregateException))] + public void ThrowExceptionOnUpdateAllMultipleEntitiesAsyncCancelledOperation() + { + // Prepare + var connection = new TraceDbConnection(); + var entities = new[] + { + new { Id = 1 }, + new { Id = 2 }, + new { Id = 3 } + }; + + // Act + connection + .UpdateAllAsync("", entities, trace: new ErroneousCancellationTrace()) + .Wait(); + } + + #endregion + + #endregion + + #region Silent Cancellation + + #region Average + + #region Average + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForAverage() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Average(trace: trace, + field: e => e.Id, + where: (object)null); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForAverageViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Average(ClassMappedNameCache.Get(), + field: new Field("Id"), + where: (object)null, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region AverageAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForAverageAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.AverageAsync(trace: trace, + field: e => e.Id, + where: (object)null).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForAverageAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.AverageAsync(ClassMappedNameCache.Get(), + field: new Field("Id"), + where: (object)null, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region AverageAll + + #region AverageAll + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForAverageAll() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.AverageAll(trace: trace, + field: e => e.Id); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForAverageAllViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.AverageAll(ClassMappedNameCache.Get(), + field: new Field("Id"), + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region AverageAllAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForAverageAllAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.AverageAllAsync(trace: trace, + field: e => e.Id).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForAverageAllAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.AverageAllAsync(ClassMappedNameCache.Get(), + field: new Field("Id"), + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region BatchQuery + + #region BatchQuery + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForBatchQuery() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.BatchQuery(0, + 10, + OrderField.Ascending(t => t.Id).AsEnumerable(), + where: (QueryGroup)null, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region BatchQueryAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForBatchQueryAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.BatchQueryAsync(0, + 10, + OrderField.Ascending(t => t.Id).AsEnumerable(), + where: (QueryGroup)null, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region Count + + #region Count + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForCount() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Count(trace: trace, + where: (object)null); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForCountViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Count(ClassMappedNameCache.Get(), + where: (object)null, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region CountAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForCountAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.CountAsync(trace: trace, + where: (object)null).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForCountAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.CountAsync(ClassMappedNameCache.Get(), + where: (object)null, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region CountAll + + #region CountAll + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForCountAll() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.CountAll(trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForCountAllViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.CountAll(ClassMappedNameCache.Get(), + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region CountAllAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForCountAllAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.CountAllAsync(trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForCountAllAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.CountAllAsync(ClassMappedNameCache.Get(), + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region Delete + + #region Delete + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForDelete() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Delete(0, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForDeleteViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Delete(ClassMappedNameCache.Get(), + new + { + Id = 1 + }, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region DeleteAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForDeleteAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.DeleteAsync(0, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForDeleteAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.DeleteAsync(ClassMappedNameCache.Get(), + new + { + Id = 1 + }, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region DeleteAll + + #region DeleteAll + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForDeleteAll() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.DeleteAll(trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForDeleteAllViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.DeleteAll(ClassMappedNameCache.Get(), + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region DeleteAllAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForDeleteAllAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.DeleteAllAsync(trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForDeleteAllAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.DeleteAllAsync(ClassMappedNameCache.Get(), + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region Exists + + #region Exists + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForExists() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Exists(trace: trace, + what: (object)null); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForExistsViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Exists(ClassMappedNameCache.Get(), + what: (object)null, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region ExistsAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForExistsAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.ExistsAsync(trace: trace, + what: (object)null).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForExistsAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.ExistsAsync(ClassMappedNameCache.Get(), + what: (object)null, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region Insert + + #region Insert + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForInsert() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Insert( + new TraceEntity { Name = "Name" }, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForInsertViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Insert(ClassMappedNameCache.Get(), + new { Name = "Name" }, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region InsertAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForInsertAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.InsertAsync( + new TraceEntity { Name = "Name" }, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForInsertAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.InsertAsync(ClassMappedNameCache.Get(), + new { Name = "Name" }, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region InsertAll + + #region InsertAll + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForInsertAll() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.InsertAll(new[] { new TraceEntity { Name = "Name" } }, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForInsertAllViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.InsertAll(ClassMappedNameCache.Get(), + new[] { new { Name = "Name" } }, + fields: Field.From("Name"), + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region InsertAllAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForInsertAllAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.InsertAllAsync(new[] { new TraceEntity { Name = "Name" } }, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForInsertAllAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.InsertAllAsync(ClassMappedNameCache.Get(), + new[] { new { Name = "Name" } }, + fields: Field.From("Name"), + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region Max + + #region Max + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMax() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Max(trace: trace, + field: e => e.Id, + where: (object)null); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMaxViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Max(ClassMappedNameCache.Get(), + field: new Field("Id"), + where: (object)null, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region MaxAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMaxAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MaxAsync(trace: trace, + field: e => e.Id, + where: (object)null).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMaxAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MaxAsync(ClassMappedNameCache.Get(), + field: new Field("Id"), + where: (object)null, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region MaxAll + + #region MaxAll + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMaxAll() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MaxAll(trace: trace, + field: e => e.Id); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMaxAllViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MaxAll(ClassMappedNameCache.Get(), + field: new Field("Id"), + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region MaxAllAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMaxAllAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MaxAllAsync(trace: trace, + field: e => e.Id).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMaxAllAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MaxAllAsync(ClassMappedNameCache.Get(), + field: new Field("Id"), + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region Merge + + #region Merge + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMerge() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Merge( + new TraceEntity { Id = 1, Name = "Name" }, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMergeViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Merge(ClassMappedNameCache.Get(), + new { Id = 1, Name = "Name" }, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region MergeAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMergeAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MergeAsync( + new TraceEntity { Id = 1, Name = "Name" }, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMergeAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MergeAsync(ClassMappedNameCache.Get(), + new { Id = 1, Name = "Name" }, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region MergeAll + + #region MergeAll + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMergeAll() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MergeAll( + new[] { new TraceEntity { Id = 1, Name = "Name" } }, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMergeAllViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MergeAll(ClassMappedNameCache.Get(), + new[] { new TraceEntity { Id = 1, Name = "Name" } }, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region MergeAllAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMergeAllAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MergeAllAsync( + new[] { new TraceEntity { Id = 1, Name = "Name" } }, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMergeAllAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MergeAllAsync(ClassMappedNameCache.Get(), + new[] { new { Id = 1, Name = "Name" } }, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region Min + + #region Min + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMin() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Min(trace: trace, + field: e => e.Id, + where: (object)null); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMinViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Min(ClassMappedNameCache.Get(), + field: new Field("Id"), + where: (object)null, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region MinAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMinAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MinAsync(trace: trace, + field: e => e.Id, + where: (object)null).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMinAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MinAsync(ClassMappedNameCache.Get(), + field: new Field("Id"), + where: (object)null, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region MinAll + + #region MinAll + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMinAll() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MinAll(trace: trace, + field: e => e.Id); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMinAllViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MinAll(ClassMappedNameCache.Get(), + field: new Field("Id"), + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region MinAllAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMinAllAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MinAllAsync(trace: trace, + field: e => e.Id).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForMinAllAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.MinAllAsync(ClassMappedNameCache.Get(), + field: new Field("Id"), + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region Query + + #region Query + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForQuery() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Query(te => te.Id == 1, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region QueryAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForQueryAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.QueryAsync(te => te.Id == 1, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region QueryAll + + #region QueryAll + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForQueryAll() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.QueryAll(trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region QueryAllAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForQueryAllAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.QueryAllAsync(trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region QueryMultiple + + #region QueryMultiple + + #region T2 + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForQueryMultipleForT2() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.QueryMultiple(te => te.Id == 1, + te => te.Id == 1, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region T3 + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForQueryMultipleForT3() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.QueryMultiple(te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region T4 + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForQueryMultipleForT4() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.QueryMultiple(te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region T5 + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForQueryMultipleForT5() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.QueryMultiple(te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region T6 + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForQueryMultipleForT6() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.QueryMultiple(te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region T7 + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForQueryMultipleForT7() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.QueryMultiple(te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region QueryMultipleAsync + + #region T2 + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForQueryMultipleAsyncForT2() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.QueryMultipleAsync(te => te.Id == 1, + te => te.Id == 1, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region T3 + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForQueryMultipleAsyncForT3() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.QueryMultipleAsync(te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region T4 + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForQueryMultipleAsyncForT4() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.QueryMultipleAsync(te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region T5 + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForQueryMultipleAsyncForT5() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.QueryMultipleAsync(te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region T6 + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForQueryMultipleAsyncForT6() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.QueryMultipleAsync(te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region T7 + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForQueryMultipleAsyncForT7() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.QueryMultipleAsync(te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + te => te.Id == 1, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #endregion + + #region Sum + + #region Sum + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForSum() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Sum(trace: trace, + field: e => e.Id, + where: (object)null); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForSumViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Sum(ClassMappedNameCache.Get(), + field: new Field("Id"), + where: (object)null, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region SumAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForSumAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.SumAsync(trace: trace, + field: e => e.Id, + where: (object)null).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForSumAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.SumAsync(ClassMappedNameCache.Get(), + field: new Field("Id"), + where: (object)null, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region SumAll + + #region SumAll + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForSumAll() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.SumAll(trace: trace, + field: e => e.Id); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForSumAllViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.SumAll(ClassMappedNameCache.Get(), + field: new Field("Id"), + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region SumAllAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForSumAllAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.SumAllAsync(trace: trace, + field: e => e.Id).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForSumAllAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.SumAllAsync(ClassMappedNameCache.Get(), + field: new Field("Id"), + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region Truncate + + #region Truncate + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForTruncate() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Truncate(trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForTruncateViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Truncate(ClassMappedNameCache.Get(), + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region TruncateAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForTruncateAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.TruncateAsync(trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForTruncateAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.TruncateAsync(ClassMappedNameCache.Get(), + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region Update + + #region Update + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForUpdate() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Update( + new TraceEntity + { + Id = 1, + Name = "Name" + }, + what: 1, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForUpdateViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.Update(ClassMappedNameCache.Get(), + new + { + Name = "Name" + }, + new + { + Id = 1 + }, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region UpdateAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForUpdateAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.UpdateAsync( + new TraceEntity + { + Id = 1, + Name = "Name" + }, + what: 1, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForUpdateAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.UpdateAsync(ClassMappedNameCache.Get(), + new + { + Name = "Name" + }, + new + { + Id = 1 + }, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + + #region UpdateAll + + #region UpdateAll + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForUpdateAll() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.UpdateAll( + new[] { new TraceEntity { Id = 1, Name = "Name" } }, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForUpdateAllViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.UpdateAll(ClassMappedNameCache.Get(), + new[] { new { Id = 1, Name = "Name" } }, + trace: trace); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #region UpdateAllAsync + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForUpdateAllAsync() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.UpdateAllAsync( + new[] { new TraceEntity { Id = 1, Name = "Name" } }, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + [TestMethod] + public void TestDbConnectionTraceSilentCancellationForUpdateAllAsyncViaTableName() + { + // Prepare + var trace = new SilentCancellationTrace(); + var connection = new TraceDbConnection(); + + // Act + connection.UpdateAllAsync(ClassMappedNameCache.Get(), + new[] { new { Id = 1, Name = "Name" } }, + trace: trace).Wait(); + + // Assert + Assert.AreEqual(1, trace.BeforeExecutionInvocationCount); + Assert.AreEqual(0, trace.AfterExecutionInvocationCount); + } + + #endregion + + #endregion + #endregion } } \ No newline at end of file diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/InsertAll.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/InsertAll.cs index eb2a8592..6a588f0b 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/InsertAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/InsertAll.cs @@ -292,7 +292,7 @@ internal static Task InsertAllAsyncInternal(this IDbConnection con fields: GetQualifiedFields(fields, entities?.FirstOrDefault()), hints: hints, commandTimeout: commandTimeout, - traceKey: traceKey, + traceKey: traceKey, transaction: transaction, trace: trace, statementBuilder: statementBuilder, @@ -307,7 +307,7 @@ internal static Task InsertAllAsyncInternal(this IDbConnection con fields: GetQualifiedFields(fields, entities?.FirstOrDefault()), hints: hints, commandTimeout: commandTimeout, - traceKey: traceKey, + traceKey: traceKey, transaction: transaction, trace: trace, statementBuilder: statementBuilder, diff --git a/RepoDb.Core/RepoDb/QueryGroup.cs b/RepoDb.Core/RepoDb/QueryGroup.cs index 7693fdd3..5478abd1 100644 --- a/RepoDb.Core/RepoDb/QueryGroup.cs +++ b/RepoDb.Core/RepoDb/QueryGroup.cs @@ -543,9 +543,14 @@ internal static void FixForQueryMultiple(QueryGroup[] queryGroups) { for (var i = 0; i < queryGroups.Length; i++) { - foreach (var field in queryGroups[i].GetFields(true)) + var fields = queryGroups[i]?.GetFields(true); + + if (fields?.Any() == true) { - field.Parameter.SetName(string.Format("T{0}_{1}", i, field.Parameter.Name)); + foreach (var field in fields) + { + field.Parameter.SetName(string.Format("T{0}_{1}", i, field.Parameter.Name)); + } } } } diff --git a/RepoDb.Core/RepoDb/QueryGroup/AsMappedObject.cs b/RepoDb.Core/RepoDb/QueryGroup/AsMappedObject.cs index 402948ac..d4b1284b 100644 --- a/RepoDb.Core/RepoDb/QueryGroup/AsMappedObject.cs +++ b/RepoDb.Core/RepoDb/QueryGroup/AsMappedObject.cs @@ -41,11 +41,11 @@ private static void AsMappedObject(IDictionary dictionary, bool fixParameters = true) { var queryFields = queryGroupTypeMap - .QueryGroup + .QueryGroup? .GetFields(true); // Identify if there are fields to count - if (queryFields.Any() != true) + if (queryFields?.Any() != true) { return; } diff --git a/RepoDb.Core/RepoDb/Trace/Tracer.cs b/RepoDb.Core/RepoDb/Trace/Tracer.cs index 4dfd7a83..8a219f0f 100644 --- a/RepoDb.Core/RepoDb/Trace/Tracer.cs +++ b/RepoDb.Core/RepoDb/Trace/Tracer.cs @@ -90,6 +90,11 @@ public static void InvokeAfterExecution(TraceResult result, return; } + if (result.CancellableTraceLog?.IsCancelled == true) + { + return; + } + var log = new ResultTraceLog(result.SessionId, result.CancellableTraceLog.Key, result.CancellableTraceLog.Statement, @@ -146,7 +151,7 @@ public static async Task InvokeAfterExecutionAsync(TraceResult result, private static void ValidateCancellation(string key, CancellableTraceLog log) { - if (log.IsThrowException) + if (log?.IsCancelled == true && log?.IsThrowException == true) { throw new CancelledExecutionException($"The execution has been cancelled for {key}."); }