-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HttpTriggerTester Expression Tree Limitations #69
Comments
Hi @m-flak, The expression usage is by design as this provides an opportunity for UnitTestEx to verify/assert that the method being invoked as HTTP, i.e. has the A backlog item is for this to further inspect the I am not sure that a test should infer a value in the code being tested and then be used in the actual test. The test should assert based on intent; otherwise, how do you know whether there is an issue, e.g. maybe a misspelling in the route? How often do the routes change that this is an issue? Thanks... |
Okay, all I wanted to do was get the route value automatically from the attribute and use it with
This is the gap I tried to fill that led me to this issue. I wanted the ability to use the metadata within |
I rethought my approach and made a simple utility method. public static string GetHttpRoute(Type functionClass)
{
string? route = null;
var runMethod = functionClass.GetMethod("Run");
var runParams = runMethod?.GetParameters();
if (runMethod is null
|| runParams is null
|| runParams.Length == 0)
{
return string.Empty;
}
var attribute = runParams[0]
.GetCustomAttributes(true)
.FirstOrDefault(
a => typeof(HttpTriggerAttribute).IsInstanceOfType(a),
null)
as HttpTriggerAttribute;
route = attribute?.Route;
route ??= string.Empty;
return route;
} |
HttpTriggerTester Expression Tree Limitations
Background
In my tests project, I have created an extension method using reflection to automatically get the route of my HTTP-Triggered-Functions with that method.
The goal here was to eliminate requirements for test code updates after changes to a Function's route in the main code. It almost works.
I've since written my code around this limitation, but it requires me to spin up & run an entire
HostTesterBase
implementor twice. 😰Issue
HttpTriggerTester's Run/RunAsync methods, unlike TypeTester's, uses expression trees. SRC
This means that I am unable to write something like this without experiencing compilation errors:
A statement like this would work with TypeTester, but I can't use TypeTester to test my HTTP-Triggered-Function.
Is there a technical reason for HttpTriggerTester's Run/RunAsync methods not having an overload for
Action<T>
orFunc<T1,T2>
??Workaround
The following boilerplate accomplishes what I intended without any issues:
The text was updated successfully, but these errors were encountered: