Tuesday, June 23, 2015

Using Moq and Unity together for testing

Moq lets you generate class (code) with prescribed behavior.
  • Moq needs an interface
  • Moq api is used to set the behavior of the generated class
Unity lets you resolve an interface to a concrete implementation.
  • Register an interface with the desired concrete implementation
  • The concrete implementation can be an instance of class generated by Moq for testing purposes
  • In production, the interface is configured to resolve to real implementation classes