Hello!!
Please help me how to nunit test. I have a method in the controller and i want to unit test it with the concept of mocking.
Can anyone guide me through on Nunit testing?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ranjeet PatraRank #1,436 · 1.1K reputationPosted Mar 30, 2017, 12:25 AM EDT
Rohanjoy BhattacharyaRank #7,492 · 240 reputationPosted Mar 30, 2017, 1:50 AM EDT
Ranjeet PatraRank #1,436 · 1.1K reputationPosted Mar 30, 2017, 2:43 AM EDT
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
public void About()
{
// Arrange
HomeController controller = new HomeController();
// Act
ViewResult result = controller.About() as ViewResult;
// Assert
Assert.AreEqual("Your application description page.", result.ViewBag.Message);
}
Rohanjoy BhattacharyaRank #7,492 · 240 reputationPosted Mar 30, 2017, 3:23 AM EDT
Ranjeet PatraRank #1,436 · 1.1K reputationPosted Mar 30, 2017, 3:57 AM EDT
public void About()
{
// Arrange
HomeController controller = new HomeController();
// Act
bool val = controller.About();
// Assert
Assert.IsTrue(val);
}