I'm creating integration tests (web class library project) for my ASP5 MVC6 application. I want to add a resource file with raw SQL to the test project for DB preparation.
I wanted to use good old resources (.resx). But I it's not available in add new item
project's menu.
I found this answer pointing to a github repo . I guess this is where he reads the file:
using (var stream = FileProvider.GetFileInfo("compiler/resources/layout.html").CreateReadStream())
using (var streamReader = new StreamReader(stream))
{
return streamReader.ReadToEnd().Replace("~", $"{basePath}/compiler/resources");
}
I tried using System.IO.File.ReadAllText("compiler/resources/my.sql")
in my test helper project in TestHelper class.
When I used the TestHelper class in my actual test project it was looking for the the file in test project directory.
TestProject/compiler/resources/my.sql
insetad of TestHelperProject/compiler/resources/my.sql
I can figure out a couple of workarounds. However I'd like to do it the right way. Preferably like I would do in with a resx file:
string sql = Resources.MySql;
Any suggestions?
EDIT
It is a little more complicated because there's no tooling support but it is doable:
resx
file or copy it from somewhere else like a classic C# project sake
as the build system, then you can use the same target that we, the ASP.NET team use: https://github.com/aspnet/Universe/blob/dev/build/_k-generate-resx.shade otherwise, you need to implement something similar in your own build scripts compiler/resources
. If you place them under any other folder then include them in the project json (like here )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.