简体   繁体   English

如何在 c# 中获取集成测试中的相对路径

[英]How to get relative path in Integration Testing in c#

Problem问题

I am trying to test my importing service in which I have to provide file which is save in the same solution but different folder and also there are bunch of project in it too and this folder is out of the projects.我正在尝试测试我的导入服务,我必须在其中提供保存在同一解决方案但不同文件夹中的文件,并且其中也有一堆项目并且该文件夹不在项目中。 I want this path to be absolute path how can I do this?我希望这条路径是绝对路径我该怎么做?

I am doing in this way我这样做

string filePath = Path.GetFullPath(@"E:\Development\Project\Misc Artifacts\ImportFileSamples\city.txt");

Server.MapPath("~") gives you root path relative to your application. Server.MapPath("~") 为您提供相对于您的应用程序的根路径。 You can specify the rest of the path and use it to fetch your file.您可以指定路径的其余部分并使用它来获取您的文件。

Like Server.MapPath("/ImportFileSamples")像 Server.MapPath("/ImportFileSamples")

You already have the absolute path.你已经有了绝对路径。

you can use this to find the relative path.您可以使用它来查找相对路径。

var relativePath = Path.GetRelativePath(
@"C:\X\API\APITest.Tests\IntegrationTest\ServiceLayerTests"
@"C:\X\API\API.Test.Tests\Images\)";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM