Moq 4.21.0

The most popular and friendly mocking library for .NET

  var mock = new Mock<ILoveThisLibrary>();

  // WOW! No record/replay weirdness?! :)
  mock.Setup(library => library.DownloadExists("2.0.0.0"))
      .Returns(true);

  // Use the Object property on the mock to get a reference to the object
  // implementing ILoveThisLibrary, and then exercise it by calling
  // methods on it
  ILoveThisLibrary lovable = mock.Object;
  bool download = lovable.DownloadExists("2.0.0.0");

  // Verify that the given method was indeed called with the expected value at most once
  mock.Verify(library => library.DownloadExists("2.0.0.0"), Times.AtMostOnce());

Moq also is the first and only library so far to provide Linq to Mocks, so that the same behavior above can be achieved much more succinctly:

  ILoveThisLibrary lovable = Mock.Of<ILoveThisLibrary>(l =>
    l.DownloadExists("2.0.0.0") == true);

  // Exercise the instance returned by Mock.Of by calling methods on it...
  bool download = lovable.DownloadExists("2.0.0.0");

  // Simply assert the returned state:
  Assert.True(download);
  
  // If you want to go beyond state testing and want to 
  // verify the mock interaction instead...
  Mock.Get(lovable).Verify(library => library.DownloadExists("2.0.0.0"));

You can think of Linq to Mocks as "from the universe of mocks, give me one whose behavior matches this expression".

Check out the Quickstart for more examples!

Sponsors

Clarius Org MFB Technologies, Inc. SandRock DRIVE.NET, Inc. Keith Pickford Thomas Bolon Reuben Swartz Jacob Foshee Eric Johnson Jonathan Ken Bonny Simon Cropp agileworks-eu Zheyu Shen Vezel ChilliCream 4OTC domischell Adrian Alonso torutek Ryan McCaffery Seika Logiciel Andrew Grant eska-gmbh Geodata AS

Sponsor this project

Learn more about GitHub Sponsors

No packages depend on Moq.

https://github.com/moq/moq/blob/main/changelog.md

.NET Framework 4.6.2

.NET Standard 2.0

.NET Standard 2.1

.NET 6.0

Version Downloads Last updated
4.21.0 8 09/25/2026
4.20.72 2 12/15/2025
4.20.71 2 12/16/2025
4.20.70 1 12/15/2025
4.20.69 2 12/16/2025
4.18.4 10 12/17/2025
4.18.3 10 12/17/2025
4.18.2 12 12/17/2025
4.18.1 12 12/17/2025
4.18.0 11 12/17/2025
4.17.2 9 12/17/2025
4.17.1 10 12/17/2025
4.16.1 10 12/17/2025
4.16.0 12 12/17/2025
4.15.2 12 12/17/2025
4.15.1 9 12/17/2025
4.14.7 12 12/17/2025
4.14.6 11 12/17/2025
4.14.5 10 12/17/2025
4.14.4 8 12/17/2025
4.14.3 12 12/17/2025
4.14.2 10 12/17/2025
4.14.1 9 12/17/2025
4.14.0 10 12/17/2025
4.13.1 10 12/17/2025
4.13.0 10 12/17/2025
4.12.0 10 12/17/2025
4.11.0 11 12/17/2025
4.11.0-rc2 8 12/17/2025
4.11.0-rc1 10 12/17/2025
4.10.1 9 12/17/2025
4.10.0 13 01/22/2026
4.9.0 8 12/17/2025
4.8.3 10 12/17/2025
4.8.2 9 12/17/2025
4.8.1 7 12/17/2025
4.8.0 243 12/10/2025
4.8.0-rc1 9 12/17/2025
4.7.145 13 12/15/2025
4.7.142 11 12/15/2025
4.7.137 12 12/15/2025
4.7.127 9 12/15/2025
4.7.99 10 12/17/2025
4.7.63 9 12/17/2025
4.7.58 12 01/22/2026
4.7.49 8 12/17/2025
4.7.46 10 12/17/2025
4.7.25 11 12/17/2025
4.7.12 8 12/17/2025
4.7.11 10 12/17/2025
4.7.10 11 12/17/2025
4.7.9 8 12/17/2025
4.7.8 8 12/17/2025
4.7.7 8 12/17/2025
4.7.1 7 12/17/2025
4.7.0 10 12/17/2025
4.6.62-alpha 8 12/17/2025
4.6.39-alpha 8 12/17/2025
4.6.38-alpha 10 12/17/2025
4.6.36-alpha 8 12/17/2025
4.6.25-alpha 9 12/17/2025
4.5.30 9 12/17/2025
4.5.29 9 12/17/2025
4.5.28 10 12/17/2025
4.5.23 9 12/17/2025
4.5.22 8 12/17/2025
4.5.21 6 12/17/2025
4.5.20 10 12/17/2025
4.5.19 10 12/17/2025
4.5.18 10 12/17/2025
4.5.16 10 12/17/2025
4.5.13 14 12/17/2025
4.5.10 12 12/17/2025
4.5.9 5 12/17/2025
4.5.9-alpha 8 12/17/2025
4.5.8 8 12/17/2025
4.5.7 8 12/17/2025
4.5.7-alpha 7 12/17/2025
4.5.6-alpha 9 12/17/2025
4.5.3 10 12/17/2025
4.5.0 8 12/17/2025
4.2.1510.2205 10 12/11/2025
4.2.1507.118 10 12/11/2025
4.2.1506.2515 13 12/11/2025
4.2.1506.2016 11 12/11/2025
4.2.1502.911 66 12/16/2025
4.2.1409.1722 10 12/11/2025
4.2.1408.717 12 12/11/2025
4.2.1408.619 8 12/11/2025
4.2.1402.2112 91 12/11/2025
4.2.1312.1622 14 12/11/2025
4.2.1312.1621 12 12/11/2025
4.2.1312.1615 12 12/11/2025
4.2.1312.1416 14 12/11/2025
4.2.1312.1323 12 12/11/2025
4.2.1312.1319 11 12/11/2025
4.1.1311.615 9 12/16/2025
4.1.1309.1617 10 12/11/2025
4.1.1309.919 188 12/16/2025
4.1.1309.801 13 12/16/2025
4.1.1309.800 11 12/16/2025
4.1.1308.2321 9 12/11/2025
4.1.1308.2316 15 12/11/2025
4.1.1308.2120 11 12/11/2025
4.0.10827 12 12/11/2025
3.1.416.3 10 12/16/2025