Esempio n. 1
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]);
        }
Esempio n. 2
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]);
        }
Esempio n. 3
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]);
        }
Esempio n. 4
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]);
        }
Esempio n. 5
0
        public override int Add(int x, int y)
        {
            var invocation = new TestInvocation(() => base.Add(x, y))
            {
                Mock      = mock,
                Target    = this,
                Method    = typeof(ICalculator).GetMethod("Add"),
                Arguments = new object[] { x, y }
            };

            mock.Invoke(invocation);

            return((int)invocation.ReturnValue);
        }
Esempio n. 6
0
        public override int Add(int x, int y)
        {
            var invocation = new TestInvocation(() => base.Add(x, y))
            {
                Mock = mock,
                Target = this,
                Method = typeof(ICalculator).GetMethod("Add"),
                Arguments = new object[] { x, y }
            };

            mock.Invoke(invocation);

            return (int)invocation.ReturnValue;
        }
Esempio n. 7
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]);
        }
Esempio n. 8
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]);
        }
Esempio n. 9
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]);
        }
Esempio n. 10
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]);
        }
Esempio n. 11
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]);
        }
Esempio n. 12
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]);
        }
Esempio n. 13
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]);
        }
Esempio n. 14
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]);
        }