C# 单元测试集 HttpRuntime.BinDirectory
我有一个明确而简单的问题。 我正在开发的 Web 应用程序正在使用单元测试(接近 1500 次测试)。由于应用程序中需要进行修改,一些测试失败,因为 HttpRuntime.BinDirectory 没有值,因此抛出 ArgumentNullException。
有没有办法在 HttpRuntime.BinDirectory 中设置我自己的值?或者使用 Moq 框架来模拟它?
任何帮助表示赞赏!
I've got a clear and simple question.
The webapplication i'm working on is using unit tests (close to 1500 tests). Due to an required modification in the application several tests are failing because The HttpRuntime.BinDirectory doesn't have a value and therefor throws and ArgumentNullException.
Is there a way to set my own value in HttpRuntime.BinDirectory? Or to Mock it using the Moq framework?
Any help is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您自己的代码正在调用
HttpRuntime.BinDirectory
,那么就不要这样做。创建您自己的类,例如带有属性BinDirectory
的ExecutionContext
,该类可以根据是否从 asp.net 或内部单元测试调用来推断正确的位置。您还可以使用
Assembly.CodeBase
来代替,只要您获取自己的程序集之一(而不是 gac 中的某些内容),它就可以在这两种情况下工作。Assuming your own code is calling into
HttpRuntime.BinDirectory
, then just don't do that. Create your own class likeExecutionContext
with a propertyBinDirectory
which can infer the correct location based on if it's called from asp.net or inside unit tests.You could also use
Assembly.CodeBase
instead which will work in both situations as long as you grab one of your own assemblies (not something in the gac).