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

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.70 6 11/30/2023
4.20.69 7 09/08/2023
4.18.4 26 05/11/2023
4.18.3 21 05/21/2023
4.18.2 978 08/24/2022
4.18.1 10 06/27/2022
4.18.0 10 08/22/2022
4.17.2 37 09/08/2022
4.17.1 38 09/10/2022
4.16.1 2,462 06/27/2022
4.16.0 14 09/02/2022
4.15.2 39 09/09/2022
4.15.1 68 08/23/2022
4.14.7 15 09/08/2022
4.14.6 17 09/07/2022
4.14.5 50 09/08/2022
4.14.4 31 09/09/2022
4.14.3 13 09/10/2022
4.14.2 53 08/23/2022
4.14.1 33 09/08/2022
4.14.0 36 09/08/2022
4.13.1 47 09/08/2022
4.13.0 46 09/08/2022
4.12.0 45 09/08/2022
4.11.0 26 09/03/2022
4.11.0-rc2 36 09/07/2022
4.11.0-rc1 9 09/04/2022
4.10.1 40 09/08/2022
4.10.0 50 09/09/2022
4.9.0 31 09/08/2022
4.8.3 53 09/04/2022
4.8.2 18 09/09/2022
4.8.1 31 08/25/2022
4.8.0 18 09/09/2022
4.8.0-rc1 29 09/07/2022
4.7.145 19 09/02/2022
4.7.142 23 09/07/2022
4.7.137 23 09/07/2022
4.7.127 33 09/09/2022
4.7.99 24 08/21/2022
4.7.63 41 09/07/2022
4.7.58 12 09/07/2022
4.7.49 39 09/09/2022
4.7.46 52 09/08/2022
4.7.25 56 09/08/2022
4.7.12 55 09/07/2022
4.7.11 50 09/08/2022
4.7.10 25 09/07/2022
4.7.9 10 09/08/2022
4.7.8 43 08/22/2022
4.7.7 22 09/09/2022
4.7.1 40 09/07/2022
4.7.0 23 09/09/2022
4.6.62-alpha 20 09/08/2022
4.6.39-alpha 18 09/11/2022
4.6.38-alpha 6 09/04/2022
4.6.36-alpha 42 09/08/2022
4.6.25-alpha 8 09/07/2022
4.5.30 24 09/03/2022
4.5.29 17 08/21/2022
4.5.28 8 09/04/2022
4.5.23 26 09/09/2022
4.5.22 40 09/08/2022
4.5.21 28 09/03/2022
4.5.20 12 09/02/2022
4.5.19 27 09/07/2022
4.5.18 33 09/08/2022
4.5.16 35 09/08/2022
4.5.13 39 09/08/2022
4.5.10 11 09/03/2022
4.5.9 24 09/08/2022
4.5.9-alpha 42 09/08/2022
4.5.8 45 09/09/2022
4.5.7 34 09/07/2022
4.5.7-alpha 12 08/23/2022
4.5.6-alpha 10 09/08/2022
4.5.3 49 09/08/2022
4.5.0 15 09/09/2022
4.2.1510.2205 36 09/03/2022
4.2.1507.118 56 09/02/2022
4.2.1506.2515 24 09/08/2022
4.2.1506.2016 18 09/08/2022
4.2.1502.911 13 09/09/2022
4.2.1409.1722 41 09/08/2022
4.2.1408.717 43 08/24/2022
4.2.1408.619 22 09/08/2022
4.2.1402.2112 11 09/03/2022
4.2.1312.1622 58 09/09/2022
4.2.1312.1621 49 09/10/2022
4.2.1312.1615 25 09/07/2022
4.2.1312.1416 56 09/05/2022
4.2.1312.1323 18 08/21/2022
4.2.1312.1319 38 09/03/2022
4.1.1311.615 39 08/25/2022
4.1.1309.1617 30 09/08/2022
4.1.1309.919 21 08/23/2022
4.1.1309.801 15 09/08/2022
4.1.1309.800 45 09/02/2022
4.1.1308.2321 51 09/07/2022
4.1.1308.2316 36 09/08/2022
4.1.1308.2120 10 09/03/2022
4.0.10827 28 09/03/2022
3.1.416.3 41 09/07/2022