title: How to verfiy that a method has been called a certain number of times using Moq?
body: <p>I have the following implementation,</p>
  
  <pre><code>public interface IMath {
      double Add(double a, double b);
      double Subtract(double a, double b);
      double Divide(double a, double b);
      double Multiply(double a, double b);
      double Factorial(int a);
  }
  
  public class CMath: IMath {
      public double Add(double a, double b) {
          return a + b;
      }
  
      public double Subtract(double a, double b) {
          return a - b;
      }
  
      public double Multiply(double a, double b) {
          return a * b;
      }
  
      public double Divide(double a, double b) {
          if (b == 0)
              throw new DivideByZeroException();
          return a / b;
      }
  
      public double Factorial(int a) {
          double factorial = 1.0;
          for (int i = 1; i &lt;= a; i++)
              factorial = Multiply(factorial, i);
          return factorial;
      }
  }
  </code></pre>
  
  <p>How can I test that <code>Multiply()</code> is called <strong>n</strong> times when <strong>n</strong>'s Factorial is calculated?</p>
  
  <p>I'm using NUnit 3 and Moq. Following are the tests that I have already written,</p>
  
  <pre><code>[TestFixture]
  public class CMathTests {
  
      CMath mathObj;
  
      [SetUp]
      public void Setup() {
          mathObj = new CMath();
      }
  
      [Test]
      public void Add_Numbers9and5_Expected14() {
          Assert.AreEqual(14, mathObj.Add(9, 5));
      }
  
      [Test]
      public void Subtract_5From9_Expected4() {
          Assert.AreEqual(4, mathObj.Subtract(9, 5));
      }
  
      [Test]
      public void Multiply_5by9_Expected45() {
          Assert.AreEqual(45, mathObj.Multiply(5, 9));
      }
  
      [Test]
      public void When80isDividedby16_ResultIs5() {
          Assert.AreEqual(5, mathObj.Divide(80, 16));
      }
  
      [Test]
      public void When5isDividedBy0_ExceptionIsThrown() {
          Assert.That(() =&gt; mathObj.Divide(1, 0),
              Throws.Exception.TypeOf&lt;DivideByZeroException&gt;());
      }
  
      [Test]
      public void Factorial_Of4_ShouldReturn24() {
          Assert.That(mathObj.Factorial(4), Is.EqualTo(24));
      }
  
      [Test]
      public void Factorial_Of4_CallsMultiply4Times() {
  
      }
  }
  </code></pre>
  
  <p>I'm fairly new to using Moq so I'm not quite getting it at the moment.</p>