对于单元测试,我使用System.Web.Http.HttpServer类运行内存中的服务器。当试图实例化Enterprise对象时,它会阻塞,因为企业库(v5.0.414.0)是在XML文件App.config中配置的,该文件没有被读取。
是否可以在.config文件中读取,还是被迫启动本地服务器(例如WcfSvcHost.exe)?
更新:
我能够这样加载配置(从How to OpenWebConfiguration with physical path?):
var wcfm = new System.Web.Configuration.WebConfigurationFileMap();
var vdm = new System.Web.Configuration.VirtualDirectoryMapping( @"C:\MyPath\", true, "App.config" );
wcfm.VirtualDirectories.Add( "/", vdm );
var cfg = System.Web.Configuration.WebConfigurationManager.OpenMappedWebConfiguration( wcfm, "/" );但是,我不知道向HttpServer对象传递数据的任何简单方法(cfg是Configuration类型,显然与HttpServer构造函数中的HttpConfiguration类型无关)。
我想避免实现一个IISExpress解决方案,但看起来我不得不走这条路,以支持Enterprise 5跛行。
发布于 2015-08-21 22:32:46
结果表明,内存中的HttpServer类工作正常,不需要自带的东西。我只需要在我的单元测试项目和Web 2项目中引用几个企业库程序集。
融合日志再次挽救了这一局面。调试晦涩的库解析错误的好方法。( http://www.hanselman.com/blog/BackToBasicsUsingFusionLogViewerToDebugObscureLoaderErrors.aspx )
https://stackoverflow.com/questions/32083003
复制相似问题