Why the TestServer (AspNetCore) gives 404 error on static files?

后端 未结 2 557
清歌不尽
清歌不尽 2021-01-16 16:04

I have a sample server

var host = new WebHostBuilder()
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
               


        
相关标签:
2条回答
  • 2021-01-16 16:21

    Another approach is to copy those files into your unit test project

    Then

    As far as you maintain the same structure folder of the project that you are testing, it will find out the files and pass it to the dependency injection process.

    0 讨论(0)
  • 2021-01-16 16:43

    XUnit starts the site from a different directory. We've had to work around it like this: https://github.com/aspnet/StaticFiles/blob/d692066b2bd711653150ad2cccc2268583355532/test/Microsoft.AspNetCore.StaticFiles.Tests/StaticFilesTestServer.cs#L20

    0 讨论(0)
提交回复
热议问题