aspnet / Mvc

[Archived] ASP.NET Core MVC is a model view controller framework for building dynamic web sites with clean separation of concerns, including the merged MVC, Web API, and Web Pages w/ Razor. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
5.62k stars 2.14k forks source link

Use of "AppDomain.FriendlyName" in Microsoft.AspNetCore.Mvc.Testing causes issues with test runner #8761

Closed remcoros closed 5 years ago

remcoros commented 5 years ago

Is this a Bug or Feature request?

A bug report for AspNetCore.Mvc.Testing package

Steps to reproduce:

Example project: https://github.com/remcoros/MvcTestingReSharper

It's the default file new -> asp core template.

Description of the problem:

When using MS.AspNetCore.Mvc.Testing on .net framework, I get the following exception when using the ReSharper test runner:

The content root 'C:\Projects\MvcTestingReSharper\MvcTestingReSharper' does not exist.
Parameter name: contentRootPath

I've tracked the cause of this down to: https://github.com/aspnet/Mvc/blob/master/src/Microsoft.AspNetCore.Mvc.Testing/WebApplicationFactory.cs#L218 where the location of the web project is determined.

It uses AppDomain.FriendlyName, but this turns out to be not so consistent. E.g. ReSharper domains are called "Entryway", and when disabling appdomains, it's called "Tests: {AssemblyName}".

I reported this to JetBrains here: https://youtrack.jetbrains.com/issue/RSRP-472316?replyTo=27-3174095

As seen in the comments there, using FriendlyName might not always work.

Version of Microsoft.AspNetCore.Mvc or Microsoft.AspNetCore.App or Microsoft.AspNetCore.All:

2.1.6

mkArtakMSFT commented 5 years ago

Thanks for contacting us, @remcoros. @javiercn, can you please look into this? Thanks!

javiercn commented 5 years ago

@remcoros I'm not sure there's an alternative way for us to infer the test assembly automatically other than the approach we take here. If I'm missing something feel free to suggest and alternative (we will take suggestions/PRs here as long as they are not runner specific).

Alternatively, the recommended way is to extend WebApplicationFactory and override the GetTestAssemblies method to manually provide the test assembly.

remcoros commented 5 years ago

@javiercn I couldn't think of anything either, but wanted to report it. In case someone has a suggestion. Let's see what Jetbrains can do, else I'll have to use GetTestAssemblies.

javiercn commented 5 years ago

@remcoros That's the main reason there's an extensibility point defined there.

mkArtakMSFT commented 5 years ago

Closing as it seems there is no good way to achieve this. Per @javiercn's point, there is an extensibility point to provide custom implementation, if necessary.

remcoros commented 5 years ago

👍 thanks for looking at it.