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 18 09/07/2024
4.20.71 1 03/02/2025
4.20.70 18 11/30/2023
4.20.69 19 09/08/2023
4.18.4 43 05/11/2023
4.18.3 42 05/21/2023
4.18.2 1,084 08/24/2022
4.18.1 20 06/27/2022
4.18.0 29 08/22/2022
4.17.2 76 09/08/2022
4.17.1 67 09/10/2022
4.16.1 2,551 06/27/2022
4.16.0 29 09/02/2022
4.15.2 68 09/09/2022
4.15.1 101 08/23/2022
4.14.7 26 09/08/2022
4.14.6 30 09/07/2022
4.14.5 96 09/08/2022
4.14.4 48 09/09/2022
4.14.3 26 09/10/2022
4.14.2 86 08/23/2022
4.14.1 44 09/08/2022
4.14.0 57 09/08/2022
4.13.1 107 09/08/2022
4.13.0 73 09/08/2022
4.12.0 74 09/08/2022
4.11.0 44 09/03/2022
4.11.0-rc2 64 09/07/2022
4.11.0-rc1 16 09/04/2022
4.10.1 70 09/08/2022
4.10.0 84 09/09/2022
4.9.0 41 09/08/2022
4.8.3 89 09/04/2022
4.8.2 33 09/09/2022
4.8.1 56 08/25/2022
4.8.0 28 09/09/2022
4.8.0-rc1 59 09/07/2022
4.7.145 34 09/02/2022
4.7.142 37 09/07/2022
4.7.137 38 09/07/2022
4.7.127 62 09/09/2022
4.7.99 60 08/21/2022
4.7.63 54 09/07/2022
4.7.58 20 09/07/2022
4.7.49 70 09/09/2022
4.7.46 90 09/08/2022
4.7.25 95 09/08/2022
4.7.12 91 09/07/2022
4.7.11 106 09/08/2022
4.7.10 43 09/07/2022
4.7.9 17 09/08/2022
4.7.8 54 08/22/2022
4.7.7 36 09/09/2022
4.7.1 62 09/07/2022
4.7.0 53 09/09/2022
4.6.62-alpha 35 09/08/2022
4.6.39-alpha 32 09/11/2022
4.6.38-alpha 15 09/04/2022
4.6.36-alpha 88 09/08/2022
4.6.25-alpha 19 09/07/2022
4.5.30 47 09/03/2022
4.5.29 35 08/21/2022
4.5.28 19 09/04/2022
4.5.23 38 09/09/2022
4.5.22 66 09/08/2022
4.5.21 68 09/03/2022
4.5.20 20 09/02/2022
4.5.19 39 09/07/2022
4.5.18 63 09/08/2022
4.5.16 49 09/08/2022
4.5.13 91 09/08/2022
4.5.10 40 09/03/2022
4.5.9 39 09/08/2022
4.5.9-alpha 74 09/08/2022
4.5.8 84 09/09/2022
4.5.7 59 09/07/2022
4.5.7-alpha 28 08/23/2022
4.5.6-alpha 25 09/08/2022
4.5.3 73 09/08/2022
4.5.0 33 09/09/2022
4.2.1510.2205 56 09/03/2022
4.2.1507.118 128 09/02/2022
4.2.1506.2515 38 09/08/2022
4.2.1506.2016 33 09/08/2022
4.2.1502.911 25 09/09/2022
4.2.1409.1722 72 09/08/2022
4.2.1408.717 71 08/24/2022
4.2.1408.619 33 09/08/2022
4.2.1402.2112 21 09/03/2022
4.2.1312.1622 97 09/09/2022
4.2.1312.1621 93 09/10/2022
4.2.1312.1615 42 09/07/2022
4.2.1312.1416 94 09/05/2022
4.2.1312.1323 35 08/21/2022
4.2.1312.1319 70 09/03/2022
4.1.1311.615 70 08/25/2022
4.1.1309.1617 44 09/08/2022
4.1.1309.919 40 08/23/2022
4.1.1309.801 32 09/08/2022
4.1.1309.800 77 09/02/2022
4.1.1308.2321 102 09/07/2022
4.1.1308.2316 54 09/08/2022
4.1.1308.2120 29 09/03/2022
4.0.10827 43 09/03/2022
3.1.416.3 72 09/07/2022