c# mocking system with spying capabilities
Find a file
Dirk Kok d3b3ee9d17
All checks were successful
/ build (push) Successful in 34s
/ deploy (push) Successful in 36s
set up .NET
2026-03-04 15:38:22 +01:00
.forgejo/workflows set up .NET 2026-03-04 15:38:22 +01:00
CorporateEspionage typed convenience overlod for GetParameter 2023-10-26 14:55:17 +02:00
CorporateEspionage.NUnit predicate constraint for arguments 2023-10-26 14:44:03 +02:00
CorporateEspionage.Tests predicate constraint for arguments 2023-10-26 14:44:03 +02:00
.dockerignore first wip 2023-03-05 01:31:51 +01:00
.gitignore first wip 2023-03-05 01:31:51 +01:00
CorporateEspionage.sln nunit assertions 2023-04-03 21:07:47 +02:00
global.json first wip 2023-03-05 01:31:51 +01:00
LICENSE Create LICENSE 2023-03-05 03:03:24 +01:00
README.md Update README.md 2023-05-02 22:40:55 +02:00

CorporateEspionage

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.

Features

  • 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 or Task.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

Planned features

  • Support for generic types and methods, and recording the generic type parameters

Wishlist features

  • Instead of manually emitting CIL, use a library that can convert expressions into CIL

How to use

CorporateEspionage is meant to be used from within unit tests, so this repository's unit tests are good examples of how to use it.