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 38 09/07/2024
4.20.71 25 03/02/2025
4.20.70 32 11/30/2023
4.20.69 50 09/08/2023
4.18.4 54 05/11/2023
4.18.3 55 05/21/2023
4.18.2 1,096 08/24/2022
4.18.1 38 06/27/2022
4.18.0 46 08/22/2022
4.17.2 89 09/08/2022
4.17.1 79 09/10/2022
4.16.1 2,562 06/27/2022
4.16.0 43 09/02/2022
4.15.2 82 09/09/2022
4.15.1 116 08/23/2022
4.14.7 39 09/08/2022
4.14.6 52 09/07/2022
4.14.5 115 09/08/2022
4.14.4 62 09/09/2022
4.14.3 39 09/10/2022
4.14.2 99 08/23/2022
4.14.1 58 09/08/2022
4.14.0 68 09/08/2022
4.13.1 120 09/08/2022
4.13.0 87 09/08/2022
4.12.0 86 09/08/2022
4.11.0 56 09/03/2022
4.11.0-rc2 79 09/07/2022
4.11.0-rc1 32 09/04/2022
4.10.1 87 09/08/2022
4.10.0 99 09/09/2022
4.9.0 55 09/08/2022
4.8.3 102 09/04/2022
4.8.2 45 09/09/2022
4.8.1 67 08/25/2022
4.8.0 43 09/09/2022
4.8.0-rc1 71 09/07/2022
4.7.145 44 09/02/2022
4.7.142 49 09/07/2022
4.7.137 48 09/07/2022
4.7.127 79 09/09/2022
4.7.99 74 08/21/2022
4.7.63 66 09/07/2022
4.7.58 32 09/07/2022
4.7.49 79 09/09/2022
4.7.46 105 09/08/2022
4.7.25 117 09/08/2022
4.7.12 107 09/07/2022
4.7.11 117 09/08/2022
4.7.10 59 09/07/2022
4.7.9 39 09/08/2022
4.7.8 64 08/22/2022
4.7.7 46 09/09/2022
4.7.1 78 09/07/2022
4.7.0 68 09/09/2022
4.6.62-alpha 46 09/08/2022
4.6.39-alpha 43 09/11/2022
4.6.38-alpha 38 09/04/2022
4.6.36-alpha 106 09/08/2022
4.6.25-alpha 31 09/07/2022
4.5.30 58 09/03/2022
4.5.29 51 08/21/2022
4.5.28 34 09/04/2022
4.5.23 52 09/09/2022
4.5.22 80 09/08/2022
4.5.21 83 09/03/2022
4.5.20 37 09/02/2022
4.5.19 50 09/07/2022
4.5.18 77 09/08/2022
4.5.16 62 09/08/2022
4.5.13 106 09/08/2022
4.5.10 57 09/03/2022
4.5.9 48 09/08/2022
4.5.9-alpha 85 09/08/2022
4.5.8 98 09/09/2022
4.5.7 71 09/07/2022
4.5.7-alpha 42 08/23/2022
4.5.6-alpha 38 09/08/2022
4.5.3 86 09/08/2022
4.5.0 46 09/09/2022
4.2.1510.2205 69 09/03/2022
4.2.1507.118 160 09/02/2022
4.2.1506.2515 49 09/08/2022
4.2.1506.2016 44 09/08/2022
4.2.1502.911 37 09/09/2022
4.2.1409.1722 89 09/08/2022
4.2.1408.717 85 08/24/2022
4.2.1408.619 47 09/08/2022
4.2.1402.2112 36 09/03/2022
4.2.1312.1622 110 09/09/2022
4.2.1312.1621 113 09/10/2022
4.2.1312.1615 54 09/07/2022
4.2.1312.1416 107 09/05/2022
4.2.1312.1323 47 08/21/2022
4.2.1312.1319 81 09/03/2022
4.1.1311.615 84 08/25/2022
4.1.1309.1617 60 09/08/2022
4.1.1309.919 53 08/23/2022
4.1.1309.801 45 09/08/2022
4.1.1309.800 89 09/02/2022
4.1.1308.2321 113 09/07/2022
4.1.1308.2316 66 09/08/2022
4.1.1308.2120 40 09/03/2022
4.0.10827 56 09/03/2022
3.1.416.3 89 09/07/2022