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

Showing the top 20 packages that depend on Moq.

Packages Downloads
CheeseDataService
Package to access SIERA+ related data services and models
538
MockQueryable.Moq
Extension for mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc. When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
482
CheeseDataService
Package to access SIERA related data services and models
85
CheeseDataService
Package to access SIERA related data services and models
58
MockQueryable.Moq
Extension for mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc. When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
55
MockQueryable.Moq
Extension for mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc. When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
51
MockQueryable.Moq
Extension for mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc. When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
39
MockQueryable.Moq
Extension for mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc. by Moq When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
38
MockQueryable.Moq
Extension for mocking Entity Framework operations such ToListAsync, FirstOrDefaultAsync etc. by Moq When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
38
MockQueryable.Moq
Core package for MockQueryable extensions for mocking operations such ToListAsync, FirstOrDefaultAsync etc. When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
38
MockQueryable.Moq
Extension for mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc. by Moq When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
37
MockQueryable.Moq
Extension for mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc. When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
37
MockQueryable.Moq
Core package for MockQueryable extensions for mocking operations such ToListAsync, FirstOrDefaultAsync etc. When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
37
MockQueryable.Moq
Extension for mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc. When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
36
MockQueryable.Moq
Extension for mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc. by Moq When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
34
CheeseDataService
Package to access SIERA related data services and models
34
MockQueryable.Moq
Core package for MockQueryable extensions for mocking operations such ToListAsync, FirstOrDefaultAsync etc. When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
34
MockQueryable.Moq
Core package for MockQueryable extensions for mocking operations such ToListAsync, FirstOrDefaultAsync etc. When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
33
MockQueryable.Moq
Extension for mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc. by Moq When writing tests for your application it is often desirable to avoid hitting the database. The extension allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.
32

.NET Framework 4.6.2

.NET Standard 2.0

.NET Standard 2.1

.NET 6.0

Version Downloads Last updated
4.21.0 8 10/04/2026
4.20.72 129 10/04/2024
4.20.70 88 01/10/2024
4.20.69 50 02/14/2024
4.18.4 41 01/03/2023
4.18.3 46 01/27/2024
4.18.2 31 08/15/2022
4.18.1 30 06/16/2022
4.18.0 15 01/05/2024
4.17.2 30 03/31/2022
4.17.1 33 03/05/2024
4.16.1 931 02/26/2021
4.16.0 39 03/05/2024
4.15.2 42 03/05/2024
4.15.1 42 03/05/2024
4.14.7 35 09/17/2024
4.14.6 34 05/08/2025
4.14.5 15 08/27/2025
4.14.4 37 03/05/2024
4.14.3 40 06/29/2024
4.14.2 48 12/28/2023
4.14.1 11 01/12/2024
4.14.0 18 03/24/2024
4.13.1 40 04/17/2022
4.13.0 36 08/20/2021
4.12.0 37 01/01/2024
4.11.0 30 03/05/2024
4.11.0-rc2 33 09/17/2024
4.11.0-rc1 13 02/27/2025
4.10.1 39 03/08/2021
4.10.0 37 03/05/2024
4.9.0 41 12/31/2023
4.8.3 28 12/15/2023
4.8.2 38 03/05/2024
4.8.1 24 12/22/2023
4.8.0 44 12/15/2023
4.8.0-rc1 38 02/29/2024
4.7.145 22 03/05/2024
4.7.142 40 02/29/2024
4.7.137 39 12/19/2023
4.7.127 20 03/05/2024
4.7.99 27 03/04/2024
4.7.63 31 03/05/2024
4.7.58 31 03/05/2024
4.7.49 29 05/22/2025
4.7.46 34 02/10/2024
4.7.25 27 03/05/2024
4.7.12 31 03/05/2024
4.7.11 21 02/20/2024
4.7.10 30 04/20/2024
4.7.9 26 03/04/2024
4.7.8 32 03/05/2024
4.7.7 36 03/05/2024
4.7.1 27 03/05/2024
4.7.0 20 03/04/2024
4.6.62-alpha 32 09/13/2024
4.6.39-alpha 37 06/24/2026
4.6.38-alpha 17 12/25/2023
4.6.36-alpha 15 02/15/2025
4.6.25-alpha 17 04/12/2024
4.5.30 18 01/03/2024
4.5.29 30 12/20/2023
4.5.28 23 07/03/2026
4.5.23 39 03/04/2024
4.5.22 41 03/29/2024
4.5.21 30 12/13/2023
4.5.20 15 03/05/2024
4.5.19 41 03/05/2024
4.5.18 31 12/17/2023
4.5.16 40 03/05/2024
4.5.13 13 10/05/2024
4.5.10 16 10/14/2024
4.5.9 14 03/04/2024
4.5.9-alpha 42 01/19/2024
4.5.8 37 05/28/2024
4.5.7 30 12/24/2023
4.5.7-alpha 13 04/17/2025
4.5.6-alpha 40 05/01/2024
4.5.3 35 01/02/2024
4.5.0 48 03/23/2024
4.2.1510.2205 30 04/25/2024
4.2.1507.118 30 07/17/2025
4.2.1506.2515 24 03/04/2024
4.2.1506.2016 35 07/22/2024
4.2.1502.911 31 06/24/2026
4.2.1409.1722 12 10/20/2024
4.2.1408.717 14 02/28/2022
4.2.1408.619 13 04/20/2025
4.2.1402.2112 35 06/06/2025
4.2.1312.1622 11 10/30/2025
4.2.1312.1621 33 01/29/2024
4.2.1312.1615 42 06/24/2026
4.2.1312.1416 8 12/09/2024
4.2.1312.1323 32 01/28/2024
4.2.1312.1319 42 05/14/2025
4.1.1311.615 38 04/02/2024
4.1.1309.1617 37 04/27/2024
4.1.1309.919 27 06/24/2026
4.1.1309.801 20 01/22/2025
4.1.1309.800 31 02/12/2025
4.1.1308.2321 33 03/25/2025
4.1.1308.2316 32 05/27/2025
4.1.1308.2120 14 06/24/2026
4.0.10827 16 03/04/2024
3.1.416.3 25 01/19/2022