示例#1
0
        public void WhenCreatingInstanceThenPropertiesAreDefined()
        {
            // Arrange & Act
            TransactionFilterAttribute filter = new TransactionFilterAttribute();

            // Assert
            Assert.Equal(TransactionScopeOption.Required, filter.ScopeOption);
            Assert.Equal(TransactionManager.DefaultTimeout, filter.Timeout);
            Assert.Equal(IsolationLevel.Serializable, filter.IsolationLevel);
        }
示例#2
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);
        }
示例#3
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);
        }