Ejemplo n.º 1
0
        public void WhenInvokingFilterWithExceptionThenTransactionRollbacks()
        {
            // Arrange
            TransactionFilterAttribute filter             = new TransactionFilterAttribute();
            CommandHandlerContext      executingContext   = new CommandHandlerContext();
            Exception                     exception       = new Exception();
            ExceptionDispatchInfo         exceptionInfo   = ExceptionDispatchInfo.Capture(exception);
            CommandHandlerExecutedContext executedContext = new CommandHandlerExecutedContext(executingContext, exceptionInfo);

            // Act
            filter.OnCommandExecuting(executingContext);
            Transaction transaction = Transaction.Current.Clone();

            filter.OnCommandExecuted(executedContext);

            // Assert
            Assert.Equal(TransactionStatus.Aborted, transaction.TransactionInformation.Status);
        }
Ejemplo n.º 2
0
        public void WhenInvokingFilterWithoutExceptionThenTransactionCompletes()
        {
            // Arrange
            TransactionFilterAttribute filter           = new TransactionFilterAttribute();
            HandlerRequest             request          = new HandlerRequest(this.config, null);
            CommandHandlerContext      executingContext = new CommandHandlerContext();

            CommandHandlerExecutedContext executedContext = new CommandHandlerExecutedContext(executingContext, null);

            executingContext.Response = new HandlerResponse(null);

            // Act
            filter.OnCommandExecuting(executingContext);
            Transaction transaction = Transaction.Current.Clone();

            filter.OnCommandExecuted(executedContext);

            // Assert
            Assert.Equal(TransactionStatus.Committed, transaction.TransactionInformation.Status);
        }