MOQ is a Mock Object Framework, used to build mock objects for the testing of a project.
As the software development process that will be followed is TDD, the building of tests will be a central part, and mock objects are very interesting in this field.
After installing MOQ, I will write a simple test to see how it works.
The test will consist in retrieving a Document object (like in a search) and asserting that it exists. For that, a Document object and an IDocument interface are created in the Models folder of the MEDManagerMain project. My purpose is to mock Document in MEDManagerMain.Tests.
Once written, the test looks like this:
[TestMethod]
public void RetrieveDocumentFromID()
{
var mDocument = new Mock<IDocument>();
mDocument.Setup(x => x.ID).Returns(1);
mDocument.Setup(x => x.name).Returns("Test Document");
Assert.AreEqual("Test Document", mDocument.Object.name);
Assert.AreEqual(1, mDocument.Object.ID);
}
Test is run and it passes.
Sources: