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

Showing the top 20 packages that depend on Moq.

Packages Downloads
AWSSDK.SecretsManager.Caching
The AWS Secrets Manager .NET caching client enables in-process caching of secrets for C# applications.
11
AWSSDK.SecretsManager.Caching
The AWS Secrets Manager .NET caching client enables in-process caching of secrets for C# applications.
9

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 14 10/09/2024
4.20.70 14 09/28/2024
4.20.69 15 03/10/2024
4.18.4 12 03/18/2023
4.18.3 10 10/09/2024
4.18.2 11 10/09/2024
4.18.1 11 10/26/2022
4.18.0 11 10/09/2024
4.17.2 10 10/09/2024
4.17.1 10 11/27/2024
4.16.1 36 02/04/2022
4.16.0 11 10/09/2024
4.15.2 11 02/06/2022
4.15.1 10 10/09/2024
4.14.7 10 10/09/2024
4.14.6 10 10/09/2024
4.14.5 12 05/17/2023
4.14.4 10 11/27/2024
4.14.3 10 10/09/2024
4.14.2 11 11/27/2024
4.14.1 9 11/27/2024
4.14.0 10 10/09/2024
4.13.1 9 11/27/2024
4.13.0 11 10/09/2024
4.12.0 10 10/09/2024
4.11.0 10 10/09/2024
4.11.0-rc2 11 10/09/2024
4.11.0-rc1 10 10/09/2024
4.10.1 12 02/02/2022
4.10.0 10 10/09/2024
4.9.0 10 10/09/2024
4.8.3 11 10/09/2024
4.8.2 11 12/10/2021
4.8.1 10 10/09/2024
4.8.0 11 10/09/2024
4.8.0-rc1 10 10/09/2024
4.7.145 9 11/27/2024
4.7.142 11 10/09/2024
4.7.137 9 10/09/2024
4.7.127 10 10/09/2024
4.7.99 10 10/09/2024
4.7.63 9 10/09/2024
4.7.58 12 10/09/2024
4.7.49 11 10/09/2024
4.7.46 10 10/09/2024
4.7.25 10 11/27/2024
4.7.12 9 10/09/2024
4.7.11 10 10/09/2024
4.7.10 10 10/09/2024
4.7.9 10 10/09/2024
4.7.8 11 10/09/2024
4.7.7 9 10/09/2024
4.7.1 11 10/09/2024
4.7.0 11 10/09/2024
4.6.62-alpha 9 10/09/2024
4.6.39-alpha 11 10/09/2024
4.6.38-alpha 11 10/14/2024
4.6.36-alpha 7 10/09/2024
4.6.25-alpha 10 10/13/2024
4.5.30 11 10/09/2024
4.5.29 10 10/09/2024
4.5.28 9 11/27/2024
4.5.23 11 10/09/2024
4.5.22 11 10/09/2024
4.5.21 10 10/09/2024
4.5.20 10 10/09/2024
4.5.19 10 10/09/2024
4.5.18 11 10/09/2024
4.5.16 12 10/09/2024
4.5.13 10 10/09/2024
4.5.10 11 10/09/2024
4.5.9 10 10/09/2024
4.5.9-alpha 12 10/09/2024
4.5.8 12 10/09/2024
4.5.7 11 10/09/2024
4.5.7-alpha 11 11/27/2024
4.5.6-alpha 11 10/09/2024
4.5.3 10 10/09/2024
4.5.0 9 11/30/2024
4.2.1510.2205 10 10/09/2024
4.2.1507.118 9 11/27/2024
4.2.1506.2515 12 10/09/2024
4.2.1506.2016 12 10/09/2024
4.2.1502.911 10 10/09/2024
4.2.1409.1722 10 10/09/2024
4.2.1408.717 10 10/09/2024
4.2.1408.619 8 10/09/2024
4.2.1402.2112 8 10/09/2024
4.2.1312.1622 10 10/09/2024
4.2.1312.1621 9 11/27/2024
4.2.1312.1615 10 10/09/2024
4.2.1312.1416 10 10/09/2024
4.2.1312.1323 11 10/09/2024
4.2.1312.1319 9 10/09/2024
4.1.1311.615 10 10/09/2024
4.1.1309.1617 11 10/09/2024
4.1.1309.919 11 10/09/2024
4.1.1309.801 7 11/27/2024
4.1.1309.800 9 10/09/2024
4.1.1308.2321 10 10/09/2024
4.1.1308.2316 10 10/09/2024
4.1.1308.2120 10 10/09/2024
4.0.10827 10 10/09/2024
3.1.416.3 10 10/09/2024