Exemple #1
0
            public void ShouldThrowExceptionWhenInvocationDoesNotMeetAcceptedConditionDueToFirstParameter()
            {
                var fakeMethod = FakeMethod.CreateFor <int, int, int>((p1, p2) => p1 + p2)
                                 .Accept(n => n == 1, n => n == 2);

                fakeMethod.Invoke(2, 2);
            }
Exemple #2
0
            public void ShouldThrowExceptionWhenInvocationDoesNotMeetAcceptanceConditionDueToThirdParameter()
            {
                var fakeMethod = FakeMethod.CreateFor <int, int, int, int>((p1, p2, p3) => p1 + p2 + p3)
                                 .Accept(n => n == 1, n => n == 2, n => n == 3);

                fakeMethod.Invoke(1, 2, 2);
            }
Exemple #3
0
            public void ShouldKeepTrackOfParametersForConsecutiveInvocations()
            {
                var first1  = new object();
                var second1 = new object();
                var third1  = new object();

                var first2  = new object();
                var second2 = new object();
                var third2  = new object();

                var first3  = new object();
                var second3 = new object();
                var third3  = new object();

                var fakeMethod = FakeMethod.CreateFor <object, object, object>((o1, o2, o3) => { });

                fakeMethod.Invoke(first1, first2, first3);
                fakeMethod.Invoke(second1, second2, second3);
                fakeMethod.Invoke(third1, third2, third3);

                Assert.AreSame(first1, fakeMethod.Invocations.ElementAt(0).FirstParameter);
                Assert.AreSame(first2, fakeMethod.Invocations.ElementAt(0).SecondParameter);
                Assert.AreSame(first3, fakeMethod.Invocations.ElementAt(0).ThirdParameter);

                Assert.AreSame(second1, fakeMethod.Invocations.ElementAt(1).FirstParameter);
                Assert.AreSame(second2, fakeMethod.Invocations.ElementAt(1).SecondParameter);
                Assert.AreSame(second3, fakeMethod.Invocations.ElementAt(1).ThirdParameter);

                Assert.AreSame(third1, fakeMethod.Invocations.ElementAt(2).FirstParameter);
                Assert.AreSame(third2, fakeMethod.Invocations.ElementAt(2).SecondParameter);
                Assert.AreSame(third3, fakeMethod.Invocations.ElementAt(2).ThirdParameter);
            }
Exemple #4
0
            public void ShouldReturnValueFromFuncWhenInvoked()
            {
                var toReturn = new object();

                var fakeMethod = FakeMethod.CreateFor <object, object>(p => toReturn);

                var returned = fakeMethod.Invoke(null);

                Assert.AreSame(toReturn, returned);
            }
Exemple #5
0
            public void ShouldPassParameterToFuncWhenFakeFuncIsInvoked()
            {
                var o = new object();

                var fakeMethod = FakeMethod.CreateFor <object, object>(p => null);

                fakeMethod.Invoke(o);

                Assert.AreSame(o, fakeMethod.Invocations.First().Parameter);
            }
Exemple #6
0
            public void ShouldPassParameterToActionWhenFakeActionIsInvoked()
            {
                object o = new object();

                var fakeMethod = FakeMethod.CreateFor <object>(p => { });

                fakeMethod.Invoke(o);

                Assert.AreSame(o, fakeMethod.Invocations.First().Parameter);
            }
Exemple #7
0
            public void ShouldReturnObjectReturnedByFuncWhenInvoked()
            {
                var toReturn = new object();

                var fakeMethod = FakeMethod.CreateFor(() => toReturn);

                var returned = fakeMethod.Invoke();

                Assert.AreSame(toReturn, returned);
            }
Exemple #8
0
            public void ShouldInvokeProvidedActionWhenFakeActionIsInvoked()
            {
                bool   actionCalled = false;
                Action action       = () => { actionCalled = true; };

                var fakeMethod = FakeMethod.CreateFor(action);

                fakeMethod.Invoke();

                Assert.IsTrue(actionCalled);
            }
Exemple #9
0
            public void ShouldInvokeProvidedActionWhenFakeActionIsInvoked()
            {
                bool            actionCalled = false;
                Action <object> action       = o => { actionCalled = true; };
                object          ignored      = null;

                var fakeMethod = FakeMethod.CreateFor(action);

                fakeMethod.Invoke(ignored);

                Assert.IsTrue(actionCalled);
            }
Exemple #10
0
            public void ShouldPassParameterToActionWhenFakeActionIsInvoked()
            {
                object param1 = new object();
                object param2 = new object();

                var fakeMethod = FakeMethod.CreateFor <object, object>((o1, o2) => { });

                fakeMethod.Invoke(param1, param2);

                Assert.AreSame(param1, fakeMethod.Invocations.First().FirstParameter);
                Assert.AreSame(param2, fakeMethod.Invocations.First().SecondParameter);
            }
Exemple #11
0
            public void ShouldInvokeActionIfAcceptConditionIsMet()
            {
                bool invoked = false;

                var fakeMethod = FakeMethod.CreateFor <int>(p => { invoked = true; }).Accept(n => n == 2);

                fakeMethod.Invoke(2);

                Assert.IsTrue(invoked);
                Assert.AreEqual(1, fakeMethod.NumberOfInvocations);
                Assert.AreEqual(2, fakeMethod.Invocations.First().Parameter);
            }
Exemple #12
0
            public void ShouldIncreaseNumberOfInvocationsWhenFakeFuncIsInvoked()
            {
                var fakeMethod = FakeMethod.CreateFor <object>(() => null);

                fakeMethod.Invoke();
                Assert.AreEqual(1, fakeMethod.NumberOfInvocations);

                fakeMethod.Invoke();
                Assert.AreEqual(2, fakeMethod.NumberOfInvocations);

                fakeMethod.Invoke();
                Assert.AreEqual(3, fakeMethod.NumberOfInvocations);
            }
Exemple #13
0
            public void ShouldIncreaseNumberOfInvocationsEachTimeFakeActionIsInvoked()
            {
                var fakeMethod = FakeMethod.CreateFor(() => { });

                fakeMethod.Invoke();
                Assert.AreEqual(1, fakeMethod.NumberOfInvocations);

                fakeMethod.Invoke();
                Assert.AreEqual(2, fakeMethod.NumberOfInvocations);

                fakeMethod.Invoke();
                Assert.AreEqual(3, fakeMethod.NumberOfInvocations);
            }
Exemple #14
0
            public void ShouldInvokeActionIfParametersMeetAcceptanceCondition()
            {
                bool actionInvoked = false;
                var  fakeMethod    = FakeMethod.CreateFor <int, int>((p1, p2) => { actionInvoked = true; }).Accept(n => n == 1, n => n == 2);

                fakeMethod.Invoke(1, 2);

                Assert.IsTrue(actionInvoked);

                Assert.AreEqual(1, fakeMethod.NumberOfInvocations);
                Assert.AreEqual(1, fakeMethod.Invocations.First().FirstParameter);
                Assert.AreEqual(2, fakeMethod.Invocations.First().SecondParameter);
            }
Exemple #15
0
            public void ShouldInvokeFuncWhenFakeFuncIsInvoked()
            {
                bool funcInvoked = false;
                var  fakeMethod  = FakeMethod.CreateFor <object>(() =>
                {
                    funcInvoked = true;
                    return(null);
                });

                fakeMethod.Invoke();

                Assert.IsTrue(funcInvoked);
            }
Exemple #16
0
            public void ShouldIncreaseNumberOfInvocationsEachTimeFakeActionIsInvoked()
            {
                object ignored    = null;
                var    fakeMethod = FakeMethod.CreateFor <object>(o => { });

                fakeMethod.Invoke(ignored);
                Assert.AreEqual(1, fakeMethod.NumberOfInvocations);

                fakeMethod.Invoke(ignored);
                Assert.AreEqual(2, fakeMethod.NumberOfInvocations);

                fakeMethod.Invoke(ignored);
                Assert.AreEqual(3, fakeMethod.NumberOfInvocations);
            }
Exemple #17
0
            public void ShouldKeepTrackOfParametersForConsecutiveInvocations()
            {
                var first  = new object();
                var second = new object();
                var third  = new object();

                var fakeMethod = FakeMethod.CreateFor <object, object>(p => null);

                fakeMethod.Invoke(first);
                fakeMethod.Invoke(second);
                fakeMethod.Invoke(third);

                Assert.AreSame(first, fakeMethod.Invocations.ElementAt(0).Parameter);
                Assert.AreSame(second, fakeMethod.Invocations.ElementAt(1).Parameter);
                Assert.AreSame(third, fakeMethod.Invocations.ElementAt(2).Parameter);
            }
Exemple #18
0
            public void ShouldIncreaseNumberOfInvocationsEachTimeFakeFuncIsInvoked()
            {
                Func <object, object> func = o => null;

                object ignored = null;

                var fakeMethod = FakeMethod.CreateFor(func);

                fakeMethod.Invoke(ignored);
                Assert.AreEqual(1, fakeMethod.NumberOfInvocations);

                fakeMethod.Invoke(ignored);
                Assert.AreEqual(2, fakeMethod.NumberOfInvocations);

                fakeMethod.Invoke(ignored);
                Assert.AreEqual(3, fakeMethod.NumberOfInvocations);
            }
Exemple #19
0
            public void ShouldInvokeProvidedActionWhenFakeFuncIsInvoked()
            {
                bool funcCalled            = false;
                Func <object, object> func = o =>
                {
                    funcCalled = true;
                    return(null);
                };

                object ignored = null;

                var fakeMethod = FakeMethod.CreateFor(func);

                fakeMethod.Invoke(ignored);

                Assert.IsTrue(funcCalled);
            }
Exemple #20
0
            public void ShouldInvokeFuncIfParametersMeetAcceptanceCondition()
            {
                bool actionInvoked = false;
                var  fakeMethod    = FakeMethod.CreateFor <int, int, int, int>(
                    (p1, p2, p3) =>
                {
                    actionInvoked = true;
                    return(p1 + p2 + p3);
                }).Accept(n => n == 1, n => n == 2, n => n == 3);

                Assert.AreEqual(6, fakeMethod.Invoke(1, 2, 3));

                Assert.IsTrue(actionInvoked);

                Assert.AreEqual(1, fakeMethod.NumberOfInvocations);
                Assert.AreEqual(1, fakeMethod.Invocations.First().FirstParameter);
                Assert.AreEqual(2, fakeMethod.Invocations.First().SecondParameter);
                Assert.AreEqual(3, fakeMethod.Invocations.First().ThirdParameter);
            }
Exemple #21
0
            public void ShouldThrowExceptionWhenInvocationDoesNotMeetAcceptanceConditionDueToSecondParameter()
            {
                var fakeMethod = FakeMethod.CreateFor <int, int>((p1, p2) => { }).Accept(n => n == 1, n => n == 2);

                fakeMethod.Invoke(1, 1);
            }
Exemple #22
0
            public void ShouldThrowExceptionWhenInvocationDoesNotMeetAcceptedConditionValues()
            {
                var fakeMethod = FakeMethod.CreateFor <int, int>(p => p).Accept(n => n == 2);

                fakeMethod.Invoke(3);
            }