I am doing unit testing of one of my action method in ASP.NET MVC 4 application.
And the problem is there is one private property in the action method of that controller.Below is the code of Private property and method :-
Private Property :
private int ProductId
{
get { return Convert.ToInt32(System.Web.HttpContext.Current.Session["FKProductID"]); }
set { System.Web.HttpContext.Current.Session["FKProductID"] = value; }
}
Method :
public ActionResult GetDetails(string Name, int area, int ProdCategoryId = 0)
{
ProductCategoryViewModel model = new ProductCategoryViewModel
{
Area= area,
FKProductID = ProductId, //private property
};
else if (model.FKProductID > 0)
{
ProductDto product= ProductService.GetProductDetails(model.FKProductID);
}
Unit test method code :
public void SelectProductTest()
{
// Act
var result = controller.GetDetails(name,area, prodcatid) as PartialViewResult;
}
As i passed the three required parameters in the test method but i am getting problem on private property place(when the control rich's it).
Can anyone let me know how to deal with such a condition ?