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 7 22.09.2024
4.20.70 7 22.09.2024
4.20.69 6 22.09.2024
4.18.4 8 27.08.2024
4.18.3 5 29.11.2024
4.18.2 0 02.08.2022
4.18.1 22 31.01.2024
4.18.0 9 22.09.2024
4.17.2 10 22.09.2024
4.17.1 5 27.11.2024
4.16.1 0 23.02.2021
4.16.0 0 16.01.2021
4.15.2 0 26.11.2020
4.15.1 10 22.09.2024
4.14.7 0 14.10.2020
4.14.6 0 30.09.2020
4.14.5 0 01.07.2020
4.14.4 0 24.06.2020
4.14.3 0 18.06.2020
4.14.2 0 16.06.2020
4.14.1 0 28.04.2020
4.14.0 5 22.09.2024
4.13.1 0 19.10.2019
4.13.0 0 31.08.2019
4.12.0 0 20.06.2019
4.11.0 0 27.05.2019
4.11.0-rc2 0 27.05.2019
4.11.0-rc1 0 19.04.2019
4.10.1 2 13.11.2024
4.10.0 8 22.09.2024
4.9.0 0 13.07.2018
4.8.3 6 22.09.2024
4.8.2 7 22.09.2024
4.8.1 9 22.09.2024
4.8.0 10 22.09.2024
4.8.0-rc1 2 10.12.2024
4.7.145 7 22.09.2024
4.7.142 8 22.09.2024
4.7.137 8 22.09.2024
4.7.127 3 26.11.2024
4.7.99 0 17.07.2017
4.7.63 0 21.06.2017
4.7.58 0 20.06.2017
4.7.49 0 18.06.2017
4.7.46 3 26.11.2024
4.7.25 0 02.06.2017
4.7.12 7 22.09.2024
4.7.11 7 26.11.2024
4.7.10 8 22.09.2024
4.7.9 3 04.12.2024
4.7.8 3 28.11.2024
4.7.7 0 25.03.2017
4.7.1 3 09.12.2024
4.7.0 8 22.09.2024
4.6.62-alpha 7 22.09.2024
4.6.39-alpha 0 18.02.2017
4.6.38-alpha 6 22.09.2024
4.6.36-alpha 7 22.09.2024
4.6.25-alpha 7 14.11.2024
4.5.30 0 09.01.2017
4.5.29 3 18.11.2024
4.5.28 0 10.11.2016
4.5.23 9 22.09.2024
4.5.22 7 22.09.2024
4.5.21 8 22.09.2024
4.5.20 8 22.09.2024
4.5.19 4 26.11.2024
4.5.18 1 09.12.2024
4.5.16 0 18.07.2016
4.5.13 3 28.11.2024
4.5.10 0 21.06.2016
4.5.9 7 22.09.2024
4.5.9-alpha 6 22.09.2024
4.5.8 0 26.05.2016
4.5.7 5 27.11.2024
4.5.7-alpha 0 22.05.2016
4.5.6-alpha 2 28.11.2024
4.5.3 7 30.10.2024
4.5.0 0 24.05.2016
4.2.1510.2205 7 22.09.2024
4.2.1507.118 0 01.07.2015
4.2.1506.2515 3 27.11.2024
4.2.1506.2016 0 20.06.2015
4.2.1502.911 8 22.09.2024
4.2.1409.1722 3 15.12.2024
4.2.1408.717 0 07.08.2014
4.2.1408.619 0 06.08.2014
4.2.1402.2112 7 22.09.2024
4.2.1312.1622 2 11.12.2024
4.2.1312.1621 3 15.12.2024
4.2.1312.1615 7 22.09.2024
4.2.1312.1416 9 22.09.2024
4.2.1312.1323 0 14.12.2013
4.2.1312.1319 6 22.09.2024
4.1.1311.615 0 18.11.2013
4.1.1309.1617 0 16.09.2013
4.1.1309.919 0 09.09.2013
4.1.1309.801 0 08.09.2013
4.1.1309.800 0 08.09.2013
4.1.1308.2321 0 23.08.2013
4.1.1308.2316 6 22.09.2024
4.1.1308.2120 7 22.09.2024
4.0.10827 7 13.02.2024
3.1.416.3 6 22.09.2024