public void ExecuteGenericMethod_CallMethodWithResultAndType_MethodReturnsResult() { const int value = 12345; var instance = new GenericMethodTestClass(); var result = instance.ExecuteGenericMethod <int>(nameof(GenericMethodTestClass.GetData), new[] { typeof(int) }, value); Assert.Equal(value, result); }
public void ExecuteGenericMethod_CallVoidMethodWithType_MethodWasCalled() { const int value = 1234; var instance = new GenericMethodTestClass(); instance.ExecuteGenericMethod(nameof(GenericMethodTestClass.DoSomething), new[] { typeof(int) }, value); Assert.Equal(value.ToString(), instance.Data); }
public void CreateGenericMethodFunc_FuncWithOneGenericParameters_CallSucceeded() { const int value = 1234; var instance = new GenericMethodTestClass(); var func = instance.CreateGenericMethodFunc <int, string>(nameof(GenericMethodTestClass.GetDataText), new [] { typeof(int) }, typeof(int)); var result = func(value); Assert.Equal(value.ToString(), result); }
public void CreateGenericMethodFunc_FuncWithTwoGenericParameters_CallSucceeded() { const int value = 1234; var dateTimeNow = DateTime.Now; var instance = new GenericMethodTestClass(); var func = instance.CreateGenericMethodFunc <int, DateTime, string>(nameof(GenericMethodTestClass.GetData), new[] { typeof(int), typeof(DateTime) }, typeof(int), typeof(DateTime)); var result = func(value, dateTimeNow); Assert.Equal(value.ToString() + dateTimeNow, result); }
public void CreateGenericMethodFunc_NoneGenericFunc_CallSucceeded() { const int value = 1234; var dateTimeNow = DateTime.Now; var instance = new GenericMethodTestClass(); var func = instance.CreateGenericMethodFunc <string>(nameof(GenericMethodTestClass.GetData), new [] { typeof(int), typeof(DateTime) }, typeof(int), typeof(DateTime)); var result = func(new object[] { value, dateTimeNow }); Assert.Equal(value.ToString() + dateTimeNow, result); }
public void CreateGenericMethodFunc_FuncWithFourGenericParameters_CallSucceeded() { const int value = 1234; var dateTimeNow = DateTime.Now; const bool boolValue = true; const double doubleValue = 123.456; var instance = new GenericMethodTestClass(); var func = instance.CreateGenericMethodFunc <int, DateTime, bool, double, string>( nameof(GenericMethodTestClass.GetData4), new[] { typeof(int), typeof(DateTime), typeof(bool), typeof(double) }, typeof(int), typeof(DateTime), typeof(bool), typeof(double)); var result = func(value, dateTimeNow, boolValue, doubleValue); Assert.Equal(value.ToString() + dateTimeNow + boolValue + doubleValue, result); }
public void ExecuteGenericMethod_CallNotExistingMethod_ThrowsException() { var instance = new GenericMethodTestClass(); Assert.Throws <MissingMethodException>(() => instance.ExecuteGenericMethod("NotExisting", new[] { new GenericArgument("T", typeof(int)) }, 1234)); Assert.Throws <MissingMethodException>(() => instance.ExecuteGenericMethod <string>(nameof(GenericMethodTestClass.GetData), new[] { new GenericArgument("T2", typeof(int)), new GenericArgument("T3", typeof(DateTime)) }, 123, 345)); }
public void ExecuteGenericMethod_CallMethodWithResultAndTwoGenericTypeParametersAndTypeNotExactlyMatching_MethodReturnsResult() { var value = new TestDataClassSpecial(); var dateTime = DateTime.Now; var instance = new GenericMethodTestClass(); var result = instance.ExecuteGenericMethod <string>(nameof(GenericMethodTestClass.GetData), new[] { typeof(TestDataClassBase), typeof(DateTime) }, value, dateTime); Assert.Equal(value.ToString() + dateTime, result); }
public void ExecuteGenericMethod_CallMethodWithResultAndTwoGenericTypeParametersAndType_MethodReturnsResult() { const int value = 12345; var dateTime = DateTime.Now; var instance = new GenericMethodTestClass(); var result = instance.ExecuteGenericMethod <string>(nameof(GenericMethodTestClass.GetData), new[] { typeof(int), typeof(DateTime) }, value, dateTime); Assert.Equal(value.ToString() + dateTime, result); }