I am planning to write unit testcase for my MVC controller.
I am using NUnit Framework.
here is my Controller method:
public async Task<ActionResult> SearchView() { List<Role> allRoles = (await _nmClient.GetDataAsync<IEnumerable<Role>>(Session, "/UserSvc/v1/Roles?skip=0&take=" + Constants.MaxSearchRowNumber)).ToList(); model.Roles=_helper.GetAvailableRoles(Session.Contents["Session"], allRoles, true); List<LicenseType> allLicenseTypes = (await _Client.GetPlatformDataAsync<IEnumerable<LicenseType>>(Session, "/UserSvc/v1/Types?skip=0&take=" + Constants.MaxSearchRowNumber)).ToList(); model.TypesJson = Newtonsoft.Json.JsonConvert.SerializeObject(allLicenseTypes); return View("SearchUsers", model); } Here first I am trying to validate the view name,But I am facing issue with getting the view name from action result.
here is my Test Method:
[Test] public void TestSearchUserView() { string expected= "SearchUserView"; PlatformUserController controller = new PlatformUserController(); var result= controller.SearchUserView() as Task<ActionResult>; //Assert.AreEqual("SearchUserView", result.); } Please let me know how can I mock the response of service as well.