MockQueryable.Core
8.0.1
See the version list below for details.
dotnet add package MockQueryable.Core --version 8.0.1
NuGet\Install-Package MockQueryable.Core -Version 8.0.1
<PackageReference Include="MockQueryable.Core" Version="8.0.1" />
<PackageVersion Include="MockQueryable.Core" Version="8.0.1" />
<PackageReference Include="MockQueryable.Core" />
paket add MockQueryable.Core --version 8.0.1
#r "nuget: MockQueryable.Core, 8.0.1"
#:package MockQueryable.Core@8.0.1
#addin nuget:?package=MockQueryable.Core&version=8.0.1
#tool nuget:?package=MockQueryable.Core&version=8.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 | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on MockQueryable.Core:
Package | Downloads |
---|---|
MockQueryable.EntityFrameworkCore
Core package for MockQueryable extensions for mocking operations such ToListAsync, FirstOrDefaultAsync etc. When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data. |
|
Matt.Paginated
Package Description |
|
Matt.ResultObject
Package Description |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on MockQueryable.Core:
Repository | Stars |
---|---|
CodeMazeBlog/CodeMazeGuides
The main repository for all the Code Maze guides
|
|
nuyonu/N-Tier-Architecture
This is a n-layer architecture based on Common web application architectures.
|
Version | Downloads | Last Updated |
---|---|---|
9.0.0 | 5,316 | 10/6/2025 |
8.0.1 | 2,712 | 10/6/2025 |
8.0.0 | 240,230 | 7/27/2025 |
7.0.4-beta | 132,196 | 9/24/2024 |
7.0.3 | 5,357,430 | 9/2/2024 |
7.0.2 | 244,334 | 8/20/2024 |
7.0.1 | 3,058,284 | 3/7/2024 |
7.0.0 | 5,342,033 | 11/21/2022 |
6.0.1 | 5,754,853 | 3/28/2022 |
6.0.0 | 364,380 | 3/24/2022 |
5.0.2 | 366,322 | 3/24/2022 |
5.0.1 | 3,470,223 | 5/25/2021 |
5.0.0 | 1,385,730 | 11/12/2020 |
5.0.0-preview.7 | 33,667 | 7/28/2020 |
3.1.3 | 2,412,427 | 5/19/2020 |
3.1.2 | 183,949 | 4/17/2020 |
3.1.1 | 464,012 | 1/25/2020 |
3.0.2 | 62,542 | 12/20/2019 |
3.0.1 | 80,442 | 10/11/2019 |
3.0.0 | 21,933 | 9/30/2019 |
1.1.0 | 810,936 | 2/28/2019 |
1.0.4 | 75,771 | 1/29/2019 |
1.0.3 | 330,531 | 8/30/2018 |
1.0.2 | 97,723 | 1/17/2018 |
1.0.1 | 2,677 | 12/26/2017 |
1.0.0 | 29,622 | 12/26/2017 |
#88 Fix .AsQueryable calls to the test data set - Thanks @Catlandor
#91 Move EF Dependency to v8 - Thanks @johnw86