public void Should_properly_handle_exception()
        {
            IPipe <TestPipeContext> pipe = Pipe.New <TestPipeContext>(x =>
            {
                x.UseTransaction();
                x.UseExecute(payload => Console.WriteLine("Execute: {0}", Thread.CurrentThread.ManagedThreadId));
                x.UseExecuteAsync(async payload =>
                {
                    await Task.Yield();

                    using (TransactionScope scope = payload.CreateTransactionScope())
                    {
                        Console.WriteLine("ExecuteAsync: {0}", Thread.CurrentThread.ManagedThreadId);

                        Assert.IsNotNull(Transaction.Current);
                        Console.WriteLine("Isolation Level: {0}", Transaction.Current.IsolationLevel);

                        scope.Complete();
                    }

                    throw new InvalidOperationException("This is a friendly boom");
                });
                x.UseExecute(payload => Console.WriteLine("After Transaction: {0}", Thread.CurrentThread.ManagedThreadId));
            });

            var context = new TestPipeContext();

            var exception = Assert.Throws <InvalidOperationException>(async() => await pipe.Send(context));

            Console.WriteLine(exception.Message);
        }
        public void Should_timeout()
        {
            IPipe <TestPipeContext> pipe = Pipe.New <TestPipeContext>(x =>
            {
                x.UseTransaction(t => t.Timeout = TimeSpan.FromSeconds(1));
                x.UseExecute(payload => Console.WriteLine("Execute: {0}", Thread.CurrentThread.ManagedThreadId));
                x.UseExecuteAsync(async payload =>
                {
                    await Task.Yield();

                    using (TransactionScope scope = payload.CreateTransactionScope())
                    {
                        Console.WriteLine("ExecuteAsync: {0}", Thread.CurrentThread.ManagedThreadId);

                        Assert.IsNotNull(Transaction.Current);
                        Console.WriteLine("Isolation Level: {0}", Transaction.Current.IsolationLevel);

                        Thread.Sleep(2000);

                        scope.Complete();
                    }

                    Console.WriteLine("Exited Scope");
                });
                x.UseExecute(payload => Console.WriteLine("After Transaction: {0}", Thread.CurrentThread.ManagedThreadId));
            });

            var context = new TestPipeContext();

            var exception = Assert.Throws <TransactionAbortedException>(async() => await pipe.Send(context));

            Console.WriteLine(exception.Message);
        }
        public async Task Should_properly_succeed()
        {
            IPipe <TestPipeContext> pipe = Pipe.New <TestPipeContext>(x =>
            {
                x.UseTransaction();
                x.UseExecute(payload => Console.WriteLine("Execute: {0}", Thread.CurrentThread.ManagedThreadId));
                x.UseExecuteAsync(payload => Task.Run(() =>
                {
                    using (TransactionScope scope = payload.CreateTransactionScope())
                    {
                        Console.WriteLine("ExecuteAsync: {0}", Thread.CurrentThread.ManagedThreadId);

                        Assert.IsNotNull(Transaction.Current);
                        Console.WriteLine("Isolation Level: {0}", Transaction.Current.IsolationLevel);
                        scope.Complete();
                    }
                }));
            });

            var context = new TestPipeContext();

            await pipe.Send(context);
        }
        public void Should_properly_fail()
        {
            IPipe <TestPipeContext> pipe = Pipe.New <TestPipeContext>(x =>
            {
                x.UseTransaction();
                x.UseExecute(payload => Console.WriteLine("Execute: {0}", Thread.CurrentThread.ManagedThreadId));
                x.UseExecuteAsync(payload => Task.Run(() =>
                {
                    using (TransactionScope scope = payload.CreateTransactionScope())
                    {
                        Console.WriteLine("ExecuteAsync: {0}", Thread.CurrentThread.ManagedThreadId);

                        Assert.IsNotNull(Transaction.Current);
                        Console.WriteLine("Isolation Level: {0}", Transaction.Current.IsolationLevel);
                    }
                }));
            });

            var context = new TestPipeContext();

            var exception = Assert.Throws <TransactionAbortedException>(async() => await pipe.Send(context));

            Console.WriteLine(exception.Message);
        }