MockQueryable.NSubstitute
10.0.13
dotnet add package MockQueryable.NSubstitute --version 10.0.13
NuGet\Install-Package MockQueryable.NSubstitute -Version 10.0.13
<PackageReference Include="MockQueryable.NSubstitute" Version="10.0.13" />
<PackageVersion Include="MockQueryable.NSubstitute" Version="10.0.13" />
<PackageReference Include="MockQueryable.NSubstitute" />
paket add MockQueryable.NSubstitute --version 10.0.13
#r "nuget: MockQueryable.NSubstitute, 10.0.13"
#:package MockQueryable.NSubstitute@10.0.13
#addin nuget:?package=MockQueryable.NSubstitute&version=10.0.13
#tool nuget:?package=MockQueryable.NSubstitute&version=10.0.13
MockQueryable
Extensions for mocking Entity Framework Core async queries like ToListAsync, FirstOrDefaultAsync, and more using popular mocking libraries such as Moq, NSubstitute, and FakeItEasy — all without hitting the database.
❤️ If you really like the tool, please 👉 Support the project or ☕ Buy me a coffee.
📦 NuGet Packages: 
✅ Build & Status
⭐ GitHub Stats
💡 Why Use MockQueryable?
Avoid hitting the real database in unit tests when querying via IQueryable:
var query = _userRepository.GetQueryable();
await query.AnyAsync(x => ...);
await query.FirstOrDefaultAsync(x => ...);
await query.ToListAsync();
// etc.
How It Works
MockQueryable creates a custom implementation of:
IQueryable<T>IAsyncEnumerable<T>IAsyncQueryProvider
allowing EF Core async extensions to execute against in-memory collections.
👷🏻See Architecture.
🚀 Getting Started
1. Create Test Data
var users = new List<UserEntity>
{
new UserEntity { LastName = "Smith", DateOfBirth = new DateTime(2012, 1, 20) },
// More test data...
};
2. Build the Mock
var mock = users.BuildMock(); // for IQueryable
3. Set Up in Your favorite Mocking Framework
Moq
_userRepository.Setup(x => x.GetQueryable()).Returns(mock);
NSubstitute
_userRepository.GetQueryable().Returns(mock);
FakeItEasy
A.CallTo(() => userRepository.GetQueryable()).Returns(mock);
🗃️ Mocking DbSet<T>
var mockDbSet = users.BuildMockDbSet();
// Moq
var repo = new TestDbSetRepository(mockDbSet.Object);
// NSubstitute / FakeItEasy
var repo = new TestDbSetRepository(mockDbSet);
🔧 Adding Custom Logic
Example: Custom FindAsync
mock.Setup(x => x.FindAsync(userId)).ReturnsAsync((object[] ids) =>
{
var id = (Guid)ids[0];
return users.FirstOrDefault(x => x.Id == id);
});
Example: Custom Expression Visitor
Build a mock with the custom SampleLikeExpressionVisitor for testing EF.Functions.Like
var mockDbSet = users.BuildMockDbSet<UserEntity, SampleLikeExpressionVisitor>();
🧩 Extend for Other Frameworks
You can even create your own extensions. Check the example here.
🔍 Sample Project
See the sample project for working examples.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- MockQueryable.EntityFrameworkCore (>= 10.0.13)
- NSubstitute (>= 6.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (4)
Showing the top 4 popular GitHub repositories that depend on MockQueryable.NSubstitute:
| Repository | Stars |
|---|---|
|
nuyonu/N-Tier-Architecture
This is a n-layer architecture based on Common web application architectures.
|
|
|
kaybi-gh/K7
Self-hosted media server for a small circle of family and friends.
|
|
|
alex289/CleanArchitecture
Sample .NET 10 API project including Clean Architecture principles, Onion Architecture, MediatR, and Entity Framework with unit and integration tests using xUnit
|
|
|
suxrobGM/logistics-app
AI-powered fleet management platform with an agentic dispatcher that matches loads to trucks, ensures HOS compliance, and optimizes routes. Built for trucking companies.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.13 | 614 | 10/19/2026 |
| 10.0.12 | 79,015 | 9/13/2026 |
| 10.0.8 | 366,295 | 5/16/2026 |
| 10.0.5 | 387,290 | 3/15/2026 |
| 10.0.2 | 207,910 | 1/29/2026 |
| 10.0.1 | 140,110 | 11/22/2025 |
| 10.0.0 | 6,150 | 11/22/2025 |
| 9.0.0 | 187,820 | 10/6/2025 |
| 8.0.1 | 141,719 | 10/6/2025 |
| 8.0.0 | 314,054 | 7/27/2025 |
| 7.0.4-beta | 64,793 | 9/24/2024 |
| 7.0.3 | 2,263,744 | 9/2/2024 |
| 7.0.2 | 73,918 | 8/20/2024 |
| 7.0.1 | 1,046,621 | 3/7/2024 |
| 7.0.0 | 1,162,270 | 11/21/2022 |
| 6.0.1 | 975,273 | 3/28/2022 |
| 6.0.0 | 139,080 | 3/24/2022 |
| 5.0.2 | 92,729 | 3/24/2022 |
| 5.0.1 | 498,639 | 5/25/2021 |
| 5.0.0 | 171,429 | 11/12/2020 |
Bump Microsoft.NET.Test.Sdk from 18.10.0 to 18.10.1 in #159
Bump coverlet.msbuild from 10.0.1 to 10.1.0 in #161
Bump NUnit3TestAdapter from 6.3.0 to 6.3.1 in #163
Bump Microsoft.NET.Test.Sdk from 18.10.1 to 18.11.0 in #165
Bump Moq from 4.20.72 to 4.21.0 in #160
Bump Microsoft.EntityFrameworkCore from 10.0.12 to 10.0.13 in #164