开发者

Functional Tests getting a file from App_Data Folder

开发者 https://www.devze.com 2023-01-25 00:30 出处:网络
I am writing functional tests and the method I am writing the tests for has to access a file in the App_Data Folder. I have tried

I am writing functional tests and the method I am writing the tests for has to access a file in the App_Data Folder. I have tried

System.Web.HttpContext.Current.Se开发者_如何转开发rver.MapPath("~/App_Data/test.txt");

as well as

Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "test.txt");

Both of them are not working. Is there a way to achieve this in functional test?

Any ideas in this regard is much appreciated.

Thanks,

Raja


I found a solution at last (with the help of my solutions architect). We set up an app config for the functional test project and we set the file name as one of the appsettings. After that we specified the relative path to the actual file as a

[DeploymentItem(@"..\..\Project1\App_Data\Test.txt")] 

attribute for the test class. We added a simple hack to use Absolute Path if it is in test (app config) and

Server.MapPath("Test.txt")

if it is not test. The logic to the solution is that since we put the file as a DeploymentItem it goes straight to the respective TestResults folder so if we use absolute path it is going to be able to reference it.

Hope this helps someone.

0

精彩评论

暂无评论...
验证码 换一张
取 消