-
Notifications
You must be signed in to change notification settings - Fork 2.1k
TestServer + MVC + Razor = The type or namespace could not be found. #6908
Comments
@javiercn can you take a look at this? Do the new test helpers you've built help in this scenario? |
There are a few things that you need to have in order to run an MVC application in memory.
We will be releasing this as a package in the next release, but for now you can just put it in your csproj and in your test project. |
@javiercn if I follow you, I need to copy my MVC's .deps.json to the bin directory of my test project. I did that. Then, I need to add WebHostBuilderExtensions and WebApplicationTestFixture to my test project, so that I can use .UseSolutionRelativeContentRoot(). I don't get any errors with the using clauses, but both classes have errors in them. WebApplicationTestFixture
"Resources is inaccessible due to its protection level."
"The name WebHostBuilderFactory does not exist in the current context. I ensured that the test project has both Microsoft.AspNetCore.Hosting and Microsoft.Extensions.DependencyInjection installed. WebHostBuilderExtensions has four lines with errors.
"The type of namespace IStartupConfigureServicesFilter could not be found. (are you missing a using directive or an assembly reference?)
"The type of namespace IStartupConfigureContainerFilter could not be found. (are you missing a using directive or an assembly reference?)
If I setup TestServer with
I get the error: System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.VisualStudio.Web.CodeGeneration, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.' If I install Microsoft.VisualStudio.Web.CodeGeneration into the test project, I get the error: |
I am using VS 2017 15.3.5. I have an MVC project that was created with the .NET Core 2.0 template and targets netcoreapp2.0. I have a test project that was created with the xUnit Test Project (.NET Core) template and targets netcoreapp2.0. I am running on Windows. When I hit the AccountController.Login() GET method and return the Login.cshtml view, I get the same error as described in #1731.
The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
Predefined type 'System.Object' is not defined or imported
The type or namespace name 'ViewFeatures' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?)
The work around described in #4818 resolves the issue, but is impractical for running on other machines or deploying to a server.
Additionally, I have a wrapper class, for an HttpClient. It works supports Identity, IdentityServer, and Antiforgery. If I run the MVC app in a separate instance of VS, without using TestServer, the test run, and succeed. If I set my wrappers HttpClient, with TestServer.CreateClient(), the AccountControler.Login() POST method does not execute because of the Antiforgery token. Does HttpServer not support Antiforgery?
The text was updated successfully, but these errors were encountered: