public void when_proxy_factory_invoked_then_gets_implementation_of_interface() { var factory = new ProxyFactory(); var mock = new TestMock(); var proxy = factory.CreateProxy(mock, typeof(ICalculator)); Assert.NotNull(proxy); Assert.True(proxy is ICalculator); }
public void when_invocation_performed_then_records_invocation() { var invocation = new TestInvocation(() => null); var mock = new TestMock(); mock.Invoke(invocation); Assert.Equal(1, mock.Invocations.Count); Assert.Same(invocation, mock.Invocations[0]); }
public void when_proxy_instance_called_then_can_retrieve_invocation_method() { var factory = new ProxyFactory(); var mock = new TestMock(defaultValue: 10); var proxy = (ICalculator)factory.CreateProxy(mock, typeof(ICalculator)); proxy.Add(5, 5); Assert.Equal(typeof(ICalculator).GetMethod("Add"), mock.LastCall.Method); }
public void when_proxy_instance_called_then_can_retrieve_mock_from_invocation() { var factory = new ProxyFactory(); var mock = new TestMock(defaultValue: 15); var proxy = (ICalculator)factory.CreateProxy(mock, typeof(ICalculator)); proxy.Add(5, 10); Assert.Same(mock, mock.LastCall.Mock); }
public void when_interface_proxy_called_then_can_set_return_value() { var factory = new ProxyFactory(); var mock = new TestMock(100); var proxy = (ICalculator)factory.CreateProxy(mock, typeof(ICalculator)); var result = proxy.Add(5, 10); Assert.Equal(100, result); }
public void when_class_proxy_instance_called_then_can_invoke_base_implementation_from_invocation() { var factory = new ProxyFactory(); var mock = new TestMock(defaultValue: 15, callBase: true); var proxy = (ICalculator)factory.CreateProxy(mock, typeof(ICalculator)); var result = proxy.Add(5, 10); Assert.Equal(15, result); }
public void when_proxy_instance_called_then_calls_back_into_mock_behavior() { var factory = new ProxyFactory(); var mock = new TestMock(defaultValue: 10); var proxy = (ICalculator)factory.CreateProxy(mock, typeof(ICalculator)); proxy.Add(5, 5); Assert.NotNull(mock.LastCall); }
public void when_proxy_instance_called_then_can_retrieve_invocation_target() { var factory = new ProxyFactory(); var mock = new TestMock(defaultValue: 15); var proxy = (ICalculator)factory.CreateProxy(mock, typeof(ICalculator)); proxy.Add(5, 10); Assert.Same(proxy, mock.LastCall.Target); }
public void when_proxy_instance_called_then_can_retrieve_invocation_arguments() { var factory = new ProxyFactory(); var mock = new TestMock(defaultValue: 15); var proxy = (ICalculator)factory.CreateProxy(mock, typeof(ICalculator)); proxy.Add(5, 10); Assert.Equal(5, (int)mock.LastCall.Arguments[0]); Assert.Equal(10, (int)mock.LastCall.Arguments[1]); }
public void when_behavior_is_executed_then_behavior_tracks_invocation() { var mock = new TestMock(); var invocation = new TestInvocation(() => null); var behavior = new CompositeBehavior(i => true); mock.Behaviors.Add(behavior); mock.Invoke(invocation); Assert.Equal(1, behavior.Invocations.Count); Assert.Same(invocation, behavior.Invocations[0]); }
public void when_behavior_matches_invocation_then_it_is_called() { var mock = new TestMock(); IInvocation invocation = null; var behavior = new DelegateBehavior(i => invocation = i); mock.Behaviors.Add(behavior); mock.Invoke(new TestInvocation(() => null)); Assert.NotNull(invocation); }
public void when_behavior_throws_then_invocation_is_still_recorded() { var mock = new TestMock(); var invocation = new TestInvocation(() => null); var behavior = new CompositeBehavior(i => true) { Invoke = { new DelegateBehavior(i => { throw new ArgumentException(); }) } }; mock.Behaviors.Add(behavior); Assert.Throws <ArgumentException>(() => mock.Invoke(invocation)); Assert.Equal(1, behavior.Invocations.Count); Assert.Same(invocation, behavior.Invocations[0]); }
public void when_behavior_throws_then_invocation_is_still_recorded() { var mock = new TestMock(); var invocation = new TestInvocation(() => null); var behavior = new CompositeBehavior(i => true) { Invoke = { new DelegateBehavior(i => { throw new ArgumentException(); }) } }; mock.Behaviors.Add(behavior); Assert.Throws<ArgumentException>(() => mock.Invoke(invocation)); Assert.Equal(1, behavior.Invocations.Count); Assert.Same(invocation, behavior.Invocations[0]); }
public void when_aspects_configured_then_invokes_in_order() { var mock = new TestMock(); var invocation = new TestInvocation(() => null); var order = new List<string>(); var behavior = new Behavior(i => true); behavior.Before.Add(new DelegateAspect(i => true, i => { order.Add("before"); return BehaviorAction.Continue; })); behavior.Invoke.Add(new DelegateAspect(i => true, i => { order.Add("invoke"); return BehaviorAction.Continue; })); behavior.After.Add(new DelegateAspect(i => true, i => { order.Add("after"); return BehaviorAction.Continue; })); mock.Behaviors.Add(behavior); mock.Invoke(invocation); Assert.Equal(3, order.Count); Assert.Equal("before", order[0]); Assert.Equal("invoke", order[1]); Assert.Equal("after", order[2]); }
public void when_aspect_stops_further_aspects_on_phase_then_does_not_invoke_next_aspect() { var mock = new TestMock(); var invocation = new TestInvocation(() => null); var order = new List<string>(); var behavior = new Behavior(i => true); behavior.Before.Add(new DelegateAspect(i => true, i => { order.Add("before"); return BehaviorAction.Continue; })); behavior.Invoke.Add(new DelegateAspect(i => true, i => { order.Add("invoke"); return BehaviorAction.Stop; })); behavior.Invoke.Add(new DelegateAspect(i => true, i => { order.Add("invoke-not"); return BehaviorAction.Continue; })); behavior.After.Add(new DelegateAspect(i => true, i => { order.Add("after"); return BehaviorAction.Continue; })); mock.Behaviors.Add(behavior); mock.Invoke(invocation); Assert.Equal(3, order.Count); Assert.Equal("before", order[0]); Assert.Equal("invoke", order[1]); Assert.Equal("after", order[2]); }
public void when_aspect_stops_further_aspects_on_phase_then_does_not_invoke_next_aspect() { var mock = new TestMock(); var invocation = new TestInvocation(() => null); var order = new List <string>(); var behavior = new CompositeBehavior(i => true); behavior.Before.Add(new DelegateBehavior(i => order.Add("before"))); behavior.Invoke.Add(new DelegateBehavior(i => order.Add("invoke"))); behavior.Invoke.Add(new DelegateBehavior(i => order.Add("invoke-not"))); behavior.After.Add(new DelegateBehavior(i => order.Add("after"))); mock.Behaviors.Add(behavior); mock.Invoke(invocation); Assert.Equal(3, order.Count); Assert.Equal("before", order[0]); Assert.Equal("invoke", order[1]); Assert.Equal("after", order[2]); }
public void when_aspects_configured_then_invokes_in_order() { var mock = new TestMock(); var invocation = new TestInvocation(() => null); var order = new List <string>(); var behavior = new CompositeBehavior(i => true); behavior.Before.Add(new DelegateBehavior(i => order.Add("before"))); behavior.Invoke.Add(new DelegateBehavior(i => order.Add("invoke"))); behavior.After.Add(new DelegateBehavior(i => order.Add("after"))); mock.Behaviors.Add(behavior); mock.Invoke(invocation); Assert.Equal(3, order.Count); Assert.Equal("before", order[0]); Assert.Equal("invoke", order[1]); Assert.Equal("after", order[2]); }
public void when_aspect_is_disabled_then_does_not_invoke_on_execute() { var mock = new TestMock(); var invocation = new TestInvocation(() => null); var order = new List <string>(); var behavior = new Behavior(i => true); behavior.Before.Add(new DelegateAspect(i => true, i => { order.Add("before"); return(BehaviorAction.Continue); })); behavior.Invoke.Add(new DelegateAspect(i => false, i => { order.Add("invoke-not"); return(BehaviorAction.Continue); })); behavior.Invoke.Add(new DelegateAspect(i => true, i => { order.Add("invoke"); return(BehaviorAction.Continue); })); behavior.After.Add(new DelegateAspect(i => true, i => { order.Add("after"); return(BehaviorAction.Continue); })); mock.Behaviors.Add(behavior); mock.Invoke(invocation); Assert.Equal(3, order.Count); Assert.Equal("before", order[0]); Assert.Equal("invoke", order[1]); Assert.Equal("after", order[2]); }
public void when_aspect_is_disabled_then_does_not_invoke_on_execute() { var mock = new TestMock(); var invocation = new TestInvocation(() => null); var order = new List<string>(); var behavior = new CompositeBehavior(i => true); behavior.Before.Add(new DelegateBehavior(i => order.Add("before"))); behavior.Invoke.Add(new DelegateBehavior(i => order.Add("invoke-not"))); behavior.Invoke.Add(new DelegateBehavior(i => order.Add("invoke"))); behavior.After.Add(new DelegateBehavior(i => order.Add("after"))); mock.Behaviors.Add(behavior); mock.Invoke(invocation); Assert.Equal(3, order.Count); Assert.Equal("before", order[0]); Assert.Equal("invoke", order[1]); Assert.Equal("after", order[2]); }