0

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

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

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

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

4

1 回答 1

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"));
于 2013-08-02T08:46:26.890 回答