public void Dispose_executes_operation_and_dispatches_to_interceptors() { var mockConnection = new Mock<DbConnection>(); var mockInterceptor = new Mock<IDbConnectionInterceptor>(); var dispatcher = new DbConnectionDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); var interceptionContext = new DbConnectionInterceptionContext(); dispatcher.Dispose(mockConnection.Object, interceptionContext); mockConnection.Protected().Verify("Dispose", Times.Once(), ItExpr.IsAny<bool>()); mockInterceptor.Verify(m => m.Disposing(mockConnection.Object, It.IsAny<DbConnectionInterceptionContext>()), Times.Once()); mockInterceptor.Verify(m => m.Disposed(mockConnection.Object, It.IsAny<DbConnectionInterceptionContext>()), Times.Once()); }
public void BeginTransaction_executes_operation_and_dispatches_to_interceptors() { var mockConnection = new Mock<DbConnection>(); var mockInterceptor = new Mock<IDbConnectionInterceptor>(); var dispatcher = new DbConnectionDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); var interceptionContext = new BeginTransactionInterceptionContext().WithIsolationLevel(IsolationLevel.Serializable); dispatcher.BeginTransaction(mockConnection.Object, interceptionContext); mockConnection.Protected().Verify<DbTransaction>("BeginDbTransaction", Times.Once(), IsolationLevel.Serializable); mockInterceptor.Verify(m => m.BeginningTransaction(mockConnection.Object, It.IsAny<BeginTransactionInterceptionContext>()), Times.Once()); mockInterceptor.Verify(m => m.BeganTransaction(mockConnection.Object, It.IsAny<BeginTransactionInterceptionContext>()), Times.Once()); }
public void EnlistTransaction_executes_operation_and_dispatches_to_interceptors() { var mockConnection = new Mock<DbConnection>(); var mockInterceptor = new Mock<IDbConnectionInterceptor>(); var dispatcher = new DbConnectionDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); var transaction = new CommittableTransaction(); var interceptionContext = new EnlistTransactionInterceptionContext().WithTransaction(transaction); dispatcher.EnlistTransaction(mockConnection.Object, interceptionContext); mockConnection.Verify(m => m.EnlistTransaction(transaction), Times.Once()); mockInterceptor.Verify(m => m.EnlistingTransaction(mockConnection.Object, It.IsAny<EnlistTransactionInterceptionContext>()), Times.Once()); mockInterceptor.Verify(m => m.EnlistedTransaction(mockConnection.Object, It.IsAny<EnlistTransactionInterceptionContext>()), Times.Once()); }
public void Dispose_executes_operation_and_dispatches_to_interceptors() { var mockConnection = new Mock <DbConnection>(); var mockInterceptor = new Mock <IDbConnectionInterceptor>(); var dispatcher = new DbConnectionDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); var interceptionContext = new DbConnectionInterceptionContext(); dispatcher.Dispose(mockConnection.Object, interceptionContext); mockConnection.Protected().Verify("Dispose", Times.Once(), ItExpr.IsAny <bool>()); mockInterceptor.Verify(m => m.Disposing(mockConnection.Object, It.IsAny <DbConnectionInterceptionContext>()), Times.Once()); mockInterceptor.Verify(m => m.Disposed(mockConnection.Object, It.IsAny <DbConnectionInterceptionContext>()), Times.Once()); }
public void Open_executes_operation_and_dispatches_to_interceptors() { var mockConnection = new Mock <DbConnection>(); var mockInterceptor = new Mock <IDbConnectionInterceptor>(); var dispatcher = new DbConnectionDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); var interceptionContext = new DbConnectionInterceptionContext(); dispatcher.Open(mockConnection.Object, interceptionContext); mockConnection.Verify(m => m.Open(), Times.Once()); mockInterceptor.Verify(m => m.Opening(mockConnection.Object, It.IsAny <DbConnectionInterceptionContext>()), Times.Once()); mockInterceptor.Verify(m => m.Opened(mockConnection.Object, It.IsAny <DbConnectionInterceptionContext>()), Times.Once()); }
public void GetState_executes_operation_and_dispatches_to_interceptors() { var mockConnection = new Mock <DbConnection>(); var mockInterceptor = new Mock <IDbConnectionInterceptor>(); var dispatcher = new DbConnectionDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); var interceptionContext = new DbInterceptionContext(); dispatcher.GetState(mockConnection.Object, interceptionContext); mockConnection.Verify(m => m.State, Times.Once()); mockInterceptor.Verify(m => m.StateGetting(mockConnection.Object, It.IsAny <DbConnectionInterceptionContext <ConnectionState> >()), Times.Once()); mockInterceptor.Verify(m => m.StateGot(mockConnection.Object, It.IsAny <DbConnectionInterceptionContext <ConnectionState> >()), Times.Once()); }
public void BeginTransaction_executes_operation_and_dispatches_to_interceptors() { var mockConnection = new Mock <DbConnection>(); var mockInterceptor = new Mock <IDbConnectionInterceptor>(); var dispatcher = new DbConnectionDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); var interceptionContext = new BeginTransactionInterceptionContext().WithIsolationLevel(IsolationLevel.Serializable); dispatcher.BeginTransaction(mockConnection.Object, interceptionContext); mockConnection.Protected().Verify <DbTransaction>("BeginDbTransaction", Times.Once(), IsolationLevel.Serializable); mockInterceptor.Verify(m => m.BeginningTransaction(mockConnection.Object, It.IsAny <BeginTransactionInterceptionContext>()), Times.Once()); mockInterceptor.Verify(m => m.BeganTransaction(mockConnection.Object, It.IsAny <BeginTransactionInterceptionContext>()), Times.Once()); }
public void SetConnectionString_executes_operation_and_dispatches_to_interceptors() { var mockConnection = new Mock <DbConnection>(); var mockInterceptor = new Mock <IDbConnectionInterceptor>(); var dispatcher = new DbConnectionDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); var interceptionContext = new DbConnectionPropertyInterceptionContext <string>().WithValue("foo"); dispatcher.SetConnectionString(mockConnection.Object, interceptionContext); mockConnection.VerifySet(m => m.ConnectionString = "foo", Times.Once()); mockInterceptor.Verify(m => m.ConnectionStringSetting(mockConnection.Object, It.IsAny <DbConnectionPropertyInterceptionContext <string> >()), Times.Once()); mockInterceptor.Verify(m => m.ConnectionStringSet(mockConnection.Object, It.IsAny <DbConnectionPropertyInterceptionContext <string> >()), Times.Once()); }
public void EnlistTransaction_executes_operation_and_dispatches_to_interceptors() { var mockConnection = new Mock <DbConnection>(); var mockInterceptor = new Mock <IDbConnectionInterceptor>(); var dispatcher = new DbConnectionDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); var transaction = new CommittableTransaction(); var interceptionContext = new EnlistTransactionInterceptionContext().WithTransaction(transaction); dispatcher.EnlistTransaction(mockConnection.Object, interceptionContext); mockConnection.Verify(m => m.EnlistTransaction(transaction), Times.Once()); mockInterceptor.Verify(m => m.EnlistingTransaction(mockConnection.Object, It.IsAny <EnlistTransactionInterceptionContext>()), Times.Once()); mockInterceptor.Verify(m => m.EnlistedTransaction(mockConnection.Object, It.IsAny <EnlistTransactionInterceptionContext>()), Times.Once()); }
public void OpenAsync_executes_operation_and_dispatches_to_interceptors() { var mockConnection = new Mock <DbConnection>(); mockConnection.Setup(m => m.OpenAsync(It.IsAny <CancellationToken>())).Returns(() => Task.FromResult(true)); var mockInterceptor = new Mock <IDbConnectionInterceptor>(); var dispatcher = new DbConnectionDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); var interceptionContext = new DbConnectionInterceptionContext(); dispatcher.OpenAsync(mockConnection.Object, interceptionContext, CancellationToken.None).Wait(); mockConnection.Verify(m => m.OpenAsync(CancellationToken.None), Times.Once()); mockInterceptor.Verify(m => m.Opening(mockConnection.Object, It.IsAny <DbConnectionInterceptionContext>()), Times.Once()); mockInterceptor.Verify(m => m.Opened(mockConnection.Object, It.IsAny <DbConnectionInterceptionContext>()), Times.Once()); }
public void Open_executes_operation_and_dispatches_to_interceptors() { var mockConnection = new Mock<DbConnection>(); var mockInterceptor = new Mock<IDbConnectionInterceptor>(); var dispatcher = new DbConnectionDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); var interceptionContext = new DbConnectionInterceptionContext(); dispatcher.Open(mockConnection.Object, interceptionContext); mockConnection.Verify(m => m.Open(), Times.Once()); mockInterceptor.Verify(m => m.Opening(mockConnection.Object, It.IsAny<DbConnectionInterceptionContext>()), Times.Once()); mockInterceptor.Verify(m => m.Opened(mockConnection.Object, It.IsAny<DbConnectionInterceptionContext>()), Times.Once()); }
public void GetState_executes_operation_and_dispatches_to_interceptors() { var mockConnection = new Mock<DbConnection>(); var mockInterceptor = new Mock<IDbConnectionInterceptor>(); var dispatcher = new DbConnectionDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); var interceptionContext = new DbInterceptionContext(); dispatcher.GetState(mockConnection.Object, interceptionContext); mockConnection.Verify(m => m.State, Times.Once()); mockInterceptor.Verify(m => m.StateGetting(mockConnection.Object, It.IsAny<DbConnectionInterceptionContext<ConnectionState>>()), Times.Once()); mockInterceptor.Verify(m => m.StateGot(mockConnection.Object, It.IsAny<DbConnectionInterceptionContext<ConnectionState>>()), Times.Once()); }
public void SetConnectionString_executes_operation_and_dispatches_to_interceptors() { var mockConnection = new Mock<DbConnection>(); var mockInterceptor = new Mock<IDbConnectionInterceptor>(); var dispatcher = new DbConnectionDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); var interceptionContext = new DbConnectionPropertyInterceptionContext<string>().WithValue("foo"); dispatcher.SetConnectionString(mockConnection.Object, interceptionContext); mockConnection.VerifySet(m => m.ConnectionString = "foo", Times.Once()); mockInterceptor.Verify(m => m.ConnectionStringSetting(mockConnection.Object, It.IsAny<DbConnectionPropertyInterceptionContext<string>>()), Times.Once()); mockInterceptor.Verify(m => m.ConnectionStringSet(mockConnection.Object, It.IsAny<DbConnectionPropertyInterceptionContext<string>>()), Times.Once()); }
public void OpenAsync_executes_operation_and_dispatches_to_interceptors() { var mockConnection = new Mock<DbConnection>(); mockConnection.Setup(m => m.OpenAsync(It.IsAny<CancellationToken>())).Returns(() => Task.FromResult(true)); var mockInterceptor = new Mock<IDbConnectionInterceptor>(); var dispatcher = new DbConnectionDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); var interceptionContext = new DbConnectionInterceptionContext(); dispatcher.OpenAsync(mockConnection.Object, interceptionContext, CancellationToken.None).Wait(); mockConnection.Verify(m => m.OpenAsync(CancellationToken.None), Times.Once()); mockInterceptor.Verify(m => m.Opening(mockConnection.Object, It.IsAny<DbConnectionInterceptionContext>()), Times.Once()); mockInterceptor.Verify(m => m.Opened(mockConnection.Object, It.IsAny<DbConnectionInterceptionContext>()), Times.Once()); }