public void PoseWrapper_Shims_And_Executes_From_Empty_Method_Call_Calling_Static_Method() { var a = new TestClassCallingStatic(); var wrapper = new PoseWrapper(a.EmptyMethod); var beforeDateTime = DateTime.Now; wrapper.Execute(); var afterDateTime = DateTime.Now; var lastCallResults = wrapper.LastExecutionResults; Assert.IsNotNull(wrapper.LastExecutionResults); Assert.AreEqual(1, wrapper.LastExecutionResults.Count); var result = wrapper.LastExecutionResults.First(); Assert.AreEqual("EmptyMethod", result.Key.Name); Assert.AreEqual(typeof(StaticMethodsTestClass), result.Key.DeclaringType); Assert.IsNotNull(result.Value); Assert.AreEqual(1, result.Value.Count); var callResult = result.Value.First(); Assert.IsTrue(beforeDateTime < callResult.CalledAt && callResult.CalledAt < afterDateTime); Assert.IsNotNull(callResult.Parameters); Assert.AreEqual(0, callResult.Parameters.Count()); }
public void PoseWrapper_Shims_And_Executes_From_Instance_Call_With_Reference_Type_Param_And_Returns_Reference_Type_Calling_Static_Method() { var a = new TestClassCallingStatic(); var wrapper = new PoseWrapper <List <int> >((Func <List <int>, List <int> >)a.MethodWithReferenceTypeParamsAndReturn); var beforeDateTime = DateTime.Now; var result = wrapper.Execute(new object[] { new List <int> { 4, 3, 2 } }); var afterDateTime = DateTime.Now; Assert.IsTrue(new List <int>().SequenceEqual(result)); var lastCallResults = wrapper.LastExecutionResults; Assert.IsNotNull(wrapper.LastExecutionResults); Assert.AreEqual(1, wrapper.LastExecutionResults.Count); var executionResult = wrapper.LastExecutionResults.First(); Assert.AreEqual("MethodWithReferenceTypeParamsAndReturn", executionResult.Key.Name); Assert.AreEqual(typeof(StaticMethodsTestClass), executionResult.Key.DeclaringType); Assert.IsNotNull(executionResult.Value); Assert.AreEqual(1, executionResult.Value.Count); var callResult = executionResult.Value.First(); Assert.IsTrue(beforeDateTime < callResult.CalledAt && callResult.CalledAt < afterDateTime); Assert.IsNotNull(callResult.Parameters); Assert.AreEqual(1, callResult.Parameters.Count()); Assert.IsTrue(new List <int> { 4, 3, 2 }.SequenceEqual((List <int>)callResult.Parameters[0])); }
public void PoseWrapper_Shims_And_Executes_From_Instance_Call_With_Multi_Params_And_Returns_Value_Calling_Static_Method() { var a = new TestClassCallingStatic(); var wrapper = new PoseWrapper <int>((Func <int, int, int>)a.MethodWithParamsAndReturn); var beforeDateTime = DateTime.Now; var result = wrapper.Execute(new object[] { 5, 6 }); var afterDateTime = DateTime.Now; Assert.AreEqual(0, result); var lastCallResults = wrapper.LastExecutionResults; Assert.IsNotNull(wrapper.LastExecutionResults); Assert.AreEqual(1, wrapper.LastExecutionResults.Count); var executionResult = wrapper.LastExecutionResults.First(); Assert.AreEqual("MethodWithParamsAndReturn", executionResult.Key.Name); Assert.AreEqual(typeof(StaticMethodsTestClass), executionResult.Key.DeclaringType); Assert.IsNotNull(executionResult.Value); Assert.AreEqual(1, executionResult.Value.Count); var callResult = executionResult.Value.First(); Assert.IsTrue(beforeDateTime < callResult.CalledAt && callResult.CalledAt < afterDateTime); Assert.IsNotNull(callResult.Parameters); Assert.AreEqual(2, callResult.Parameters.Count()); Assert.AreEqual(5, (int)callResult.Parameters[0]); Assert.AreEqual(6, (int)callResult.Parameters[1]); }
public void PoseWrapper_Shims_And_Executes_From_Instance_Call_Records_String_Parameters_Calling_Static_Method() { var a = new TestClassCallingStatic(); var wrapper = new PoseWrapper((Action <string>)a.MethodWithStringParam); var beforeDateTime = DateTime.Now; wrapper.Execute(new object[] { "bird" }); var afterDateTime = DateTime.Now; var lastCallResults = wrapper.LastExecutionResults; Assert.IsNotNull(wrapper.LastExecutionResults); Assert.AreEqual(1, wrapper.LastExecutionResults.Count); var executionResult = wrapper.LastExecutionResults.First(); Assert.AreEqual("MethodWithStringParam", executionResult.Key.Name); Assert.AreEqual(typeof(StaticMethodsTestClass), executionResult.Key.DeclaringType); Assert.IsNotNull(executionResult.Value); Assert.AreEqual(1, executionResult.Value.Count); var callResult = executionResult.Value.First(); Assert.IsTrue(beforeDateTime < callResult.CalledAt && callResult.CalledAt < afterDateTime); Assert.IsNotNull(callResult.Parameters); Assert.AreEqual(1, callResult.Parameters.Count()); var parameter = callResult.Parameters.First(); Assert.AreEqual("bird", (string)parameter); }
public void PoseWrapper_Shims_And_Executes_From_Instance_Call_And_Returns_Value_Calling_Static_Method() { var a = new TestClassCallingStatic(); var wrapper = new PoseWrapper <int>((Func <int>)a.MethodWithReturn, null, WrapperOptions.None); var beforeDateTime = DateTime.Now; var result = wrapper.Execute(); var afterDateTime = DateTime.Now; Assert.AreEqual(0, result); // todo: custom values return var lastCallResults = wrapper.LastExecutionResults; Assert.IsNotNull(wrapper.LastExecutionResults); Assert.AreEqual(1, wrapper.LastExecutionResults.Count); var executionResult = wrapper.LastExecutionResults.First(); Assert.AreEqual("MethodWithReturn", executionResult.Key.Name); Assert.AreEqual(typeof(StaticMethodsTestClass), executionResult.Key.DeclaringType); Assert.IsNotNull(executionResult.Value); Assert.AreEqual(1, executionResult.Value.Count); var callResult = executionResult.Value.First(); Assert.IsTrue(beforeDateTime < callResult.CalledAt && callResult.CalledAt < afterDateTime); Assert.IsNotNull(callResult.Parameters); Assert.AreEqual(0, callResult.Parameters.Count()); }
public void PoseWrapper_Shims_And_Executes_From_Instance_Call_Records_Multi_Parameters_Calling_Static_Method() { var a = new TestClassCallingStatic(); var wrapper = new PoseWrapper((Action <int, int, string, List <bool> >)a.MethodWithMultiParams); var beforeDateTime = DateTime.Now; wrapper.Execute(new object[] { 1, 2, "bird", new List <bool> { true, false, true } }); var afterDateTime = DateTime.Now; var lastCallResults = wrapper.LastExecutionResults; Assert.IsNotNull(wrapper.LastExecutionResults); Assert.AreEqual(1, wrapper.LastExecutionResults.Count); var executionResult = wrapper.LastExecutionResults.First(); Assert.AreEqual("MethodWithMultiParams", executionResult.Key.Name); Assert.AreEqual(typeof(StaticMethodsTestClass), executionResult.Key.DeclaringType); Assert.IsNotNull(executionResult.Value); Assert.AreEqual(1, executionResult.Value.Count); var callResult = executionResult.Value.First(); Assert.IsTrue(beforeDateTime < callResult.CalledAt && callResult.CalledAt < afterDateTime); Assert.IsNotNull(callResult.Parameters); Assert.AreEqual(4, callResult.Parameters.Count()); Assert.AreEqual(1, (int)callResult.Parameters[0]); Assert.AreEqual(2, (int)callResult.Parameters[1]); Assert.AreEqual("bird", (string)callResult.Parameters[2]); Assert.IsTrue(new List <bool> { true, false, true }.SequenceEqual((List <bool>)callResult.Parameters[3])); }