gpt4 book ai didi

c# - 单元测试中的 OpenRasta 模拟 HttpContext

转载 作者:太空狗 更新时间:2023-10-30 01:24:02 24 4
gpt4 key购买 nike

目前我正在使用 NUnit 为我的处理程序方法编写单元测试。我使用了 HttpContext.Current在我的 Controller 方法之一中,它在 HttpContext.Current 处抛出 NULL 引用异常当我为我的处理程序执行测试用例时。

有什么方法可以模拟 HttpContext?或者有什么其他方法可以解决这个问题。

最佳答案

您不需要直接访问 HttpContext.Current。您应该能够使用 available dependencies 之一 很容易模仿。

关于c# - 单元测试中的 OpenRasta 模拟 HttpContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10499237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com