public void Create_IfMultipleInputParameters_PassesInputArguments(bool isInstance) { // Arrange MethodInfo method = GetMethodInfo(isInstance, "TestIntStringObjectArray"); int expectedA = 1; string expectedB = "B"; object[] expectedC = new object[] { new object() }; // Act IMethodInvoker <MethodInvokerFactoryTests> invoker = MethodInvokerFactory.Create <MethodInvokerFactoryTests>(method); // Assert Assert.NotNull(invoker); bool callbackCalled = false; Action <int, string, object> callback = (a, b, c) => { callbackCalled = true; Assert.Equal(expectedA, a); Assert.Same(expectedB, b); Assert.Same(expectedC, c); }; MethodInvokerFactoryTests instance = GetInstance(isInstance); object[] arguments = new object[] { expectedA, expectedB, expectedC, callback }; invoker.InvokeAsync(instance, arguments).GetAwaiter().GetResult(); Assert.True(callbackCalled); }
public void Create_IfInOutByRefMethodReturnsTask_RoundtripsArguments(bool isInstance) { // Arrange MethodInfo method = GetMethodInfo(isInstance, "TestInOutByRefReturnTask"); int expectedA = 1; string expectedInitialB = "B"; string expectedFinalB = "b"; object[] expectedC = new object[] { new object(), default(int), String.Empty }; // Act IMethodInvoker <MethodInvokerFactoryTests> invoker = MethodInvokerFactory.Create <MethodInvokerFactoryTests>(method); // Assert Assert.NotNull(invoker); bool callbackCalled = false; InOutRefTaskFunc callback = delegate(int a, ref string b, out object[] c) { callbackCalled = true; Assert.Equal(expectedA, a); Assert.Same(expectedInitialB, b); b = expectedFinalB; c = expectedC; return(Task.FromResult(0)); }; MethodInvokerFactoryTests instance = GetInstance(isInstance); object[] arguments = new object[] { expectedA, expectedInitialB, null, callback }; invoker.InvokeAsync(instance, arguments).GetAwaiter().GetResult(); Assert.True(callbackCalled); Assert.Same(expectedFinalB, arguments[1]); Assert.Same(expectedC, arguments[2]); }
public void Create_IfMultipleOutputParameters_SetsOutputArguments(bool isInstance) { // Arrange MethodInfo method = GetMethodInfo(isInstance, "TestOutIntStringObjectArray"); int expectedA = 1; string expectedB = "B"; object[] expectedC = new object[] { new object() }; // Act IMethodInvoker <MethodInvokerFactoryTests> invoker = MethodInvokerFactory.Create <MethodInvokerFactoryTests>(method); // Assert Assert.NotNull(invoker); bool callbackCalled = false; OutAction callback = delegate(out int a, out string b, out object[] c) { callbackCalled = true; a = expectedA; b = expectedB; c = expectedC; }; MethodInvokerFactoryTests instance = GetInstance(isInstance); object[] arguments = new object[] { default(int), null, null, callback }; invoker.InvokeAsync(instance, arguments).GetAwaiter().GetResult(); Assert.True(callbackCalled); Assert.Equal(expectedA, arguments[0]); Assert.Same(expectedB, arguments[1]); Assert.Same(expectedC, arguments[2]); }
public void Create_IfReturnsTaskAndTaskCanceled_ReturnsCanceledTask(bool isInstance) { // Arrange MethodInfo method = GetMethodInfo(isInstance, "ReturnCanceledTask"); // Act IMethodInvoker <MethodInvokerFactoryTests> invoker = MethodInvokerFactory.Create <MethodInvokerFactoryTests>(method); // Assert MethodInvokerFactoryTests instance = GetInstance(isInstance); Task task = invoker.InvokeAsync(instance, null); Assert.NotNull(task); task.WaitUntilCompleted(); Assert.Equal(TaskStatus.Canceled, task.Status); }
public void Create_IfParameterlessMethod_CanInvoke(bool isInstance) { // Arrange MethodInfo method = GetMethodInfo(isInstance, "ParameterlessMethod"); // Act IMethodInvoker <MethodInvokerFactoryTests> invoker = MethodInvokerFactory.Create <MethodInvokerFactoryTests>(method); try { // Assert MethodInvokerFactoryTests instance = GetInstance(isInstance); invoker.InvokeAsync(instance, null).GetAwaiter().GetResult(); Assert.True(_parameterlessMethodCalled); } finally { _parameterlessMethodCalled = false; } }
public void Create_IfMultipleReferenceParameters_RoundtripsArguments(bool isInstance) { // Arrange MethodInfo method = GetMethodInfo(isInstance, "TestByRefIntStringObjectArray"); int expectedInitialA = 1; string expectedInitialB = "B"; object[] expectedInitialC = new object[] { new object() }; int expectedFinalA = 2; string expectedFinalB = "b"; object[] expectedFinalC = new object[] { new object(), default(int), String.Empty }; // Act IMethodInvoker <MethodInvokerFactoryTests> invoker = MethodInvokerFactory.Create <MethodInvokerFactoryTests>(method); // Assert Assert.NotNull(invoker); bool callbackCalled = false; ByRefAction callback = delegate(ref int a, ref string b, ref object[] c) { callbackCalled = true; Assert.Equal(expectedInitialA, a); Assert.Same(expectedInitialB, b); Assert.Same(expectedInitialC, c); a = expectedFinalA; b = expectedFinalB; c = expectedFinalC; }; MethodInvokerFactoryTests instance = GetInstance(isInstance); object[] arguments = new object[] { expectedInitialA, expectedInitialB, expectedInitialC, callback }; invoker.InvokeAsync(instance, arguments).GetAwaiter().GetResult(); Assert.True(callbackCalled); Assert.Equal(expectedFinalA, arguments[0]); Assert.Same(expectedFinalB, arguments[1]); Assert.Same(expectedFinalC, arguments[2]); }