Build/Test Issues

Bug in setting ASPNETCORE_TEST_CONTENTROOT_ by NCrunch

Started by tiesmaster on 4,735 views

Hi,

First of all, it's awesome that NCrunch even has support in handling the ContentRoot for ASP.NET Core integration tests, however, I encountered a bug there. I've reproduced the issue in this repo: https://github.com/tiesmaster/ReproduceNCrunchBug.

Steps to reproduce:
1. Create a new ASP.NET Core MVC application (ae9ea87)
2. Add integration tests, as described here: https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-2.2#aspnet-core-integration-tests (97ad82b)
3. Override the assembly name for the main project (064fbb5)

Expected result:
UnitTest1.Test1 still creates the test server successfully

Actual result:
Exception in WebHostBuilderExtensions.UseSolutionRelativeContentRoot()

System.InvalidOperationException: Solution root could not be located using application root C:\Users\ties\AppData\Local\NCrunch\18800\13\ReproduceNCrunchBug.IntegrationTests\bin\Debug\netcoreapp2.2\.
at Microsoft.AspNetCore.TestHost.WebHostBuilderExtensions.UseSolutionRelativeContentRoot(IWebHostBuilder builder, String solutionRelativePath, String applicationBasePath, String solutionName)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.SetContentRoot(IWebHostBuilder builder)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.EnsureServer()
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateDefaultClient(DelegatingHandler[] handlers)
at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateClient(WebApplicationFactoryClientOptions options)
at ReproduceNCrunchBug.IntegrationTests.UnitTest1.Test1() in C:\src\playground\ReproduceNCrunchBug\ReproduceNCrunchBug.IntegrationTests\UnitTest1.cs:line 14

Cause:
NCrunch sets the environment variable ASPNETCORE_TEST_CONTENTROOT_<APPNAME> in order for WebApplicationFactory to find the appropriate content root that belongs to the Startup class (https://github.com/aspnet/AspNetCore/blob/7e3c69eae0cc634e37778c4d55b19fc7c1c432db/src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs#L207-L223). However, it searches using the Startup's assembly name, while NCrunch adds the ASPNETCORE_TEST_CONTENTROOT_<APPNAME> environment variables based on the project names. This results in the bug.

@remco
I hope this is enough to reproduce the bug. Let me know if you need more for this.
Hi, thanks for sharing this issue.

Can you confirm which version of NCrunch you're running? I vaguely remember this issue being reported before and I thought we'd fixed it.
Ey, thanks for the swift reply. I was running second-to-last version (v3.25.0.something), but just updated to latest (v3.26.0.4) and the tests in the reproduction still fails.
Could you try the build below to see if it resolves the problem?

NCrunch_Console_3.27.0.1.msi
NCrunch_Console_3.27.0.1.zip
NCrunch_GridNodeServer_3.27.0.1.msi
NCrunch_GridNodeServer_3.27.0.1.zip
NCrunch_LicenseServer_3.27.0.1.zip
NCrunch_VS2008_3.27.0.1.msi
NCrunch_VS2010_3.27.0.1.msi
NCrunch_VS2010_3.27.0.1.zip
NCrunch_VS2012_3.27.0.1.msi
NCrunch_VS2012_3.27.0.1.zip
NCrunch_VS2013_3.27.0.1.msi
NCrunch_VS2013_3.27.0.1.zip
NCrunch_VS2015_3.27.0.1.msi
NCrunch_VS2015_3.27.0.1.msi.7z
NCrunch_VS2015_3.27.0.1.zip
NCrunch_VS2017_3.27.0.1.msi
NCrunch_VS2017_3.27.0.1.msi.7z
NCrunch_VS2017_3.27.0.1.zip
NCrunch_VS2019_3.27.0.1.msi
NCrunch_VS2019_3.27.0.1.msi.7z
NCrunch_VS2019_3.27.0.1.zip
Awesome! That fixes it 👍

Thanks 😎!!

Post a reply

Log in to reply.