title: Moq an interface and setting up a mock
body: <p>I have an Interface to check vowel and to return a char as</p>
  
  <pre><code>public interface IVowChecker
  {
      bool VowCheck(char a);
      char ReturnChar(int n);
      Student GetStudentById(int n);
  }
  </code></pre>
  
  <p>It's concrete class implementation</p>
  
  <pre><code>public class VowChecker:IVowChecker
  {
      public bool VowCheck(char a)
      {
          if (a == 'a' || a == 'A')
              return true;
          return false;
      }
      public char ReturnChar(int n)
      {
          return (char)n;
      }
      public Student GetStudentById(int n)
      {
          var list = new []
          {
              new Student{RollNo=1,Name="A"},
              new Student{RollNo=2,Name="B"},
              new Student{RollNo=3,Name="C"},
              new Student{RollNo=4,Name="D"},
              new Student{RollNo=5,Name="E"},
              new Student{RollNo=6,Name="F"},
          };
  
          var student = from i in list
                        where i.RollNo == n
                        select i;
          return student.FirstOrDefault();
      }
  }
  </code></pre>
  
  <p>And a service using this VowChecker</p>
  
  <pre><code>public class MyCharService
  {
      private readonly IVowChecker _checker;
  
      public MyCharService(IVowChecker checker)
      {
          _checker = checker;
      }
      public bool CheckInput(char a)
      {
          return _checker.VowCheck(a);
      }
      public char ReturnChar(int a)
      {
          return _checker.ReturnChar(a);
      }
      public Student GetStudentById(int n)
      {
          return _checker.GetStudentById(n);
      }
  }
  </code></pre>
  
  <p>I am using Xunit testing framework for unit testing and Moq library.
  My unit test code is </p>
  
  <pre><code>public class MyCharServiceShould
  {
      ...
  
      [Theory]
      [InlineData(65)]
      [InlineData(68)]
      public void BeAbleToReturnChar(int n)
      {
          var service = new Mock&lt;IVowChecker&gt;();
  
          service.Setup(i =&gt; i.ReturnChar(n)).Returns('A');
          var obj = new MyCharService(service.Object);
          var result = obj.ReturnChar(n);
  
      }
      [Theory]
      [InlineData(2)]
      public void BeAbleToRetrieveStudent(int n)
      {
          var service = new Mock&lt;IVowChecker&gt;();
          service.Setup&lt;Student&gt;(i =&gt; i.GetStudentById(n)).Returns&lt;Student&gt;(f =&gt; (Student)f);
          var ob = new MyCharService(service.Object);
          var res = ob.GetStudentById(2);
          Assert.Equal(res.Name, "B");
      }
  }
  </code></pre>
  
  <p>My Student class</p>
  
  <pre><code>public class Student
  {
      public int RollNo{ get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>I have used a debugger in the last line of my test and checked the values of both the tests. For the 1st test I am expecting 'A' as the result and for the 2nd test I am expecting 'D' as the result. But in both the cases I am getting 'A' as the result. Can anyone kindly help me out where I am missing out the concept. Thank you.</p>