【问题标题】:How to pass Dynamic value to pathtowebapp [AspNetDevelopmentServer(identifier,pathtowebapp)] attribute in Unit Test method如何在单元测试方法中将动态值传递给 pathtowebapp [AspNetDevelopmentServer(identifier,pathtowebapp)] 属性
【发布时间】:2018-01-04 20:40:23
【问题描述】:

我在此有单元测试项目,我正在使用 AspNetDevelopmentServer 属性在本地测试我的 wcf 服务。当我像这样给出硬编码的参数时,它工作正常

[AspNetDevelopmentServer("Test",@"C:\\Users\\LocalSourcePath")]

当我尝试通过变量(动态)传递这个参数时,比如

string path = @Directory.GetParent((Directory.GetParent(Path.GetDirectoryName((new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)).LocalPath))).Parent.FullName).FullName+"\\Publish";
[AspNetDevelopmentServer("Test",path )]

它会抛出这样的错误:

"属性参数必须是常量表达式,typeof 属性参数类型的表达式或数组创建表达式 "

还有其他方法可以将动态值传递给属性吗?提前谢谢。

【问题讨论】:

    标签: c# asp.net unit-testing wcf aspnet-development-server


    【解决方案1】:

    尝试使用其他项目的相对路径(大概在 C:\Users\LocalSourcePath 中的同一 Visual Studio 解决方案中):

    [AspNetDevelopmentServer("Test", @"..\..\MyProject")]
    

    路径是相对于您的 MyProjectTests\bin\debug 文件夹

    【讨论】:

      猜你喜欢
      • 2018-11-26
      • 2017-11-23
      • 2019-01-31
      • 2019-06-29
      • 2014-03-22
      • 1970-01-01
      • 2012-02-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多