Moq 4.20.69

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
.NET 6.0 .NET Standard 2.0 .NET Framework 4.6.2
dotnet add package Moq --version 4.20.69
NuGet\Install-Package Moq -Version 4.20.69
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Moq" Version="4.20.69" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Moq --version 4.20.69
#r "nuget: Moq, 4.20.69"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Moq as a Cake Addin
#addin nuget:?package=Moq&version=4.20.69

// Install Moq as a Cake Tool
#tool nuget:?package=Moq&version=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 alternate text is missing from this package README image 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 alternate text is missing from this package README image Eric Johnson Norman Mackay Certify The Web Taylor Mansfield Mårten Rånge David Petric Rich Lee Danilo Dantas alternate text is missing from this package README image Gary Woodfine alternate text is missing from this package README image alternate text is missing from this package README image Steve Bilogan Ix Technologies B.V. New Relic Chris Johnston‮ David JENNI alternate text is missing from this package README image Jonathan Oleg Kyrylchuk Juan Blanco LosManos Mariusz Kogut Charley Wu alternate text is missing from this package README image Thomas Due Jakob Tikjøb Andersen

Sponsor this project  

Learn more about GitHub Sponsors

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (750)

Showing the top 5 NuGet packages that depend on Moq:

Package Downloads
AutoFixture.AutoMoq The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

This extension turns AutoFixture into an Auto-Mocking Container. The mock instances are created by Moq. To use it, add the AutoMoqCustomization to your Fixture instance. Read more at http://blog.ploeh.dk/2010/08/19/AutoFixtureAsAnAutomockingContainer.aspx

Moq.AutoMock

An auto-mocking container that generates mocks using Moq

Autofac.Extras.Moq The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Autofac extension for automocking and creation of mock objects in Moq.

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.

Moq.EntityFrameworkCore

Library that provides methods that will help you with mocking Entity Framework Core.

GitHub repositories (1.1K)

Showing the top 5 popular GitHub repositories that depend on Moq:

Repository Stars
microsoft/PowerToys
Windows system utilities to maximize productivity
jellyfin/jellyfin
The Free Software Media System
dotnet-architecture/eShopOnContainers
Cross-platform .NET sample microservices and container based application that runs on Linux Windows and macOS. Powered by .NET 7, Docker Containers and Azure Kubernetes Services. Supports Visual Studio, VS for Mac and CLI based environments with Docker CLI, dotnet CLI, VS Code or any other code editor.
Wox-launcher/Wox
Launcher for Windows, an alternative to Alfred and Launchy.
AvaloniaUI/Avalonia
Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET Foundation community project.
Version Downloads Last updated
4.20.69 1,726,670 8/11/2023
4.18.4 33,155,902 12/30/2022
4.18.3 4,557,014 12/5/2022
4.18.2 27,243,481 8/2/2022
4.18.1 19,452,859 5/16/2022
4.18.0 819,634 5/11/2022
4.17.2 18,477,060 3/6/2022
4.17.1 1,781,588 2/26/2022
4.16.1 82,838,653 2/23/2021
4.16.0 14,745,889 1/16/2021
4.15.2 11,295,300 11/26/2020
4.15.1 6,425,551 11/10/2020
4.14.7 7,238,852 10/14/2020
4.14.6 3,279,076 9/30/2020
4.14.5 21,033,098 7/1/2020
4.14.4 1,702,064 6/24/2020
4.14.3 1,470,482 6/18/2020
4.14.2 972,979 6/16/2020
4.14.1 12,801,281 4/28/2020
4.14.0 1,158,889 4/24/2020
4.13.1 43,001,371 10/19/2019
4.13.0 9,983,656 8/31/2019
4.12.0 12,910,451 6/20/2019
4.11.0 4,422,547 5/27/2019
4.11.0-rc2 5,210 5/27/2019
4.11.0-rc1 195,008 4/19/2019
4.10.1 29,315,553 12/3/2018
4.10.0 13,152,210 9/8/2018
4.9.0 8,976,813 7/13/2018
4.8.3 5,220,405 6/9/2018
4.8.2 12,408,406 2/23/2018
4.8.1 5,014,165 1/8/2018
4.8.0 3,312,018 12/24/2017
4.8.0-rc1 49,557 12/8/2017
4.7.145 7,060,983 11/6/2017
4.7.142 2,614,094 10/10/2017
4.7.137 1,416,899 10/3/2017
4.7.127 849,080 9/25/2017
4.7.99 6,166,075 7/17/2017
4.7.63 1,685,729 6/21/2017
4.7.58 72,311 6/20/2017
4.7.49 368,612 6/18/2017
4.7.46 73,702 6/18/2017
4.7.25 1,326,374 6/2/2017
4.7.12 275,372 5/30/2017
4.7.11 5,891 5/30/2017
4.7.10 1,168,018 5/6/2017
4.7.9 417,157 4/29/2017
4.7.8 1,796,683 3/26/2017
4.7.7 27,439 3/25/2017
4.7.1 1,559,938 2/28/2017
4.7.0 10,003,019 2/22/2017
4.6.62-alpha 5,884 2/21/2017
4.6.39-alpha 13,197 2/18/2017
4.6.38-alpha 745,842 8/20/2016
4.6.36-alpha 204,428 7/20/2016
4.6.25-alpha 107,575 6/6/2016
4.5.30 3,772,927 1/9/2017
4.5.29 1,121,319 12/10/2016
4.5.28 1,882,644 11/10/2016
4.5.23 1,153,034 10/11/2016
4.5.22 781,859 9/20/2016
4.5.21 1,530,956 8/12/2016
4.5.20 10,249 8/12/2016
4.5.19 92,524 8/10/2016
4.5.18 7,109 8/10/2016
4.5.16 808,498 7/18/2016
4.5.13 188,367 7/11/2016
4.5.10 701,685 6/21/2016
4.5.9 663,359 6/9/2016
4.5.9-alpha 10,450 5/22/2016
4.5.8 689,728 5/26/2016
4.5.7 9,103 5/26/2016
4.5.7-alpha 4,328 5/22/2016
4.5.6-alpha 4,525 5/22/2016
4.5.3 938,894 5/25/2016
4.5.0 266,047 5/24/2016
4.2.1510.2205 7,715,462 10/22/2015
4.2.1507.118 2,781,292 7/1/2015
4.2.1506.2515 147,662 6/25/2015
4.2.1506.2016 66,705 6/20/2015
4.2.1502.911 3,013,502 2/9/2015
4.2.1409.1722 2,217,832 9/17/2014
4.2.1408.717 901,941 8/7/2014
4.2.1408.619 26,812 8/6/2014
4.2.1402.2112 2,309,993 2/21/2014
4.2.1312.1622 914,531 12/17/2013
4.2.1312.1621 6,268 12/16/2013
4.2.1312.1615 6,852 12/16/2013
4.2.1312.1416 20,438 12/14/2013
4.2.1312.1323 7,477 12/14/2013
4.2.1312.1319 48,568 12/13/2013
4.1.1311.615 370,013 11/18/2013
4.1.1309.1617 630,455 9/16/2013
4.1.1309.919 286,508 9/9/2013
4.1.1309.801 13,970 9/8/2013
4.1.1309.800 6,505 9/8/2013
4.1.1308.2321 875,489 8/23/2013
4.1.1308.2316 9,034 8/23/2013
4.1.1308.2120 1,347,570 8/21/2013
4.0.10827 4,764,785 2/9/2011
3.1.416.3 501,522 2/9/2011