Moq 4.20.72

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 Kirill Osenkov MFB Technologies, Inc. Stephen Shaw Torutek DRIVE.NET, Inc. Ashley Medway Keith Pickford Thomas Bolon Kori Francis Toni Wenzel Giorgi Dalakishvili Uno Platform Dan Siegel Reuben Swartz Jacob Foshee Eric Johnson Ix Technologies B.V. David JENNI Jonathan Oleg Kyrylchuk Charley Wu Jakob Tikjøb Andersen Seann Alexander Tino Hager Mark Seemann Ken Bonny Simon Cropp agileworks-eu sorahex Zheyu Shen Vezel ChilliCream 4OTC Vincent Limo Brooke Hamilton

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.20.72 52 08/10/2025
4.20.70 40 08/10/2025
4.20.69 37 08/10/2025
4.18.4 37 07/11/2025
4.18.3 41 08/10/2025
4.18.2 35 08/10/2025
4.18.1 38 08/10/2025
4.18.0 42 08/10/2025
4.17.2 43 08/10/2025
4.17.1 38 08/10/2025
4.16.1 35 07/09/2025
4.16.0 33 08/10/2025
4.15.2 35 08/10/2025
4.15.1 33 08/10/2025
4.14.7 42 08/10/2025
4.14.6 39 08/10/2025
4.14.5 33 08/10/2025
4.14.4 36 08/10/2025
4.14.3 37 08/10/2025
4.14.2 36 08/10/2025
4.14.1 33 08/10/2025
4.14.0 40 08/10/2025
4.13.1 32 08/10/2025
4.13.0 38 08/10/2025
4.12.0 37 08/10/2025
4.11.0 37 08/10/2025
4.11.0-rc2 30 08/10/2025
4.11.0-rc1 46 08/09/2025
4.10.1 44 08/10/2025
4.10.0 33 08/10/2025
4.8.0-rc1 38 08/11/2025
4.7.145 34 08/10/2025
4.7.142 32 08/10/2025
4.7.137 38 08/10/2025
4.7.127 36 08/10/2025
4.7.99 31 08/10/2025
4.7.63 35 08/10/2025
4.7.58 41 08/10/2025
4.7.49 33 08/10/2025
4.7.46 40 08/10/2025
4.7.25 36 08/10/2025
4.7.12 32 08/10/2025
4.7.11 34 08/10/2025
4.7.10 41 08/10/2025
4.6.62-alpha 37 08/10/2025
4.6.39-alpha 41 08/09/2025
4.6.38-alpha 40 08/10/2025
4.6.36-alpha 35 08/10/2025
4.6.25-alpha 32 08/10/2025
4.5.30 37 08/10/2025
4.5.29 36 08/10/2025
4.5.28 43 08/10/2025
4.5.23 36 08/10/2025
4.5.22 37 08/10/2025
4.5.21 40 08/10/2025
4.5.20 33 08/10/2025
4.5.19 35 08/10/2025
4.5.18 38 08/10/2025
4.5.16 41 08/10/2025
4.5.13 36 08/10/2025
4.5.10 46 08/10/2025
4.5.9-alpha 41 08/11/2025
4.5.7-alpha 40 08/11/2025
4.5.6-alpha 37 08/11/2025
4.2.1510.2205 37 08/09/2025
4.2.1507.118 33 08/10/2025
4.2.1506.2515 31 08/09/2025
4.2.1506.2016 41 08/09/2025
4.2.1502.911 35 08/10/2025
4.2.1409.1722 34 08/09/2025
4.2.1408.717 37 08/10/2025
4.2.1408.619 32 08/10/2025
4.2.1402.2112 37 08/09/2025
4.2.1312.1622 37 08/10/2025
4.2.1312.1621 35 08/10/2025
4.2.1312.1615 36 08/10/2025
4.2.1312.1416 35 08/10/2025
4.2.1312.1323 40 08/09/2025
4.2.1312.1319 41 08/09/2025
4.1.1311.615 35 08/10/2025
4.1.1309.1617 39 08/09/2025
4.1.1309.919 37 08/10/2025
4.1.1309.801 35 08/10/2025
4.1.1309.800 33 08/10/2025
4.1.1308.2321 35 08/09/2025
4.1.1308.2316 36 08/09/2025
4.1.1308.2120 35 08/09/2025
4.0.10827 45 08/09/2025
3.1.416.3 35 08/10/2025