Navigate:
~$MOQ0.0%

Moq: Mocking library for .NET using LINQ

Mock .NET objects using lambda expressions and LINQ.

LIVE RANKINGS • 06:52 AM • STEADY
OVERALL
#255
3
DEVELOPER TOOLS
#53
1
30 DAY RANKING TREND
ovr#255
·Devel#53
STARS
6.3K
FORKS
840
DOWNLOADS
4
7D STARS
+1
7D FORKS
0
See Repo:
Share:

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.


1

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.

2

Setup/Verify Pattern

Configure expectations before or after method calls without record/replay workflows. Simplifies test structure by decoupling mock definition from execution order.

3

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);


vv4.20.72

Maintenance release removing an unused internal attribute; no functional changes or breaking updates.

  • Release notes do not specify any breaking changes, new requirements, or migration steps.
  • Internal cleanup only; no action required for consumers upgrading from v4.20.71.
vv4.20.71

Maintenance release with license metadata update and test fixes; no breaking changes or new features.

  • Update License.txt to SPDX identifier for automatic tooling recognition.
  • Add Verify overload and fix semantic test error in MatchersFixture; no API impact.
vv4.20.70

Maintenance release with performance improvements for interface mocking and privacy compliance fixes; no breaking changes or new requirements.

  • Expect faster interface mock creation due to cached GetInterfaceMap lookups.
  • GDPR compliance restored; review telemetry settings if privacy policies apply to your project.


[ EXPLORE MORE ]

Related Repositories

Discover similar tools and frameworks used by developers