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

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

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

            PoseContext.Isolate(() => {
                value = a.MethodWithReturn();
            }, 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);
        }
Exemplo n.º 2
0
            public int MethodWithReturn()
            {
                var inst = new InstanceMethodsTestClass();

                return(inst.MethodWithReturn());
            }