Skip to content

TestServer HttpClient SendAsync returns NOT_FOUND when api is in classLibrary #10331

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

Closed
ghstahl opened this issue May 17, 2019 · 2 comments
Closed
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates ✔️ Resolution: Duplicate Resolved as a duplicate of another issue

Comments

@ghstahl
Copy link

ghstahl commented May 17, 2019

Describe the bug

The exact same controller works when it is in the main application OR in a class library.
i.e.
https://localhost:5001/api/SomeThing2/dog

However, when called from TestServer's HttpClient it returns a 404 when the SomeThing2 controller is in a class library. Cut and paste the controller back to the main application results in TestServer's HttpClient returning a 200.

To Reproduce

minimal project
or
AzurePipelinesDemoAspNetCore

Currently, it is failing my tests when the Something2 is an external project
https://github.com/P7CoreOrg/AzurePipelinesDemoAspNetCore/blob/master/src/SomeThing2/Controllers/SomeThing2Controller.cs

Cut and Paste the SomeThing2Controller to the following location;
https://github.com/P7CoreOrg/AzurePipelinesDemoAspNetCore/tree/master/src/TheWebApp/Controllers
which is in the main app make everything work.

https://github.com/P7CoreOrg/AzurePipelinesDemoAspNetCore/blob/master/src/xUnit_TheWebAppTests/UnitTestSomeThing.cs

       [Fact]
       public async Task Test_Get_SomeThing2_Success()
       {
           var client = _fixture.Client;
           var req = new HttpRequestMessage(HttpMethod.Get, "/api/SomeThing2/dog")
           {
               // Content = new FormUrlEncodedContent(dict)
           };
           var response = await client.SendAsync(req);
           response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
           var jsonString = await response.Content.ReadAsStringAsync();
           jsonString.ShouldNotBeNullOrWhiteSpace();

           var dogs = JsonConvert.DeserializeObject<List<string>>(jsonString);
           dogs.ShouldNotBeNull();
           dogs.Count.ShouldBeGreaterThan(0);

       }

Expected behavior

Should not return a 404 when SomeThing2Controller is in a separate classlibrary.

@pranavkm pranavkm added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates and removed area-hosting labels May 17, 2019
@ghstahl
Copy link
Author

ghstahl commented May 18, 2019

The only clue I have so far from stepping symbols is EndpointDataSource contains only endpoints from the host app and not the referenced projects.

@ghstahl ghstahl changed the title TestServer HttpClient GetAsync returns NOT_FOUND when api is in classLibrary TestServer HttpClient SendAsync returns NOT_FOUND when api is in classLibrary May 20, 2019
@mkArtakMSFT
Copy link
Contributor

Thanks for contacting us, @ghstahl.
This got fixed today: #4332
Closing this issue as a dupe.

@mkArtakMSFT mkArtakMSFT added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label May 20, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates ✔️ Resolution: Duplicate Resolved as a duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants