MockQueryable.NSubstitute
11.0.0
dotnet add package MockQueryable.NSubstitute --version 11.0.0
NuGet\Install-Package MockQueryable.NSubstitute -Version 11.0.0
<PackageReference Include="MockQueryable.NSubstitute" Version="11.0.0" />
<PackageVersion Include="MockQueryable.NSubstitute" Version="11.0.0" />
<PackageReference Include="MockQueryable.NSubstitute" />
paket add MockQueryable.NSubstitute --version 11.0.0
#r "nuget: MockQueryable.NSubstitute, 11.0.0"
#:package MockQueryable.NSubstitute@11.0.0
#addin nuget:?package=MockQueryable.NSubstitute&version=11.0.0
#tool nuget:?package=MockQueryable.NSubstitute&version=11.0.0
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 | net11.0 is compatible. |
-
net11.0
- MockQueryable.EntityFrameworkCore (>= 11.0.0)
- 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 |
|---|---|---|
| 11.0.0 | 0 | 11/11/2026 |
| 10.0.13 | 46,482 | 10/19/2026 |
| 10.0.12 | 113,639 | 9/13/2026 |
| 10.0.8 | 407,709 | 5/16/2026 |
| 10.0.5 | 596,777 | 3/15/2026 |
| 10.0.2 | 221,219 | 1/29/2026 |
| 10.0.1 | 143,730 | 11/22/2025 |
| 10.0.0 | 6,878 | 11/22/2025 |
| 9.0.0 | 193,940 | 10/6/2025 |
| 8.0.1 | 148,924 | 10/6/2025 |
| 8.0.0 | 340,245 | 7/27/2025 |
| 7.0.4-beta | 66,961 | 9/24/2024 |
| 7.0.3 | 2,340,342 | 9/2/2024 |
| 7.0.2 | 74,634 | 8/20/2024 |
| 7.0.1 | 1,075,727 | 3/7/2024 |
| 7.0.0 | 1,201,929 | 11/21/2022 |
| 6.0.1 | 999,479 | 3/28/2022 |
| 6.0.0 | 139,385 | 3/24/2022 |
| 5.0.2 | 94,925 | 3/24/2022 |
| 5.0.1 | 500,645 | 5/25/2021 |
Support .NET 11 and Entity Framework Core 11; update dependencies to current stable versions.