Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a simple Unit test too. Im just studing. namespace UnitTest { [TestClass] public class HomeController { [TestMethod] public void Index_NoInputs_ReturnsDefaultViewResult() { // Arrange

I have a simple Unit test too. Im just studing.

namespace UnitTest { [TestClass] public class HomeController { [TestMethod] public void Index_NoInputs_ReturnsDefaultViewResult() { // Arrange HomeController controller = new HomeController(); // Act ViewResult result = Index() as ViewResult; // Assert Assert.IsNotNull(result); Assert.AreEqual("", result.ViewName); Assert.IsNull(result.Model); } } }

The index is underlined at the Act

My HomeController.cs

public class HomeController : Controller { private readonly IEmployeeRepository _employeeRepository; public HomeController(IEmployeeRepository employeeRepository) { _employeeRepository = employeeRepository; } public IActionResult Index() { return View(); } [HttpGet] public IActionResult GetAllEmployee() { var allEmployee = _employeeRepository.AllEmployee(); var j = Json(allEmployee); return j; } [HttpGet] public IActionResult GetEmployeeDetails(int id) { var employee = _employeeRepository.Get(id); return Json(employee); } }

Ive also tried it this way too. But it still not okay.

namespace UnitTest { [TestClass] public class HomeControllerTests { [TestMethod] public void Index_NoInputs_ReturnsDefaultViewResult() { IEmployeeRepository repository = .......; HomeController controller = new HomeController(repository); // Act ViewResult result = controller.Index() as ViewResult; // Assert Assert.IsNotNull(result); Assert.AreEqual("", result.ViewName); Assert.IsNull(result.Model); } } }

I tried figure out what comes after the

IEmployeeRepository repository = ...

But it just did not want work out.

Please show me the full test coding and explain it too. .Im just studing. Thanks.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions