Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
A friendly substitute for .NET mocking libraries.
| Date | Stars |
|---|---|
| 2026-07-24 | 2965 |
| 2026-07-25 | 2965 |
| 2026-07-28 | 2965 |
| 2026-07-30 | 2965 |
| 2026-08-06 | 2965 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
35.0
growth rate 0.00%/day
NSubstitute
========
[](https://github.com/nsubstitute/NSubstitute/actions/workflows/test.yml)
[](https://www.nuget.org/packages/NSubstitute)
Visit the [NSubstitute website](https://nsubstitute.github.io) for more information.
### What is it?
NSubstitute is designed as a friendly substitute for .NET mocking libraries.
It is an attempt to satisfy our craving for a mocking library with a succinct syntax that helps us keep the focus on the intention of our tests, rather than on the configuration of our test doubles. We've tried to make the most frequently required operations obvious and easy to use, keeping less usual scenarios discoverable and accessible, and all the while maintaining as much natural language as possible.
Perfect for those new to testing, and for others who would just like to to get their tests written with less noise and fewer lambdas.
### Installation
* [NSubstitute package](https://nuget.org/List/Packages/NSubstitute)
* Optional Roslyn analysers (recommended):
* For C# projects: [NSubstitute.Analyzers.CSharp](https://www.nuget.org/packages/NSubstitute.Analyzers.CSharp/)
* For VB projects: [NSubstitute.Analyzers.VisualBasic](https://www.nuget.org/packages/NSubstitute.Analyzers.VisualBasic/)
### Getting help
If you have questions, feature requests or feedback on NSubstitute please [raise an issue](https://github.com/nsubstitute/NSubstitute/issues) on our project site. All questions are welcome via our project site, but for "how-to"-style questions you can also try [StackOverflow with the \[nsubstitute\] tag](https://stackoverflow.com/tags/nsubstitute), which often leads to very good answers from the larger programming community. StackOverflow is especially useful if your question also relates to other libraries that our team may not be as familiar with (e.g. NSubstitute with Entity Framework).
### Basic use
Let's say we have a basic calculator interface:
```csharp
public interface ICalculator
{
int Add(int a, int b);
string Mode { get; set; }
event Action PoweringUp;
}
```
<!--
```requiredcode
ICalculator _calculator;
[SetUp]
public void SetUp() { _calculator = Substitute.For<ICalculator>(); }
```
-->
We can ask NSubstitute to create a substitute instance for this type. We could ask for a stub, mock, fake, spy, test double etc., but why bother when we just want to substitute an instance we have some control over?
```csharp
_calculator = Substitute.For<ICalculator>();
```
⚠️ **Note**: NSubstitute will only work properly with interfaces or with `virtual` members of classes. Be careful substituting for classes with non-virtual members. See [Creating a substitute](https://nsubstitute.github.io/help/creating-a-substitute/#substituting_infrequently_and_carefully_for_classes) for more information.
Now we can tell our substitute to return a value for a call:
```csharp
_calculator.Add(1, 2).Returns(3);
Assert.That(_calculator.Add(1, 2), Is.EqualTo(3));
```
We can check that our substitute received a call, and did not receive others:
```csharp
_calculator.Add(1, 2);
_calculator.Received().Add(1, 2);
_calculator.DidNotReceive().Add(5, 7);
```
If our Received() assertion fails, NSubstitute tries to give us some help as to what the problem might be:
```
NSubstitute.Exceptions.ReceivedCallsException : Expected to receive a call matching:
Add(1, 2)
Actually received no matching calls.
Received 2 non-matching calls (non-matching arguments indicated with '*' characters):
Add(1, *5*)
Add(*4*, *7*)
```
We can also work with properties using the Returns syntax we use for methods, or just stick with plain old property setters (for read/write properties):
```csharp
_calculator.Mode.Returns("DEC");
Assert.That(_calculator.Mode, Is.EqualTo("DEC"));
_calculator.Mode = "HEX";
Assert.That(_calculatExcerpt of 6,149 characters
Read on GitHubDavid Tchepak · Australia
861
Oleksandr Povar · @CluedIn-io · Denmark
60
48
46
30
21
Brendan Forster · Canada
16
Julian Verdurmen · Netherlands
15
Ani Betts · Germany
11
10
Rob Moore (MakerX) · @MakerXStudio · Australia
8
7
Xerxes Battiwalla · Australia
6
5
5
4
4
4
3
3
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:f36eebc3aa2beac4, topic:testing