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 Downloads Last updated
4.20.72 61 09/07/2024
4.20.71 52 09/04/2024
4.20.70 2,920 12/06/2023
4.20.69 50 08/24/2023
4.20.2 55 08/15/2023
4.20.1 62 08/22/2023
4.20.0 55 08/22/2023
4.20.0-rc 46 08/11/2023
4.20.0-beta 47 09/30/2023
4.20.0-alpha 52 09/29/2023
4.18.4 64 01/18/2023
4.18.3 57 07/02/2023
4.18.2 56 10/26/2022
4.18.1 67 06/07/2022
4.18.0 58 07/06/2022
4.17.2 56 06/30/2023
4.17.1 63 06/29/2023
4.16.1 59 11/20/2021
4.16.0 53 07/02/2023
4.15.2 60 03/21/2021
4.15.1 54 07/24/2022
4.14.7 49 06/28/2023
4.14.6 55 04/28/2023
4.14.5 55 06/30/2023
4.14.4 56 07/05/2022
4.14.3 53 06/29/2023
4.14.2 56 11/04/2022
4.14.1 53 06/29/2023
4.14.0 56 06/28/2023
4.13.1 60 06/29/2023
4.13.0 54 07/02/2023
4.12.0 57 06/28/2023
4.11.0 52 07/01/2023
4.11.0-rc2 50 07/01/2023
4.11.0-rc1 50 07/02/2023
4.10.1 73 07/28/2022
4.10.0 68 06/28/2022
4.9.0 54 07/20/2022
4.8.3 52 07/04/2023
4.8.2 56 06/29/2023
4.8.1 54 07/01/2023
4.8.0 64 07/06/2022
4.8.0-rc1 54 07/02/2023
4.7.145 54 11/12/2022
4.7.142 55 08/08/2022
4.7.137 58 05/30/2023
4.7.127 57 06/29/2023
4.7.99 48 06/30/2023
4.7.63 47 07/04/2022
4.7.58 81 07/02/2023
4.7.49 52 06/29/2023
4.7.46 52 06/29/2023
4.7.25 58 09/10/2022
4.7.12 59 01/31/2023
4.7.11 47 06/28/2023
4.7.10 59 08/09/2022
4.7.9 54 08/26/2022
4.7.8 61 07/09/2022
4.7.7 53 06/27/2023
4.7.1 62 07/05/2022
4.7.0 72 07/02/2023
4.6.62-alpha 50 07/02/2023
4.6.39-alpha 58 08/17/2022
4.6.38-alpha 54 07/07/2022
4.6.36-alpha 57 07/07/2023
4.6.25-alpha 58 08/26/2022
4.5.30 79 07/10/2022
4.5.29 83 06/22/2022
4.5.28 72 12/21/2021
4.5.23 53 06/29/2023
4.5.22 57 09/19/2022
4.5.21 55 06/27/2022
4.5.20 52 07/02/2023
4.5.19 55 10/08/2022
4.5.18 51 06/30/2023
4.5.16 60 07/03/2022
4.5.13 48 06/30/2023
4.5.10 57 06/29/2023
4.5.9 54 08/13/2022
4.5.9-alpha 53 07/07/2023
4.5.8 60 06/27/2023
4.5.7 59 12/02/2022
4.5.7-alpha 47 07/08/2023
4.5.6-alpha 51 06/27/2023
4.5.3 55 06/29/2023
4.5.0 48 07/01/2023
4.2.1510.2205 54 08/12/2022
4.2.1507.118 57 06/27/2023
4.2.1506.2515 63 07/12/2022
4.2.1506.2016 56 07/02/2023
4.2.1502.911 57 07/03/2023
4.2.1409.1722 54 07/02/2023
4.2.1408.717 66 07/03/2023
4.2.1408.619 48 06/30/2023
4.2.1402.2112 57 08/03/2022
4.2.1312.1622 48 07/01/2023
4.2.1312.1621 53 07/02/2023
4.2.1312.1615 56 07/01/2023
4.2.1312.1416 56 08/02/2022
4.2.1312.1323 57 06/24/2022
4.2.1312.1319 51 07/08/2023
4.1.1311.615 51 07/28/2022
4.1.1309.1617 56 08/30/2022
4.1.1309.919 50 10/11/2022
4.1.1309.801 57 07/01/2023
4.1.1309.800 52 03/17/2023
4.1.1308.2321 56 08/08/2022
4.1.1308.2316 56 09/01/2022
4.1.1308.2120 60 07/02/2023
4.0.10827 84 07/03/2023
3.1.416.3 49 07/02/2023