public void MultipleAspect_ThrowException_In_OnEntry_Handled_InnerAspects_OnEntry_OnExit_Called()
        {
            // Arrange
            var afterBreaker = new ObservableAspect {
                InternalOrder = 2
            };
            var breaker = new ThrowAspect(typeof(ApplicationException), BoundaryType.Entry)
            {
                InternalOrder = 1
            };
            var beforeBreaker = new ObservableAspect()
            {
                InternalOrder = 0
            };

            var pipeline = CreatePipeline <IService>(
                new Service(), nameof(IService.Identity),
                Args.Pack <MethodBoundaryAspect>(beforeBreaker, breaker, afterBreaker),
                Args.Box(10));

            // Assert
            Assert.Throws <ApplicationException>(() => _executor.ExecutePipeline(pipeline, pipeline.Invocation));
            Assert.Empty(afterBreaker.ExecutionStack);
            Assert.Equal(new []
            {
                new BoundaryState(BoundaryType.Exit),
                new BoundaryState(BoundaryType.Entry),
            }, beforeBreaker.ExecutionStack);

            Assert.Equal(new []
            {
                new BoundaryState(BoundaryType.Entry)
            }, breaker.ExecutionStack);
        }
        public void SingleAspect_If_UnhandledException_Occuring_InBoundary_It_Breakes_Pipeline_And_Throws_Outsite()
        {
            // Arrange
            var aspect   = new ThrowAspect(typeof(ArgumentException), BoundaryType.Entry, throwAsUnhandled: true);
            var pipeline = CreatePipeline <IService>(
                new Service(), nameof(IService.Identity), Args.Pack(aspect), Args.Box(10));

            // Act && Assert
            Assert.Throws <ArgumentException>(() => _executor.ExecutePipeline(pipeline, pipeline.Invocation));

            InvocationAssert.ProceedNotCalled(pipeline.Invocation);
            Assert.Equal(BoundaryType.Entry, aspect.ExecutionStack.Pop().BoundaryType);
        }
        public void SingleAspect_If_HandledException_Occuring_InBoundary_OnEntry_OtherAspectsShouldNotBeCalled()
        {
            // Arrange
            var aspect   = new ThrowAspect(typeof(ArgumentException), BoundaryType.Entry);
            var pipeline = CreatePipeline <IService>(
                new Service(), nameof(IService.Identity), Args.Pack(aspect), Args.Box(10));

            // Act && Assert
            Assert.Throws <ArgumentException>(() => _executor.ExecutePipeline(pipeline, pipeline.Invocation));

            InvocationAssert.ProceedNotCalled(pipeline.Invocation);
            Assert.Equal(new[]
            {
                new BoundaryState(BoundaryType.Entry),
            }, aspect.ExecutionStack);
        }
        public async Task SingleAspect_UnhandledException_ShouldBreakPipeline()
        {
            // Arrange
            var aspect   = new ThrowAspect(typeof(ArgumentException), BoundaryType.Entry, throwAsUnhandled: true);
            var pipeline = CreatePipeline <IService>(
                new Service(), nameof(IService.IdentityAsync), Args.Pack(aspect), Args.Box(10));

            // Act
            _executor.ExecutePipeline(pipeline, pipeline.Invocation);

            await Assert.ThrowsAsync <ArgumentException>(
                async() => await Await <int>(pipeline.Invocation));

            // Assert
            Assert.Equal(new [] { new BoundaryState(BoundaryType.Entry) }, aspect.ExecutionStack);

            Assert.IsType <ArgumentException>(pipeline.CurrentException);
            InvocationAssert.ProceedNotCalled(pipeline.Invocation);
        }
        public void SingleAspect_CallThrow_AfterMethodExecution_ShouldThrow()
        {
            // Arrange
            var aspect   = new ThrowAspect(typeof(ArgumentException), BoundaryType.Success, throwAsUnhandled: false);
            var pipeline = CreatePipeline <IService>(
                new Service(), nameof(IService.Identity), Args.Pack(aspect), Args.Box(10));

            // Act
            Assert.Throws <ArgumentException>(() => _executor.ExecutePipeline(pipeline, pipeline.Invocation));

            // Assert
            Assert.Equal(new []
            {
                new BoundaryState(BoundaryType.Success),
                new BoundaryState(BoundaryType.Entry)
            }, aspect.ExecutionStack);

            Assert.IsType <ArgumentException>(pipeline.CurrentException);
            InvocationAssert.ProceedCalled(pipeline.Invocation);
        }