【发布时间】:2015-05-10 14:38:04
【问题描述】:
我在 ASP.Net Web 应用程序中进行单元测试,现在我可以访问模型文件中的构造函数来测试哪个具有用于上传我的 XML 文件的 Server.MapPath 代码,当尝试测试这个时我得到错误,因为HttpContext 为空,所以我必须模拟 Server.MapPath。
我已经搜索了很多,但每个示例仅针对 Asp.NET MVC,但我在 ASP.NET 中工作。所以请帮助 ASP.NET 解决这个问题。
我的代码如下。
public class NugetPlatformModel
{
public bool IsHavingLicense { get; set; }
public List<PlatformProducts> PlatformProduct = new List<PlatformProducts>();
public NugetPlatformModel()
{
var xmldoc = new XmlDocument();
mldoc.Load(HttpContext.Current.Server.MapPath(@"~\Content\PlatformProducts.xml"));
}
}
还有我的单元测试代码
[Test]
public void Account_UnlicensedCustomerIdentity_IsStudioLicenseAndIshavinglicenseFalse()
{
//Act
NugetPlatformModel nugetPlatformModel = new NugetPlatformModel();
//Assert
AssertEquals(false, nugetPlatformModel.IsHavingLicense);
}
【问题讨论】:
标签: c# asp.net asp.net-mvc unit-testing