Exemple #1
0
            public bool CallTwoDifferentMethods()
            {
                var result1 = StaticMethodsTestClass.MethodWithParamAndReturn(5);
                var result2 = StaticMethodsTestClass.MethodWithParamsAndReturn(7, 1);

                return(result1 < result2);
            }
        public void ShimmedMethod_Generates_From_Static_Call_With_Multi_Params_And_Returns_Value()
        {
            var shimmedMethod = new ShimmedMethod <int>(typeof(StaticMethodsTestClass).GetMethod("MethodWithParamsAndReturn"));

            Assert.IsNotNull(shimmedMethod);
            Assert.IsNotNull(shimmedMethod.Method);
            Assert.IsNotNull(shimmedMethod.Shim);

            var beforeDateTime = DateTime.Now;
            int value          = -1;

            PoseContext.Isolate(() => {
                value = StaticMethodsTestClass.MethodWithParamsAndReturn(2, 4);
            }, new[] { shimmedMethod.Shim });
            Assert.AreEqual(0, value); // Shimmy will set to default for that value type
            Assert.AreEqual(1, shimmedMethod.CallResults.Count);
            var callResult = shimmedMethod.CallResults.First();

            Assert.IsNotNull(callResult.Parameters);
            var afterDateTime = DateTime.Now;

            Assert.IsNotNull(callResult.CalledAt);
            Assert.IsTrue(beforeDateTime < callResult.CalledAt && callResult.CalledAt < afterDateTime);
            Assert.AreEqual(2, (int)callResult.Parameters[0]);
            Assert.AreEqual(4, (int)callResult.Parameters[1]);
        }
Exemple #3
0
        public void PoseWrapper_SetReturn_Changes_Value_Of_Correct_Shim_On_Function_Call()
        {
            var a           = new TestClass();
            var wrapper     = new PoseWrapper <bool>((Func <bool>)a.CallTwoDifferentMethods, null, WrapperOptions.None);
            var methodInfo1 = typeof(StaticMethodsTestClass).GetMethod("MethodWithParamAndReturn");
            var methodInfo2 = typeof(StaticMethodsTestClass).GetMethod("MethodWithParamsAndReturn");

            wrapper.SetReturn(() => StaticMethodsTestClass.MethodWithParamAndReturn(Pose.Is.A <int>()), 3);
            wrapper.SetReturn(() => StaticMethodsTestClass.MethodWithParamsAndReturn(Pose.Is.A <int>(), Pose.Is.A <int>()), 7);

            var preCallDateTime = DateTime.Now;
            var result          = wrapper.Execute();

            Assert.IsTrue(result);

            Assert.AreEqual(2, wrapper.LastExecutionResults.Count);
            var resultsMethodWithParamAndReturn  = wrapper.LastExecutionResults.First(ler => ler.Key.Equals(methodInfo1)).Value;
            var resultsMethodWithParamsAndReturn = wrapper.LastExecutionResults.First(ler => ler.Key.Equals(methodInfo2)).Value;

            Assert.AreEqual(1, resultsMethodWithParamAndReturn.Count);
            Assert.AreEqual(1, resultsMethodWithParamsAndReturn.Count);
            var resultsMethodWithParamAndReturnData  = resultsMethodWithParamAndReturn[0];
            var resultsMethodWithParamsAndReturnData = resultsMethodWithParamsAndReturn[0];

            Assert.IsTrue(resultsMethodWithParamAndReturnData.CalledAt > preCallDateTime);
            Assert.IsTrue(resultsMethodWithParamsAndReturnData.CalledAt > resultsMethodWithParamAndReturnData.CalledAt);
            Assert.AreEqual(5, (int)resultsMethodWithParamAndReturnData.Parameters[0]);
            Assert.AreEqual(7, (int)resultsMethodWithParamsAndReturnData.Parameters[0]);
            Assert.AreEqual(1, (int)resultsMethodWithParamsAndReturnData.Parameters[1]);
        }
Exemple #4
0
        public void PoseWrapper_Returns_Results_Per_Method_By_Expression()
        {
            var a          = new TestClass();
            var wrapper    = new PoseWrapper <bool>((Func <bool>)a.CallTwoDifferentMethods, null, WrapperOptions.None);
            var methodInfo = typeof(StaticMethodsTestClass).GetMethod("MethodWithParamsAndReturn");

            var result = wrapper.Execute();

            var callResults = wrapper.ResultsFor(() => StaticMethodsTestClass.MethodWithParamsAndReturn(Pose.Is.A <int>(), Pose.Is.A <int>()));

            Assert.IsNotNull(callResults);
            Assert.AreEqual(1, callResults.Count);
            Assert.IsTrue(callResults.SequenceEqual(wrapper.LastExecutionResults.FirstOrDefault(m => m.Key == methodInfo).Value));
        }
Exemple #5
0
 public int MethodWithParamsAndReturn(int param1, int param2)
 {
     return(StaticMethodsTestClass.MethodWithParamsAndReturn(param1, param2));
 }