dotNET generic methods
Hi there all!
Currently I am trying to test our software (C# based).
I have "imported" the DLL files through the CLR Bridge and was able to access most of the properties and methods without any problem. However, my only problem is with generic type. So the C# (DLL) code is:
public class SomeClass<T> : ISomeClass where T : class
{ public SomeClass(string param1, T param2, SomeType param3);
}
So I write the TC script in DelphiScript. How do I run such a function?
In C# it would be something like this: var = new SomeClass<T>(param1, param2, param3);
In PowerShell: $var = New-Object 'SomeClass[T]' $param1, $param2, $param3
So I have tried a lot of approaches but with no luck.
Most errors are about "cannot create an instance of SomeClass because Type.ContainsGenericParameters is true".
So I tried MakeGenericType, MakeGenericMethod, GetType etc. but with no success.
Could someone maybe help with this? Or clarify if this is simply not possible in TestComplete? :)
Kind regards,
Frits
Here's the thing with the CLR bridge. While it CAN be used for what you're trying to do (import the DLLs and running them through tests), that's not what it was intended for. The intention is to import DLLs via the CLR bridge for use in building tests against other applications.
What you might want to investigate is https://support.smartbear.com/testcomplete/docs/testing-with/advanced/using-external-functions/calling-from-dll/about.html
Alternatively, perhaps have your developers build a harness or stub of some sort that allows you to make UI calls to exercise the DLL functions.
I've done both in the past with a DLL that we developed to do tax rule calculations for an online webstore. Worked pretty well.
This is not to say that the CLR bridge won't work for you, but there may be a better solution that might be more geared for your needs.