public void CanExecutePipelineNoTarget() { var pipeline = new BehaviorPipeline(new ExecuteDelegate((m, n) => m.CreateValueReturn(null))); Action a = CanExecutePipelineNoTarget; pipeline.Execute(new MethodInvocation(this, a.GetMethodInfo())); }
public void CanExecutePipelineWithTarget() { var pipeline = new BehaviorPipeline(); Action a = CanExecutePipelineWithTarget; pipeline.Execute(MethodInvocation.Create(this, a.GetMethodInfo(), (m, n) => m.CreateReturn())); }
public void WhenExecutingPipelineWithNoTarget_ThenThrowsIfNoBehaviorReturns() { var pipeline = new BehaviorPipeline(); Action a = CanExecutePipelineNoTarget; Assert.Throws <NotImplementedException>(() => pipeline.Execute(new MethodInvocation(this, a.GetMethodInfo()))); }
public void WhenInvokingPipelineWithNoBehaviors_ThenTargetCannotInvokeNext() { var pipeline = new BehaviorPipeline(); Action a = WhenInvokingPipelineWithNoBehaviors_ThenInvokesTarget; Assert.Throws <NotSupportedException>(() => pipeline.Invoke( new MethodInvocation(this, a.GetMethodInfo(), (m, n) => n.Invoke(m, n)))); }
public void WhenExecutingPipelineResultWithNoTarget_ThenThrowsIfNoResult() { var pipeline = new BehaviorPipeline(); Func <object> f = NonVoidMethod; Assert.Throws <NotImplementedException>(() => pipeline.Execute <object>(new MethodInvocation(this, f.GetMethodInfo()))); }
public void WhenInvokingPipeline_ThenBehaviorsCanReturnException() { var pipeline = new BehaviorPipeline( new ExecuteHandler((m, n) => m.CreateExceptionReturn(new ArgumentException()))); Action a = WhenInvokingPipeline_ThenBehaviorsCanReturnException; Assert.Throws <ArgumentException>(() => pipeline.Invoke(MethodInvocation.Create(this, a.GetMethodInfo()), true)); }
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()))); }
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()))); }
public void WhenExecutingPipeline_ThenBehaviorCanThrow() { var pipeline = new BehaviorPipeline( new ExecuteDelegate((m, n) => m.CreateExceptionReturn(new ArgumentException()))); Action a = WhenInvokingPipeline_ThenBehaviorsCanReturnException; Assert.Throws <ArgumentException>(() => pipeline.Execute(new MethodInvocation(this, a.GetMethodInfo()), new ExecuteDelegate((m, n) => throw new NotImplementedException()))); }
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()))); }
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)); }
public void WhenInvokingPipeline_ThenBehaviorsCanReturnValueWithArg() { var expected = new object(); var pipeline = new BehaviorPipeline( new ExecuteHandler((m, n) => m.CreateValueReturn(expected, m.Arguments))); Func <object, object?> a = NonVoidMethodWithArg; var result = pipeline.Invoke(MethodInvocation.Create(this, a.GetMethodInfo(), expected)); Assert.Equal(expected, result.ReturnValue); }
public void WhenInvokingPipelineWithNoBehaviors_ThenInvokesTarget() { var targetCalled = false; var pipeline = new BehaviorPipeline(); Action a = WhenInvokingPipelineWithNoBehaviors_ThenInvokesTarget; pipeline.Invoke(new MethodInvocation(this, a.GetMethodInfo()), new ExecuteDelegate((m, n) => { targetCalled = true; return(m.CreateValueReturn(null)); })); Assert.True(targetCalled); }
public void WhenInvokingPipeline_ThenBehaviorsCanReturnValueWithArg() { var expected = new object(); var pipeline = new BehaviorPipeline( new ExecuteDelegate((m, n) => m.CreateValueReturn(expected, new object()))); Func <object, object> a = NonVoidMethodWithArg; var result = pipeline.Invoke(new MethodInvocation(this, a.GetMethodInfo(), expected), new ExecuteDelegate((m, n) => throw new NotImplementedException())); Assert.Equal(expected, result.ReturnValue); }
public void WhenInvokingPipeline_ThenBehaviorsCanReturnValueWithOut() { var expected = new object(); var output = new object(); var pipeline = new BehaviorPipeline( new ExecuteHandler((m, n) => m.CreateValueReturn(expected, new object(), output))); NonVoidMethodWithArgOutDelegate a = NonVoidMethodWithArgOut; var result = pipeline.Invoke(MethodInvocation.Create(this, a.GetMethodInfo(), expected, output)); Assert.Equal(expected, result.ReturnValue); Assert.Equal(output, result.Outputs.GetValue(0)); }
public void WhenInvokingPipeline_ThenBehaviorsCanReturnValueWithOut() { var expected = new object(); var output = new object(); var pipeline = new BehaviorPipeline( new InvokeBehavior((m, n) => m.CreateValueReturn(expected, new object(), output))); NonVoidMethodWithArgOutDelegate a = NonVoidMethodWithArgOut; var result = pipeline.Invoke(new MethodInvocation(this, a.GetMethodInfo(), expected, output), new InvokeBehavior((m, n) => throw new NotImplementedException())); Assert.Equal(expected, result.ReturnValue); Assert.Equal(output, result.Outputs[0]); }
public void WhenCloningBehaviors_ThenCanManipulateCopyWithoutAffectingOriginal() { var pipeline = new BehaviorPipeline(); pipeline.Behaviors.Add(new TestBehavior()); pipeline.Behaviors.Add(new TestBehavior()); pipeline.Behaviors.Add(new TestBehavior()); var clone = (IList <IAvatarBehavior>)((ICloneable)pipeline.Behaviors).Clone(); Assert.True(pipeline.Behaviors.SequenceEqual(clone)); clone.Clear(); Assert.NotEmpty(pipeline.Behaviors); Assert.Empty(clone); }
public void WhenInvokingPipeline_ThenBehaviorsCanPassDataWithContext() { var expected = Guid.NewGuid(); var actual = Guid.Empty; var pipeline = new BehaviorPipeline( new ExecuteHandler((m, n) => { m.Context["guid"] = expected; return(n.Invoke(m, n)); }), new ExecuteHandler((m, n) => { actual = (Guid)m.Context["guid"]; return(n.Invoke(m, n)); })); Action a = WhenInvokingPipeline_ThenBehaviorsCanPassDataWithContext; var result = pipeline.Invoke(MethodInvocation.Create(this, a.GetMethodInfo(), (m, n) => m.CreateReturn())); Assert.Equal(expected, actual); Assert.True(result.Context.ContainsKey("guid")); Assert.Equal(expected, result.Context["guid"]); }
public void WhenInvokingPipeline_ThenSkipsNonApplicableBehaviors() { var firstCalled = false; var secondCalled = false; var targetCalled = false; var pipeline = new BehaviorPipeline( new AnonymousBehavior((m, n) => { firstCalled = true; return(n.Invoke(m, n)); }), new AnonymousBehavior((m, n) => { secondCalled = true; return(n.Invoke(m, n)); }, m => false)); Action a = WhenInvokingPipeline_ThenInvokesAllBehaviorsAndTarget; pipeline.Invoke(MethodInvocation.Create(this, a.GetMethodInfo(), (m, n) => { targetCalled = true; return(m.CreateReturn()); })); Assert.True(firstCalled); Assert.False(secondCalled); Assert.True(targetCalled); }
public void WhenInvokingPipeline_ThenBehaviorCanShortcircuitInvocation() { var firstCalled = false; var secondCalled = false; var targetCalled = false; var pipeline = new BehaviorPipeline( new ExecuteDelegate((m, n) => { firstCalled = true; return(m.CreateValueReturn(null)); }), new ExecuteDelegate((m, n) => { secondCalled = true; return(n().Invoke(m, n)); })); Action a = WhenInvokingPipeline_ThenBehaviorCanShortcircuitInvocation; pipeline.Invoke(new MethodInvocation(this, a.GetMethodInfo()), new ExecuteDelegate((m, n) => { targetCalled = true; return(m.CreateValueReturn(null)); })); Assert.True(firstCalled); Assert.False(secondCalled); Assert.False(targetCalled); }
public void WhenInvokingPipeline_ThenSkipsNonApplicableBehaviors() { var firstCalled = false; var secondCalled = false; var targetCalled = false; var pipeline = new BehaviorPipeline( StuntBehavior.Create((m, n) => { firstCalled = true; return(n().Invoke(m, n)); }), StuntBehavior.Create((m, n) => { secondCalled = true; return(n().Invoke(m, n)); }, m => false)); Action a = WhenInvokingPipeline_ThenInvokesAllBehaviorsAndTarget; pipeline.Invoke(new MethodInvocation(this, a.GetMethodInfo()), new ExecuteDelegate((m, n) => { targetCalled = true; return(m.CreateValueReturn(null)); })); Assert.True(firstCalled); Assert.False(secondCalled); Assert.True(targetCalled); }
public void WhenInvokingPipeline_ThenInvokesAllBehaviorsAndTarget() { var firstCalled = false; var secondCalled = false; var targetCalled = false; var pipeline = new BehaviorPipeline( new InvokeBehavior((m, n) => { firstCalled = true; return(n().Invoke(m, n)); }), new InvokeBehavior((m, n) => { secondCalled = true; return(n().Invoke(m, n)); })); Action a = WhenInvokingPipeline_ThenInvokesAllBehaviorsAndTarget; pipeline.Invoke(new MethodInvocation(this, a.GetMethodInfo()), new InvokeBehavior((m, n) => { targetCalled = true; return(m.CreateValueReturn(null)); })); Assert.True(firstCalled); Assert.True(secondCalled); Assert.True(targetCalled); }
public void WhenAddingMultipleBehaviors_ThenCanOptimizeCollectionChanges() { var changes = new List <NotifyCollectionChangedAction>(); var pipeline = new BehaviorPipeline(); ((INotifyCollectionChanged)pipeline.Behaviors).CollectionChanged += (sender, args) => changes.Add(args.Action); (pipeline.Behaviors as ISupportInitialize)?.BeginInit(); pipeline.Behaviors.Add(new TestBehavior()); pipeline.Behaviors.Add(new TestBehavior()); pipeline.Behaviors.Add(new TestBehavior()); Assert.Empty(changes); (pipeline.Behaviors as ISupportInitialize)?.EndInit(); Assert.Single(changes); Assert.Equal(NotifyCollectionChangedAction.Reset, changes[0]); }
internal DynamicStuntInterceptor(bool notImplemented) { this.notImplemented = notImplemented; pipeline = new BehaviorPipeline(); }
internal Interceptor () { pipeline = new BehaviorPipeline (); }
public CalculatorInterfaceProxy() { pipeline = new BehaviorPipeline(); }
public CalculatorClassProxy () { pipeline = new BehaviorPipeline (); }
internal Interceptor() { pipeline = new BehaviorPipeline(); }
public CalculatorClassProxy() { pipeline = new BehaviorPipeline(); }
public CalculatorInterfaceProxy () { pipeline = new BehaviorPipeline (); }