MockQueryable.NSubstitute
10.0.1
dotnet add package MockQueryable.NSubstitute --version 10.0.1
NuGet\Install-Package MockQueryable.NSubstitute -Version 10.0.1
<PackageReference Include="MockQueryable.NSubstitute" Version="10.0.1" />
<PackageVersion Include="MockQueryable.NSubstitute" Version="10.0.1" />
<PackageReference Include="MockQueryable.NSubstitute" />
paket add MockQueryable.NSubstitute --version 10.0.1
#r "nuget: MockQueryable.NSubstitute, 10.0.1"
#:package MockQueryable.NSubstitute@10.0.1
#addin nuget:?package=MockQueryable.NSubstitute&version=10.0.1
#tool nuget:?package=MockQueryable.NSubstitute&version=10.0.1
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
| Package | Downloads | Latest Version | Install via Package Manager |
|---|---|---|---|
| MockQueryable.Core | Install-Package MockQueryable.Core |
||
| MockQueryable.EntityFrameworkCore | Install-Package MockQueryable.EntityFrameworkCore |
||
| MockQueryable.Moq | Install-Package MockQueryable.Moq |
||
| MockQueryable.NSubstitute | Install-Package MockQueryable.NSubstitute |
||
| MockQueryable.FakeItEasy | Install-Package MockQueryable.FakeItEasy |
✅ 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.
🚀 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.1)
- NSubstitute (>= 5.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (2)
Showing the top 2 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.
|
|
|
alex289/CleanArchitecture
Sample .NET 10 API project including Clean Architecture principles, Onion Architecture, MediatR, and Entity Framework with unit and integration tests using xUnit
|
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.1 | 178 | 11/22/2025 |
| 10.0.0 | 128 | 11/22/2025 |
| 9.0.0 | 41,454 | 10/6/2025 |
| 8.0.1 | 10,049 | 10/6/2025 |
| 8.0.0 | 96,879 | 7/27/2025 |
| 7.0.4-beta | 41,096 | 9/24/2024 |
| 7.0.3 | 1,209,745 | 9/2/2024 |
| 7.0.2 | 61,927 | 8/20/2024 |
| 7.0.1 | 749,542 | 3/7/2024 |
| 7.0.0 | 914,167 | 11/21/2022 |
| 6.0.1 | 713,129 | 3/28/2022 |
| 6.0.0 | 131,279 | 3/24/2022 |
| 5.0.2 | 66,680 | 3/24/2022 |
| 5.0.1 | 470,231 | 5/25/2021 |
| 5.0.0 | 143,995 | 11/12/2020 |
| 5.0.0-preview.7 | 691 | 7/28/2020 |
| 3.1.3 | 162,015 | 5/19/2020 |
| 3.1.2 | 19,763 | 4/17/2020 |
| 3.1.1 | 33,179 | 1/25/2020 |
| 3.0.2 | 5,588 | 12/20/2019 |
| 3.0.1 | 29,854 | 10/11/2019 |
| 3.0.1-alpha | 669 | 10/6/2019 |
| 3.0.0 | 1,204 | 9/30/2019 |
| 1.1.0 | 116,143 | 2/28/2019 |
| 1.0.4 | 19,778 | 1/29/2019 |
| 1.0.3 | 14,453 | 8/30/2018 |
| 1.0.2 | 6,527 | 7/6/2018 |
#93 ExecuteUpdateAsync not suported with SetProperty with Value Expression - fixed