MockQueryable.Moq
10.0.5
dotnet add package MockQueryable.Moq --version 10.0.5
NuGet\Install-Package MockQueryable.Moq -Version 10.0.5
<PackageReference Include="MockQueryable.Moq" Version="10.0.5" />
<PackageVersion Include="MockQueryable.Moq" Version="10.0.5" />
<PackageReference Include="MockQueryable.Moq" />
paket add MockQueryable.Moq --version 10.0.5
#r "nuget: MockQueryable.Moq, 10.0.5"
#:package MockQueryable.Moq@10.0.5
#addin nuget:?package=MockQueryable.Moq&version=10.0.5
#tool nuget:?package=MockQueryable.Moq&version=10.0.5
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.
🚀 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.5)
- Moq (>= 4.20.72)
NuGet packages (9)
Showing the top 5 NuGet packages that depend on MockQueryable.Moq:
| Package | Downloads |
|---|---|
|
Zeesfam.NetLib
Package Description |
|
|
Franz.Common.Testing
Shared utility library for the Franz Framework. |
|
|
Simpository
A simple database repository library |
|
|
VG.Infrastructure.EntityFramework.UnitTest
Package Description |
|
|
TestAssist
Essential utilities and helpers for streamlined unit testing in C# |
GitHub repositories (11)
Showing the top 11 popular GitHub repositories that depend on MockQueryable.Moq:
| Repository | Stars |
|---|---|
|
simplcommerce/SimplCommerce
A simple, cross platform, modulith ecommerce system built on .NET
|
|
|
Ombi-app/Ombi
Want a Movie or TV Show on Plex/Emby/Jellyfin? Use Ombi!
|
|
|
VirtoCommerce/vc-platform
Virto Commerce B2B Innovation Platform
|
|
|
CodeMazeBlog/CodeMazeGuides
The main repository for all the Code Maze guides
|
|
|
lkurzyniec/netcore-boilerplate
Boilerplate of API in .NET 10
|
|
|
Librum-Reader/Librum-Server
The Librum server
|
|
|
carlreid/StreamMaster
A powerful M3U proxy and stream management platform for Plex DVR, Emby, Jellyfin Live TV (and more)
|
|
|
Letterbook/Letterbook
Sustainable federated social media built for open correspondence
|
|
|
SapiensAnatis/Dawnshard
Server emulator for Dragalia Lost
|
|
|
matt-bentley/CleanArchitecture
An opinionated ASP.NET Core solution setup for creating web applications using Clean Architecture and Domain-Driven Design principles.
|
|
|
microsoftgraph/group-membership-management
Group Membership Management (GMM) is a service that dynamically manages the membership of AAD Groups. Groups managed by GMM can have their membership defined using existing AAD Groups and/or custom membership sources.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.5 | 39,856 | 3/15/2026 |
| 10.0.2 | 176,354 | 1/29/2026 |
| 10.0.1 | 203,327 | 11/22/2025 |
| 10.0.0 | 3,350 | 11/22/2025 |
| 9.0.0 | 287,514 | 10/6/2025 |
| 8.0.1 | 283,539 | 10/6/2025 |
| 8.0.0 | 423,852 | 7/27/2025 |
| 7.0.4-beta | 131,918 | 9/24/2024 |
| 7.0.3 | 6,414,031 | 9/2/2024 |
| 7.0.2 | 217,001 | 8/20/2024 |
| 7.0.1 | 2,616,152 | 3/7/2024 |
| 7.0.0 | 4,585,039 | 11/21/2022 |
| 6.0.1 | 4,944,042 | 3/28/2022 |
| 6.0.0 | 246,883 | 3/24/2022 |
| 5.0.2 | 321,210 | 3/24/2022 |
| 5.0.1 | 2,755,945 | 5/25/2021 |
| 5.0.0 | 1,285,316 | 11/12/2020 |
| 5.0.0-preview.7 | 33,671 | 7/28/2020 |
| 3.1.3 | 2,333,917 | 5/19/2020 |
| 3.1.2 | 148,935 | 4/17/2020 |
#107 Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.Relational v 10.0.5 - supported
#113 AutoMapper to 16.1.1
#105 FakeItEasy to 9.0.1