Exemple #1
0
        public void TrackMockBehaviors()
        {
            var stunt = new FakeStunt();

            // Forces initialization of the default mock.
            Assert.NotNull(stunt.Mock);

            var setup = new MockSetup(
                new MethodInvocation(stunt, typeof(FakeStunt).GetMethod("Do")),
                Array.Empty <IArgumentMatcher>());

            var initialBehaviors = stunt.Behaviors.Count;
            var behavior         = new MockBehaviorPipeline(setup);

            stunt.AddBehavior(behavior);
            stunt.AddBehavior(new DelegateStuntBehavior((m, n) => n().Invoke(m, n)));
            Assert.Equal(initialBehaviors + 2, stunt.Behaviors.Count);

            Assert.Single(stunt.Mock.Setups);
            Assert.Same(behavior, stunt.Mock.GetPipeline(setup));

            stunt.Behaviors.Remove(behavior);

            Assert.Equal(initialBehaviors + 1, stunt.Behaviors.Count);
            Assert.Empty(stunt.Mock.Setups);
        }
        public void ExecutesNextIfNoBehaviors()
        {
            var invocation = new MethodInvocation(new FakeMock(), typeof(object).GetMethod(nameof(object.ToString)));
            var pipeline   = new MockBehaviorPipeline(new MockSetup(invocation, Array.Empty <IArgumentMatcher>()));

            Assert.NotNull(pipeline.Execute(invocation, () => (m, n) => m.CreateValueReturn(null)));
        }
        public void AppliesToSetup()
        {
            var invocation = new MethodInvocation(new FakeMock(), typeof(object).GetMethod(nameof(object.ToString)));
            var setup      = new MockSetup(invocation, Array.Empty <IArgumentMatcher>());
            var pipeline   = new MockBehaviorPipeline(setup);

            Assert.True(pipeline.AppliesTo(invocation));
        }
        public void ThrowsIfTargetNotIMocked()
        {
            var invocation = new MethodInvocation(new object(), typeof(object).GetMethod(nameof(object.ToString)));
            var pipeline   = new MockBehaviorPipeline(new MockSetup(invocation, Array.Empty <IArgumentMatcher>()));

            pipeline.Behaviors.Add(MockBehavior.Create((m, i, n) => i.CreateValueReturn(null), "test"));

            Assert.Throws <ArgumentException>(() => pipeline.Execute(invocation, () => (m, n) => throw new NotImplementedException()));
        }
        public void ExecutesBehaviorAndNext()
        {
            var invocation = new MethodInvocation(new FakeMock(), typeof(object).GetMethod(nameof(object.ToString)));
            var pipeline   = new MockBehaviorPipeline(new MockSetup(invocation, Array.Empty <IArgumentMatcher>()));

            pipeline.Behaviors.Add(new DelegateMockBehavior((m, i, n) => n().Invoke(m, i, n), "test"));

            Assert.NotNull(pipeline.Execute(invocation, () => (m, n) => m.CreateValueReturn(null)));
        }
Exemple #6
0
        public void ExecutesBehavior()
        {
            var invocation = new MethodInvocation(new FakeMock(), typeof(object).GetMethod(nameof(object.ToString)));
            var pipeline   = new MockBehaviorPipeline(new MockSetup(invocation, Array.Empty <IArgumentMatcher>()));

            pipeline.Behaviors.Add(new AnonymousMockBehavior((m, i, n) => i.CreateValueReturn(null), "test"));

            Assert.NotNull(pipeline.Execute(invocation, () => (m, n) => throw new NotImplementedException()));
        }