Moq: Mocking library for .NET using LINQ
Mock .NET objects using lambda expressions and LINQ.
Learn more about Moq
Moq is a mocking library built for .NET that leverages LINQ expression trees and lambda expressions as its core mechanism for defining mock behavior. The library provides two primary APIs: a traditional Setup/Verify pattern and a LINQ-based Mock.Of approach that allows inline mock configuration. It generates mock implementations at runtime without requiring record/replay workflows or proxy generation frameworks. Moq is commonly used in unit testing to isolate dependencies and verify method interactions.
LINQ-Based Mock Configuration
Define mock behavior using lambda expressions and LINQ syntax directly in test code. Eliminates separate configuration steps by embedding setup and verification inline with test logic.
Setup/Verify Pattern
Configure expectations before or after method calls without record/replay workflows. Simplifies test structure by decoupling mock definition from execution order.
Runtime Mock Generation
Creates mock implementations at runtime without code generation or separate files. Define mock behavior inline with tests using fluent API, keeping test logic colocated and readable.
using Moq;
using Xunit;
var mockRepository = new Mock<IUserRepository>();
mockRepository.Setup(repo => repo.GetUserById(42))
.Returns(new User { Id = 42, Name = "John Doe" });
var user = mockRepository.Object.GetUserById(42);
Assert.Equal("John Doe", user.Name);Top in Developer Tools
Related Repositories
Discover similar tools and frameworks used by developers
gogcli
Command-line interface for Gmail, Calendar, Drive, Contacts, and other Google services with JSON output.
Floki
Elixir HTML parser with CSS selectors and multiple parser backends.
n
A command-line utility for installing, switching between, and managing multiple Node.js versions on Unix-like systems.
Colima
Lima-based container runtime provisioning for macOS and Linux.
Dear ImGui
Immediate mode GUI library for 3D applications.
Related Reading
Guides and comparisons from the Greptile content library
What is agentic coding? Benefits, risks, and best tools to consider
What engineering leaders need to know about agentic coding: how it differs from AI coding and vibe coding, how it works, the benefits and risks, and the tools worth evaluating.
Greptile Ranks #1 on Martian's AI Code Review Benchmark
Greptile ranks #1 on Martian's independent online AI code review benchmark, leading all evaluated tools in F1 score and precision with near-leading recall.
Best Developer Productivity Tools in 2026
The best developer productivity tools in 2026, compared by the workflow problem they solve: code review, autocomplete, AI-native editing, terminal agents, code search, observability, and security.
How to ACTUALLY Think About Code Reviews: The 3-Layer Checklist
A code review checklist and best practices organized around three layers — Mechanical, Structural, and Narrative — that help any team improve code quality without slowing reviews down.