title: Unit testing asp.net MVC controller with constructor injection
body: <p>How do i setup my test project so that i can unit test my controllers,
  I'm not able to call my controller actions from test method as it requires dependent interface object.
  I don't want to implement any mock repository.
  I want to use my existing database repository and business logic available same as integration testing.</p>
  
  <p>My Project Structure is as below:</p>
  
  <ul>
  <li>MVC.Web</li>
  <li>MVC.BL (Interface and implementation)</li>
  <li>MVC.Repository (Interface and implementation)</li>
  </ul>
  
  <p>Repository Example:</p>
  
  <pre><code>public class UserRepository : IUserRepository
  {
      private readonly IBaseUOW&lt;DBEntitiesEntities&gt; _dbContext;
      private readonly IBaseRepository&lt;User&gt; _userRepository;
  
      public UserRepository(IBaseUOW&lt;MoynoECTNewEntities&gt; dbContext)
      {
          _dbContext = dbContext;
          _userRepository = dbContext.GetRepository&lt;User&gt;();
      }
  
      public UserResponse GetUserList()
      {
          var response = new UserResponse {Acknowledge = AcknowledgeType.Success};
  
          var typeList = _userRepository.Get().OrderBy(x =&gt; x.UserName).ToList();
  
          response.UserList = typeList.ToList();
  
          return response;
      }
  }
  </code></pre>
  
  <p>Business Layer Example:</p>
  
  <pre><code>public class UserBL : IUserBL
  {
      public UserResponse GetUserList()
      {
          var response = new UserResponse();
  
          var userList = _userRepository.GetUserList();
          if (userList != null &amp;&amp; userList.UserList.Count &gt; 0)
          {
              response.UserList = userList.UserList.ToList();
          }
          else
          {
              response.Message = "No Data Found";
              response.Acknowledge = AcknowledgeType.Failure;
          }
  
          return response;
      }
  }
  </code></pre>
  
  <p>Controller Example:</p>
  
  <pre><code>public class AdminController : BaseController
  {
      public readonly IUserBL _userBl;
      public readonly IUserRoleBL _userRoleBl;
  
      public AdminController(IUserRoleBL userRoleBl, IUserBL userBl)
      {
          _userRoleBl = userRoleBl;
          _userBl = userBl;
      }
  
      public ActionResult GetUserList()
      {
          var response = _userBl.GetUserList();
          return View("_GridViewUser", response.UserList);
      }
  }
  </code></pre>
  
  <p>My unit test method example:</p>
  
  <pre><code>[TestClass]
  public class AdminControllerTest
  {
  
      [TestMethod]
      public void Check_UserMaster_ViewName()
      {
         //assemple
          var controller = // how to call controller ?
         // act
          var result= // controller.GetUserList() as ViewResult;
         // assert
          Assert.AreEqual("UserMaster", result.ViewName);
      }
  }
  </code></pre>