gpt4 book ai didi

asp.net - 如何对 HttpContext.Current.Server.MapPath 进行单元测试

转载 作者:行者123 更新时间:2023-12-02 15:34:30 25 4
gpt4 key购买 nike

我在方法中使用 HttpContext.Current.Server.MapPath() 来获取文档。

要为此方法编写单元测试,

我必须做什么:

  1. 应用程序配置
  2. 在我的单元测试方法中

我如何模拟这个?

我仅对 Current.Server.Mappath() 进行单元测试,而不是对 Path.Combine()

最佳答案

可能最好的解决方案是避免使用Server.MapPath:例如,您可以替换:

Server.MapPath("~/MyFolder/MyFile.dat")

作者:

Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"MyFolder\MyFile.dat")

关于asp.net - 如何对 HttpContext.Current.Server.MapPath 进行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19511228/

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