I want to test my project using visual studio unit test but it produce error of null reference of User.Identity.GetUserID() is there any way to mock it or I have to logged-in through unit test. I have searched a lot but not found the solution.
here is code to be tested
public PartialViewResult _AdmitPatient(int id)
{
if (cFunctions.AllowAccessToRecord((int)id, User.Identity.GetUserId(), "patient") == false)
{
return null;
}
Admission admission = new Admission();
admission.PatientID = id;
return PartialView(admission);
}
Here is unit test for this code
[TestMethod]
public void TestAdmitPatView()
{
var adc = new AdmissionController();
var res = adc._AdmitPatient(6);
Assert.AreEqual(adm.PatientID, res.ViewData);
}
if I have to create logged-in in unit test kindly tell me in detail how to be logged-in