lundi 9 mars 2015

Mocking HttpContext.server.MapPath in ASP.NET unit testing

I have working in unit testing in ASP.Net web application, now I have accessing my constructor in the model file to test which has Server.MapPath code for uploading my XMLfile, when try to testing this i get error, because the HttpContext is null so i have to mocking Server.MapPath.


I have searched lot but every samples given only for Asp.NET MVC but I have working in ASP.NET. so please help in ASP.NET to solve this issue.


My code is given below.



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"));
}
}


And my unit testing code



[Test]
public void Account_UnlicensedCustomerIdentity_IsStudioLicenseAndIshavinglicenseFalse()
{

//Act
NugetPlatformModel nugetPlatformModel = new NugetPlatformModel();

//Assert
AssertEquals(false, nugetPlatformModel.IsHavingLicense);

}

Aucun commentaire:

Enregistrer un commentaire