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