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