title: C# Unit Test Mocking using Moq.dll
body: <p>My test case always fails, tell me where I am wrong, Code is below</p>
  
  <pre><code>public class EmployeeService
  {
      private readonly IRepository _repository;
  
      public EmployeeService(IRepository repository)
      {
          _repository = repository;
      }
  
      public bool SaveEmployeeData(Employee employee,bool isSaveNeeded)
      {
          bool result = false;
          try
          {
              if (isSaveNeeded)
              {
                  result= _repository.Save(employee);
              }
          }
          catch (Exception ex)
          {
              throw new Exception();
          }
          return result;
      }
  }
  </code></pre>
  
  <p>And My test case is</p>
  
  <pre><code>[TestMethod()]
  public void SaveEmployeeDataTest()
  {
      var a = new Mock&lt;IRepository&gt;();
      a.Setup(s =&gt; s.Save(new Employee())).Returns(true).Verifiable();
      var result = new EmployeeService(a.Object).SaveEmployeeData(new Employee(), true);
      Assert.IsTrue(result);
  }
  </code></pre>
  
  <p>It always fails.</p>