public async Task ExecuteAsync_does_not_call_Commit_if_existing_transaction() { var sqlGenerator = new Mock<IUpdateSqlGenerator>().Object; var mockModificationCommandBatch = new Mock<ModificationCommandBatch>(sqlGenerator); mockModificationCommandBatch.Setup(m => m.ModificationCommands.Count).Returns(1); var mockRelationalConnection = new Mock<IRelationalConnection>(); var transactionMock = new Mock<IRelationalTransaction>(); mockRelationalConnection.Setup(m => m.Transaction).Returns(transactionMock.Object); var cancellationToken = new CancellationTokenSource().Token; var relationalTypeMapper = new ConcreteTypeMapper(); var batchExecutor = new BatchExecutorForTest(relationalTypeMapper); await batchExecutor.ExecuteAsync(new[] { mockModificationCommandBatch.Object }, mockRelationalConnection.Object, cancellationToken); mockRelationalConnection.Verify(rc => rc.OpenAsync(cancellationToken)); mockRelationalConnection.Verify(rc => rc.Close()); mockRelationalConnection.Verify(rc => rc.BeginTransaction(), Times.Never); transactionMock.Verify(t => t.Commit(), Times.Never); mockModificationCommandBatch.Verify(mcb => mcb.ExecuteAsync( It.IsAny<IRelationalTransaction>(), relationalTypeMapper, It.IsAny<DbContext>(), null, cancellationToken)); }
public async Task ExecuteAsync_calls_Commit_if_no_transaction() { var sqlGenerator = new Mock<ISqlGenerator>().Object; var mockModificationCommandBatch = new Mock<ModificationCommandBatch>(sqlGenerator); var mockRelationalConnection = new Mock<IRelationalConnection>(); var transactionMock = new Mock<RelationalTransaction>( mockRelationalConnection.Object, Mock.Of<DbTransaction>(), false, Mock.Of<ILogger>()); RelationalTransaction currentTransaction = null; mockRelationalConnection.Setup(m => m.BeginTransaction()).Returns(() => currentTransaction = transactionMock.Object); mockRelationalConnection.Setup(m => m.Transaction).Returns(() => currentTransaction); var cancellationToken = new CancellationTokenSource().Token; var relationalTypeMapper = new RelationalTypeMapper(); var batchExecutor = new BatchExecutorForTest(relationalTypeMapper); await batchExecutor.ExecuteAsync(new[] { mockModificationCommandBatch.Object }, mockRelationalConnection.Object, cancellationToken); mockRelationalConnection.Verify(rc => rc.OpenAsync(cancellationToken)); mockRelationalConnection.Verify(rc => rc.Close()); transactionMock.Verify(t => t.Commit()); mockModificationCommandBatch.Verify(mcb => mcb.ExecuteAsync( It.IsAny<RelationalTransaction>(), relationalTypeMapper, It.IsAny<DbContext>(), null, cancellationToken)); }
public async Task ExecuteAsync_calls_Commit_if_no_transaction() { var sqlGenerator = new Mock <IUpdateSqlGenerator>().Object; var mockModificationCommandBatch = new Mock <ModificationCommandBatch>(sqlGenerator); mockModificationCommandBatch.Setup(m => m.ModificationCommands.Count).Returns(1); var mockRelationalConnection = new Mock <IRelationalConnection>(); var transactionMock = new Mock <IRelationalTransaction>(); IRelationalTransaction currentTransaction = null; mockRelationalConnection.Setup(m => m.BeginTransaction()).Returns(() => currentTransaction = transactionMock.Object); mockRelationalConnection.Setup(m => m.Transaction).Returns(() => currentTransaction); var cancellationToken = new CancellationTokenSource().Token; var relationalTypeMapper = new ConcreteTypeMapper(); var batchExecutor = new BatchExecutorForTest(relationalTypeMapper); await batchExecutor.ExecuteAsync(new[] { mockModificationCommandBatch.Object }, mockRelationalConnection.Object, cancellationToken); mockRelationalConnection.Verify(rc => rc.OpenAsync(cancellationToken)); mockRelationalConnection.Verify(rc => rc.Close()); transactionMock.Verify(t => t.Commit()); mockModificationCommandBatch.Verify(mcb => mcb.ExecuteAsync( It.IsAny <IRelationalTransaction>(), relationalTypeMapper, It.IsAny <DbContext>(), null, cancellationToken)); }
public async Task ExecuteAsync_does_not_call_Commit_if_existing_transaction() { var mockModificationCommandBatch = new Mock <ModificationCommandBatch>(); var transactionMock = new Mock <RelationalTransaction>(); var mockRelationalConnection = new Mock <IRelationalConnection>(); mockRelationalConnection.Setup(m => m.Transaction).Returns(transactionMock.Object); var cancellationToken = new CancellationTokenSource().Token; var relationalTypeMapper = new RelationalTypeMapper(); var batchExecutor = new BatchExecutorForTest(relationalTypeMapper); await batchExecutor.ExecuteAsync(new[] { mockModificationCommandBatch.Object }, mockRelationalConnection.Object, cancellationToken); mockRelationalConnection.Verify(rc => rc.OpenAsync(cancellationToken)); mockRelationalConnection.Verify(rc => rc.Close()); mockRelationalConnection.Verify(rc => rc.BeginTransaction(), Times.Never); transactionMock.Verify(t => t.Commit(), Times.Never); mockModificationCommandBatch.Verify(mcb => mcb.ExecuteAsync( It.IsAny <RelationalTransaction>(), relationalTypeMapper, It.IsAny <DbContext>(), null, cancellationToken)); }
public async Task ExecuteAsync_calls_Commit_if_no_transaction() { var mockModificationCommandBatch = new Mock<ModificationCommandBatch>(); mockModificationCommandBatch.Setup(m => m.ModificationCommands.Count).Returns(1); var mockRelationalConnection = new Mock<IRelationalConnection>(); var transactionMock = new Mock<IRelationalTransaction>(); IRelationalTransaction currentTransaction = null; mockRelationalConnection.Setup(m => m.BeginTransaction()).Returns(() => currentTransaction = transactionMock.Object); mockRelationalConnection.Setup(m => m.Transaction).Returns(() => currentTransaction); var cancellationToken = new CancellationTokenSource().Token; var batchExecutor = new BatchExecutorForTest(); await batchExecutor.ExecuteAsync(new[] { mockModificationCommandBatch.Object }, mockRelationalConnection.Object, cancellationToken); mockRelationalConnection.Verify(rc => rc.OpenAsync(cancellationToken)); mockRelationalConnection.Verify(rc => rc.Close()); transactionMock.Verify(t => t.Commit()); mockModificationCommandBatch.Verify(mcb => mcb.ExecuteAsync( It.IsAny<IRelationalConnection>(), null, cancellationToken)); }