Getting "Multiple actions matched" if adding refrence to 2 different Web API projects to test project #27711
Unanswered
lisamariet
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
AspNetCore.TestHost version 2.2.0
AspNetCore version 2.2
Swagger version 4.0.1
I have 2 web api projects (inside a Service Fabric app) that both has a controller with the same name. But they do different things. One api is Admin api and the other is client consumer - read only api.
Both has a controller with the same name and same method for GetAll() and the route is the same. But because the APIs spin up on different ports (configured by service fabric) they are in reality not the same route.
It works fine to run these APIs in Service Fabric cluster and calling the APIs.
This however is not something the TestHost seems to notice and I don't know how to configure the TestHost for this to work either.
I first setup TestHost with the AdminApi and created test methods, and this works like a charm. Then when I added the ClientApi project that has the same GetAll method with the same route, my tests for that endpoint in AdminAPi started failing with the errormessage "Multiple actions matched".
I mean I have not done anything else in test project but add a reference to the ClientApi project, The Startup that is used is still from AdminApi project. So simply just adding a reference to ClientApi... makes test fail.
I assume the problem is that TestHost scans for all /controller/ folders in any project that is referenced, regardless of the code in Startup. And since I don't know how to configure the Test Startup to have different ports or a different base path I cannot get this to work.
I would like to write integration tests that calls AdminApi and ClientApi in the same test. This seems impossible.
This inhertis from the AdminApit projects Startup.cs file and overrides methods because a need to have a different setup in test.
Beta Was this translation helpful? Give feedback.
All reactions