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.

.NET Framework 4.6.2

.NET Standard 2.0

.NET Standard 2.1

.NET 6.0

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