Пример #1
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 = new FakeFunc <object, object, object, object>((o1, o2, o3) => null);

                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);
            }
Пример #2
0
            public void ShouldIncreaseNumberOfInvocationsEachTimeFakeFuncIsInvoked()
            {
                Func <object, object, object, object> func = (o1, o2, o3) => null;

                object ignored = null;

                var fakeMethod = new FakeFunc <object, object, object, object>(func);

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

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

                fakeMethod.Invoke(ignored, ignored, ignored);
                Assert.AreEqual(3, fakeMethod.NumberOfInvocations);
            }
Пример #3
0
            public void ShouldReturnValueFromFuncWhenInvoked()
            {
                var toReturn = new object();

                var fakeMethod = new FakeFunc <object, object, object, object>((o1, o2, o3) => toReturn);

                var returned = fakeMethod.Invoke(null, null, null);

                Assert.AreSame(toReturn, returned);
            }
Пример #4
0
            public void ShouldPassParameterToFuncWhenFakeFuncIsInvoked()
            {
                var p1 = new object();
                var p2 = new object();

                var fakeMethod = new FakeFunc <object, object, object>((o1, o2) => null);

                fakeMethod.Invoke(p1, p2);

                Assert.AreSame(p1, fakeMethod.Invocations.First().FirstParameter);
                Assert.AreSame(p2, fakeMethod.Invocations.First().SecondParameter);
            }
Пример #5
0
            public void ShouldInvokeProvidedActionWhenFakeFuncIsInvoked()
            {
                bool actionCalled = false;
                Func <object, object, object, object> func = (o1, o2, o3) =>
                {
                    actionCalled = true;
                    return(null);
                };

                object ignored = null;

                var fakeMethod = new FakeFunc <object, object, object, object>(func);

                fakeMethod.Invoke(ignored, ignored, ignored);

                Assert.IsTrue(actionCalled);
            }
Пример #6
0
            public void ShouldReturnValueFromFuncWhenInvoked()
            {
                var toReturn = new object();

                var fakeMethod = new FakeFunc<object, object, object>((o1, o2) => toReturn);

                var returned = fakeMethod.Invoke(null, null);

                Assert.AreSame(toReturn, returned);
            }
Пример #7
0
            public void ShouldPassParameterToFuncWhenFakeFuncIsInvoked()
            {
                var p1 = new object();
                var p2 = new object();

                var fakeMethod = new FakeFunc<object, object, object>((o1, o2) => null);

                fakeMethod.Invoke(p1, p2);

                Assert.AreSame(p1, fakeMethod.Invocations.First().FirstParameter);
                Assert.AreSame(p2, fakeMethod.Invocations.First().SecondParameter);
            }
Пример #8
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 fakeMethod = new FakeFunc<object, object, object>((o1, o2) => null);

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

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

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

                Assert.AreSame(third1, fakeMethod.Invocations.ElementAt(2).FirstParameter);
                Assert.AreSame(third2, fakeMethod.Invocations.ElementAt(2).SecondParameter);
            }
Пример #9
0
            public void ShouldInvokeProvidedActionWhenFakeFuncIsInvoked()
            {
                bool actionCalled = false;
                Func<object, object, object> func = (o1, o2) =>
                {
                    actionCalled = true;
                    return null;
                };

                object ignored = null;

                var fakeMethod = new FakeFunc<object, object, object>(func);

                fakeMethod.Invoke(ignored, ignored);

                Assert.IsTrue(actionCalled);
            }
Пример #10
0
            public void ShouldIncreaseNumberOfInvocationsEachTimeFakeFuncIsInvoked()
            {
                Func<object, object, object> func = (o1, o2) => null;

                object ignored = null;

                var fakeMethod = new FakeFunc<object, object, object>(func);

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

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

                fakeMethod.Invoke(ignored, ignored);
                Assert.AreEqual(3, fakeMethod.NumberOfInvocations);
            }