public void ShimmedMethod_Generates_From_Instance_Call_With_Multi_Params_And_Returns_Value()
        {
            var a             = new InstanceMethodsTestClass();
            var shimmedMethod = new ShimmedMethod <int>(typeof(InstanceMethodsTestClass).GetMethod("MethodWithParamsAndReturn"));

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

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

            PoseContext.Isolate(() => {
                value = a.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);

            // first parameter should be instance
            var instanceParam = callResult.Parameters[0] as InstanceMethodsTestClass;

            Assert.IsNotNull(instanceParam);
            Assert.AreEqual(a.InstanceGuid, instanceParam.InstanceGuid);

            Assert.AreEqual(2, (int)callResult.Parameters[1]);
            Assert.AreEqual(4, (int)callResult.Parameters[2]);
        }
Пример #2
0
            public int MethodWithParamsAndReturn(int param1, int param2)
            {
                var inst = new InstanceMethodsTestClass();

                return(inst.MethodWithParamsAndReturn(param1, param2));
            }