获取MSTest Out文件夹的绝对路径

时间:2013-08-02 08:31:27

标签: visual-studio-2012 mstest

我有一个具有以下属性的测试:

[DeploymentItem(@"SampleData\do12.vas.pdws.xls")]

当我运行测试时,我的xls文件被复制到“TestResults \ User Date \ Out”文件夹。

如何在测试中确定此文件夹的绝对路径?

1 个答案:

答案 0 :(得分:0)

我这样做了

[TestMethod]
    [DeploymentItem(@"SampleData\do12.vas.pdws.xls")]
    public void TestGetCardNumbers()
    {

        var controller = new MainController();
        var controllerContext = new Mock<ControllerContext>();

        string assemblyFile = (new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath;
        string path = System.IO.Path.GetDirectoryName(assemblyFile);
        path = Uri.UnescapeDataString(path);
        controllerContext.Setup(cc => cc.HttpContext.Session["XlFileUpload"]).Returns(System.IO.Path.Combine(path, "do12.vas.pdws.xls"));