Ejemplo n.º 1
0
        public void CanExecutePipelineNoTarget()
        {
            var pipeline = new BehaviorPipeline(new ExecuteDelegate((m, n) => m.CreateValueReturn(null)));

            Action a = CanExecutePipelineNoTarget;

            pipeline.Execute(new MethodInvocation(this, a.GetMethodInfo()));
        }
Ejemplo n.º 2
0
        public void WhenExecutingPipelineWithNoTarget_ThenThrowsIfNoBehaviorReturns()
        {
            var pipeline = new BehaviorPipeline();

            Action a = CanExecutePipelineNoTarget;

            Assert.Throws <NotImplementedException>(() => pipeline.Execute(new MethodInvocation(this, a.GetMethodInfo())));
        }
Ejemplo n.º 3
0
        public void CanExecutePipelineWithTarget()
        {
            var pipeline = new BehaviorPipeline();

            Action a = CanExecutePipelineWithTarget;

            pipeline.Execute(MethodInvocation.Create(this, a.GetMethodInfo(), (m, n) => m.CreateReturn()));
        }
Ejemplo n.º 4
0
        public void WhenExecutingPipelineResultWithNoTarget_ThenThrowsIfNoResult()
        {
            var pipeline = new BehaviorPipeline();

            Func <object> f = NonVoidMethod;

            Assert.Throws <NotImplementedException>(()
                                                    => pipeline.Execute <object>(new MethodInvocation(this, f.GetMethodInfo())));
        }
Ejemplo n.º 5
0
        public void CanExecutePipelineResultNoTarget()
        {
            var value = new object();

            var pipeline = new BehaviorPipeline(new ExecuteDelegate((m, n) => m.CreateValueReturn(value)));

            Func <object> f = NonVoidMethod;

            Assert.Same(value, pipeline.Execute <object>(new MethodInvocation(this, f.GetMethodInfo())));
        }
Ejemplo n.º 6
0
        public void WhenExecutingPipelineResult_ThenBehaviorCanThrow()
        {
            var pipeline = new BehaviorPipeline(
                new ExecuteHandler((m, n) => m.CreateExceptionReturn(new ArgumentException())));

            Func <object?> f = NonVoidMethod;

            Assert.Throws <ArgumentException>(()
                                              => pipeline.Execute <object>(MethodInvocation.Create(this, f.GetMethodInfo())));
        }
Ejemplo n.º 7
0
        public void WhenExecutingPipeline_ThenBehaviorCanThrow()
        {
            var pipeline = new BehaviorPipeline(
                new ExecuteHandler((m, n) => m.CreateExceptionReturn(new ArgumentException())));

            Action a = WhenInvokingPipeline_ThenBehaviorsCanReturnException;

            Assert.Throws <ArgumentException>(()
                                              => pipeline.Execute(MethodInvocation.Create(this, a.GetMethodInfo())));
        }
Ejemplo n.º 8
0
        public void WhenExecutingPipelineResult_ThenBehaviorCanThrow()
        {
            var pipeline = new BehaviorPipeline(
                new ExecuteDelegate((m, n) => m.CreateExceptionReturn(new ArgumentException())));

            Func <object> f = NonVoidMethod;

            Assert.Throws <ArgumentException>(()
                                              => pipeline.Execute <object>(new MethodInvocation(this, f.GetMethodInfo()),
                                                                           new ExecuteDelegate((m, n) => throw new NotImplementedException())));
        }
Ejemplo n.º 9
0
        public void WhenSkippingBehavior_ThenBehaviorIsNotExecuted()
        {
            var pipeline = new BehaviorPipeline();

            pipeline.Behaviors.Add(new TestBehavior());

            var invocation = MethodInvocation.Create(new object(), typeof(object).GetMethod("ToString") !);

            invocation.SkipBehavior <TestBehavior>();

            Assert.Throws <NotImplementedException>(()
                                                    => pipeline.Execute <string>(invocation));
        }
Ejemplo n.º 10
0
 public override bool Equals(object obj) => pipeline.Execute <bool>(new MethodInvocation(this, MethodBase.GetCurrentMethod(), obj));
Ejemplo n.º 11
0
 public void Add(int value) => pipeline.Execute(new MethodInvocation(this, MethodBase.GetCurrentMethod(), value));
Ejemplo n.º 12
0
 public void Do() => pipeline.Execute(new MethodInvocation(this, MethodBase.GetCurrentMethod()));