DEV.co
Open-Source Testing · ramantsitou

MockQueryable

MockQueryable is a .NET library that enables unit testing of Entity Framework Core async queries (ToListAsync, FirstOrDefaultAsync, etc.) against in-memory test data without touching a real database. It integrates with popular mocking frameworks—Moq, NSubstitute, and FakeItEasy—to simplify mock setup.

Source: GitHub — github.com/ramantsitou/MockQueryable
865
GitHub stars
82
Forks
C#
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryramantsitou/MockQueryable
Ownerramantsitou
Primary languageC#
LicenseMIT — OSI-approved
Stars865
Forks82
Open issues1
Latest releasev10.0.8 (2026-05-16)
Last updated2026-07-06
Sourcehttps://github.com/ramantsitou/MockQueryable

What MockQueryable is

MockQueryable provides custom implementations of IQueryable<T>, IAsyncEnumerable<T>, and IAsyncQueryProvider to intercept EF Core async LINQ operations on in-memory collections. It supports both IQueryable mocking and DbSet<T> mocking, with extensibility for custom expression visitors and provider logic.

Quickstart

Get the MockQueryable source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/ramantsitou/MockQueryable.gitcd MockQueryable# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Unit Testing Repository Patterns

Mock IQueryable returns from repository methods to test business logic filters, sorting, and pagination without database setup or teardown.

Testing LINQ-to-Entities Queries

Validate that complex async LINQ queries (FirstOrDefaultAsync, AnyAsync, ToListAsync) execute correctly with mocked data and the right predicate logic.

Fast CI/CD Test Suites

Eliminate database I/O latency in integration tests; run large test suites in-memory to speed up build pipelines.

Implementation considerations

  • Choose the appropriate NuGet package variant (Moq, NSubstitute, or FakeItEasy) to match your test framework; core logic is shared.
  • For custom LINQ operators or EF.Functions (e.g., LIKE, date functions), implement custom expression visitors; default behavior may not cover edge cases.
  • Ensure test data setup mirrors real-world entity state and relationships; incomplete or unrealistic mocks can mask bugs.
  • Be aware that in-memory execution may differ from SQL translation; validate critical queries against a real database in at least one integration test.

When to avoid it — and what to weigh

  • Testing Database-Specific Behavior — MockQueryable cannot replicate SQL Server, PostgreSQL, or other DB engine–specific semantics, constraints, or performance characteristics.
  • End-to-End Testing Requirements — If you need to validate actual database transactions, migrations, or schema integrity, use a real test database or containers instead.
  • Testing Custom SQL or Stored Procedures — MockQueryable handles LINQ-to-Entities only; it cannot mock raw SQL queries or stored procedure calls.
  • Non-.NET or Non-EF Core Projects — Library is C# / .NET specific; no benefit for projects using other ORMs, languages, or database access patterns.

License & commercial use

Licensed under MIT (MIT License), a permissive open-source license. Permits commercial use, modification, and distribution with minimal restrictions.

MIT license explicitly permits commercial use. No vendor lock-in or proprietary restrictions. Safe for closed-source, commercial applications. Attribute the author (Raman Tsitou) in license notices; review MIT terms to confirm compliance with your legal requirements.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationAdequate
License clarityClear
Deployment complexityLow
DEV.co fitGood
Assessment confidenceHigh
Security considerations

MockQueryable is a test utility; security depends on how test data is defined and isolated. Ensure test databases and in-memory data do not contain production secrets or credentials. No reported vulnerabilities in the data provided; review security advisories and dependencies (EF Core, mocking libs) in your supply chain.

Alternatives to consider

InMemory EF Core Provider

Microsoft's built-in in-memory database can be configured in DbContext for some unit tests; lacks async-specific mocking and does not intercept at IQueryable level.

Effort / EF6 Mock Database

Legacy in-memory provider for EF6; not recommended for EF Core projects; less active development.

Manual IQueryable Implementation

Implement custom IQueryable<T> and IAsyncQueryProvider from scratch; requires deep LINQ knowledge and is error-prone compared to using MockQueryable.

Software development agency

Build on MockQueryable with DEV.co software developers

Integrate MockQueryable into your test suite to eliminate database dependencies and run faster, isolated unit tests. Contact our team to discuss best practices for .NET testing.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

MockQueryable FAQ

Does MockQueryable require a real database?
No. It mocks IQueryable and DbSet in-memory; tests run entirely in memory without database connectivity.
Which mocking framework should I choose?
Pick the one your team already uses (Moq, NSubstitute, or FakeItEasy). MockQueryable provides extension methods for each; behavior is equivalent.
Can I test custom LINQ operators or EF.Functions?
Core LINQ (Where, Select, FirstOrDefault, etc.) is supported out-of-box. For EF.Functions.Like or custom operators, implement a custom expression visitor as shown in the sample project.
Is MockQueryable suitable for integration tests?
No; it is designed for unit tests. For integration tests that validate real database behavior, use test containers or a dedicated test database.

Software development & web development with DEV.co

DEV.co is a software development agency delivering custom software development services to companies building on open source. Our software developers and web developers design, integrate, and ship production systems — spanning web development, APIs, AI, data, and cloud. If MockQueryable is part of your open-source testing roadmap, our team can implement, customize, migrate, and maintain it.

Ready to Speed Up Your EF Core Unit Tests?

Integrate MockQueryable into your test suite to eliminate database dependencies and run faster, isolated unit tests. Contact our team to discuss best practices for .NET testing.