Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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]);
        }
Exemplo n.º 4
0
        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]);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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]);
        }
Exemplo n.º 14
0
        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]);
        }
Exemplo n.º 15
0
        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]);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        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]);
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
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]);
        }
Exemplo n.º 20
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]);
        }
Exemplo n.º 21
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]);
        }
Exemplo n.º 22
0
        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]);
        }
Exemplo n.º 23
0
        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]);
        }
Exemplo n.º 24
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 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]);
        }
Exemplo n.º 25
0
        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]);
        }
Exemplo n.º 26
0
        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]);
        }
Exemplo n.º 27
0
        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);
        }
Exemplo n.º 28
0
        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);
        }