public void WhenExecuteExceptionFilterAsyncWithoutContextThenThrowsArgumentNullException()
        {
            // Arrange
            Mock<MessageProcessorTests.ISpy> spy = new Mock<MessageProcessorTests.ISpy>();
            IExceptionFilter filter = new CustomExceptionFilterAttribute(spy.Object);
        
            CancellationToken cancellationToken = new CancellationToken();

            // Act
            ExceptionAssert.ThrowsArgumentNull(() => filter.ExecuteExceptionFilterAsync(null, cancellationToken), "handlerExecutedContext");

            // Assert
            spy.Verify(s => s.Spy("OnException"), Times.Never());
        }
        public void WhenExecuteExceptionFilterAsyncWithoutContextThenThrowsArgumentNullException()
        {
            // Arrange
            Mock <MessageProcessorTests.ISpy> spy = new Mock <MessageProcessorTests.ISpy>();
            IExceptionFilter filter = new CustomExceptionFilterAttribute(spy.Object);

            CancellationToken cancellationToken = new CancellationToken();

            // Act
            ExceptionAssert.ThrowsArgumentNull(() => filter.ExecuteExceptionFilterAsync(null, cancellationToken), "handlerExecutedContext");

            // Assert
            spy.Verify(s => s.Spy("OnException"), Times.Never());
        }
        public void WhenExecuteExceptionFilterAsyncThenReturnsCompletedTask()
        {
            // Arrange
            Mock<MessageProcessorTests.ISpy> spy = new Mock<MessageProcessorTests.ISpy>();
            IExceptionFilter filter = new CustomExceptionFilterAttribute(spy.Object);
            CommandHandlerContext handlerContext = new CommandHandlerContext();
            Exception exception = new Exception();
            ExceptionDispatchInfo exceptionInfo = ExceptionDispatchInfo.Capture(exception);
            CommandHandlerExecutedContext handlerExecutedContext = new CommandHandlerExecutedContext(handlerContext, exceptionInfo);
            CancellationToken cancellationToken = new CancellationToken();

            // Act
            var task = filter.ExecuteExceptionFilterAsync(handlerExecutedContext, cancellationToken);

            // Assert
            Assert.NotNull(task);
            Assert.True(task.IsCompleted);
            spy.Verify(s => s.Spy("OnException"), Times.Once());
        }
        public void WhenExecuteExceptionFilterAsyncThenReturnsCompletedTask()
        {
            // Arrange
            Mock <MessageProcessorTests.ISpy> spy                = new Mock <MessageProcessorTests.ISpy>();
            IExceptionFilter              filter                 = new CustomExceptionFilterAttribute(spy.Object);
            CommandHandlerContext         handlerContext         = new CommandHandlerContext();
            Exception                     exception              = new Exception();
            ExceptionDispatchInfo         exceptionInfo          = ExceptionDispatchInfo.Capture(exception);
            CommandHandlerExecutedContext handlerExecutedContext = new CommandHandlerExecutedContext(handlerContext, exceptionInfo);
            CancellationToken             cancellationToken      = new CancellationToken();

            // Act
            var task = filter.ExecuteExceptionFilterAsync(handlerExecutedContext, cancellationToken);

            // Assert
            Assert.NotNull(task);
            Assert.True(task.IsCompleted);
            spy.Verify(s => s.Spy("OnException"), Times.Once());
        }
Exemple #5
0
 protected void Init()
 {
     CustomExceptionFilterAttribute = new CustomExceptionFilterAttribute();
 }