Moq 4.20.69

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 C. Augusto Proiete Kirill Osenkov MFB Technologies, Inc. Stephen Shaw Torutek DRIVE.NET, Inc. David Kean Daniel Gnägi Ashley Medway Keith Pickford bitbonk Thomas Bolon Yurii Rashkovskii Kori Francis Zdenek Havlin Sean Killeen Toni Wenzel Giorgi Dalakishvili Kelly White Allan Ritchie Mike James Uno Platform Dan Siegel Reuben Swartz Jeremy Simmons Jacob Foshee Eric Johnson Norman Mackay Certify The Web Taylor Mansfield Mårten Rånge David Petric Rich Lee Danilo Dantas Gary Woodfine Steve Bilogan Ix Technologies B.V. New Relic Chris Johnston‮ David JENNI Jonathan Oleg Kyrylchuk Juan Blanco LosManos Mariusz Kogut Charley Wu Thomas Due Jakob Tikjøb Andersen

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.
19
AWSSDK.SecretsManager.Caching
The AWS Secrets Manager .NET caching client enables in-process caching of secrets for C# applications.
15

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