C# 单元测试集 HttpRuntime.BinDirectory

发布于 2024-09-28 18:18:07 字数 222 浏览 0 评论 0原文

我有一个明确而简单的问题。 我正在开发的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

变身佩奇 2024-10-05 18:18:07

假设您自己的代码正在调用 HttpRuntime.BinDirectory,那么就不要这样做。创建您自己的类,例如带有属性 BinDirectoryExecutionContext,该类可以根据是否从 asp.net 或内部单元测试调用来推断正确的位置。

您还可以使用 Assembly.CodeBase 来代替,只要您获取自己的程序集之一(而不是 gac 中的某些内容),它就可以在这两种情况下工作。

Assuming your own code is calling into HttpRuntime.BinDirectory, then just don't do that. Create your own class like ExecutionContext with a property BinDirectory 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文