title: Using MOQ to test a repository
body: <p>I am trying to test a repository using MOQ to mock the behavior of the repo. I am failry new to MOQ, so bear with me please.</p>
  
  <p>Given the following method:</p>
  
  <pre><code>public static SubmissionVersion DeleteNote(IRepository repository, SubmissionVersion version, Guid noteId)
  {
      Note note = repository.GetById&lt;Note&gt;(noteId);
      version.Notes.Remove(note);
      repository.Save(version);
      repository.Delete(note);
      return repository.GetById&lt;SubmissionVersion&gt;(version.Id);
  }
  </code></pre>
  
  <p>Does this test look OK?</p>
  
  <pre><code>[Fact]
  public void DeleteNoteV2()
  {
      // Arrange
      var note = new Note{ Id = Guid.NewGuid()};
  
      var subVersion = new Mock&lt;SubmissionVersion&gt;();
      subVersion.Setup(x =&gt; x.Notes.Remove(note));
  
      var repo = new Mock&lt;IRepository&gt;();
      repo.Setup(x =&gt; x.GetById&lt;Note&gt;(note.Id)).Returns(note);
      repo.Setup(x =&gt; x.GetById&lt;SubmissionVersion&gt;(It.IsAny&lt;Guid?&gt;())).Returns(subVersion.Object);
  
      // Act
      SubmissionVersion.DeleteNote(repo.Object, subVersion.Object, note.Id.Value);
  
      // Assert
      repo.Verify(x =&gt; x.GetById&lt;Note&gt;(note.Id), Times.Once());
      repo.Verify(x =&gt; x.Save(subVersion.Object), Times.Once());
      repo.Verify(x =&gt; x.Delete(note), Times.Once());
  
      subVersion.Verify(x =&gt; x.Notes.Remove(It.IsAny&lt;Note&gt;()), Times.Once());
  }
  </code></pre>