public void Dispatch_method_executes_command_and_dispatches_to_interceptors_which_can_change_result() { var interceptionContext = new DbInterceptionContext(); var mockCommand = new Mock<DbCommand>(); mockCommand.Setup(m => m.ExecuteScalar()).Returns(11); var mockInterceptor = new Mock<IDbCommandInterceptor>(); mockInterceptor.Setup(m => m.ScalarExecuted(mockCommand.Object, 11, interceptionContext)).Returns(13); var dispatcher = new DbCommandDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); Assert.Equal(13, dispatcher.Scalar(mockCommand.Object, interceptionContext)); mockCommand.Verify(m => m.ExecuteScalar()); mockInterceptor.Verify(m => m.ScalarExecuting(mockCommand.Object, interceptionContext)); mockInterceptor.Verify(m => m.ScalarExecuted(mockCommand.Object, 11, interceptionContext)); }
public void Dispatch_method_executes_command_and_dispatches_to_interceptors_which_can_change_result() { var interceptionContext = new DbInterceptionContext(); var cancellationToken = new CancellationToken(); var result = new Task<DbDataReader>(() => new Mock<DbDataReader>().Object); var mockCommand = new Mock<DbCommand>(); mockCommand.Protected() .Setup<Task<DbDataReader>>("ExecuteDbDataReaderAsync", CommandBehavior.SequentialAccess, cancellationToken) .Returns(result); var mockInterceptor = new Mock<IDbCommandInterceptor>(); var interceptResult = new Task<DbDataReader>(() => new Mock<DbDataReader>().Object); mockInterceptor.Setup( m => m.AsyncReaderExecuted(mockCommand.Object, CommandBehavior.SequentialAccess, result, interceptionContext)) .Returns(interceptResult); var dispatcher = new DbCommandDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); Assert.Same( interceptResult, dispatcher.AsyncReader(mockCommand.Object, CommandBehavior.SequentialAccess, cancellationToken, interceptionContext)); mockCommand.Protected() .Verify("ExecuteDbDataReaderAsync", Times.Once(), CommandBehavior.SequentialAccess, cancellationToken); mockInterceptor.Verify( m => m.AsyncReaderExecuting(mockCommand.Object, CommandBehavior.SequentialAccess, interceptionContext)); mockInterceptor.Verify( m => m.AsyncReaderExecuted(mockCommand.Object, CommandBehavior.SequentialAccess, result, interceptionContext)); }
public void Dispatch_method_executes_command_and_dispatches_to_interceptors_which_can_change_result() { var interceptionContext = new DbInterceptionContext(); var cancellationToken = new CancellationToken(); var mockCommand = new Mock<DbCommand>(); var result = new Task<object>(() => 11); mockCommand.Setup(m => m.ExecuteScalarAsync(cancellationToken)).Returns(result); var mockInterceptor = new Mock<IDbCommandInterceptor>(); var interceptResult = new Task<object>(() => 13); mockInterceptor.Setup(m => m.AsyncScalarExecuted(mockCommand.Object, result, interceptionContext)).Returns(interceptResult); var dispatcher = new DbCommandDispatcher(); var internalDispatcher = dispatcher.InternalDispatcher; internalDispatcher.Add(mockInterceptor.Object); Assert.Same(interceptResult, dispatcher.AsyncScalar(mockCommand.Object, cancellationToken, interceptionContext)); mockCommand.Verify(m => m.ExecuteScalarAsync(cancellationToken)); mockInterceptor.Verify(m => m.AsyncScalarExecuting(mockCommand.Object, interceptionContext)); mockInterceptor.Verify(m => m.AsyncScalarExecuted(mockCommand.Object, result, interceptionContext)); }