Moq 4.20.70

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. Daniel Gnägi Ashley Medway Keith Pickford Thomas Bolon Kori Francis Toni Wenzel Giorgi Dalakishvili Mike James Dan Siegel Reuben Swartz Jacob Foshee Eric Johnson Norman Mackay Certify The Web Rich Lee Ix Technologies B.V. David JENNI Jonathan Oleg Kyrylchuk Mariusz Kogut Charley Wu Jakob Tikjøb Andersen Seann Alexander Tino Hager Mark Seemann Angelo Belchior Blauhaus Technology (Pty) Ltd Ken Bonny Simon Cropp agileworks-eu Zheyu Shen

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