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.
1

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