I couldn't figure out how to use Moq to run assertions on calls on mocked objects, so I made my own mocking system to do that.
- Uses System.Reflection.Emit to create types at runtime, that implement arbitrary interfaces (mock objects) and record the parameters of any method call
- Inspect the parameters of specific invocations, and run assertions using your favorite unit testing framework
- Supports methods with an arbitrary amount of parameters, with arbitrary types, or no parameters at all
- Supports method with both void and non-void return types (and returns the default value for the type)
- Supports methods that return Task or Task<T> (and return
Task.CompletedTask
orTask.FromResult(default(T))
respectively) - Separate package offering NUnit constraints to make your job easier
- Configure the return values of expected method invocations, by invocation index or by parameter criteria
- Support for generic types and methods, and recording the generic type parameters
- Instead of manually emitting CIL, use a library that can convert expressions into CIL
CorporateEspionage is meant to be used from within unit tests, so this repository's unit tests are good examples of how to use it.