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 (744)

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,271,114 8/11/2023
4.18.4 31,794,443 12/30/2022
4.18.3 4,470,084 12/5/2022
4.18.2 26,803,005 8/2/2022
4.18.1 19,223,248 5/16/2022
4.18.0 807,613 5/11/2022
4.17.2 18,270,327 3/6/2022
4.17.1 1,766,683 2/26/2022
4.16.1 82,217,182 2/23/2021
4.16.0 14,598,626 1/16/2021
4.15.2 11,232,953 11/26/2020
4.15.1 6,391,319 11/10/2020
4.14.7 7,205,191 10/14/2020
4.14.6 3,264,530 9/30/2020
4.14.5 20,953,658 7/1/2020
4.14.4 1,695,015 6/24/2020
4.14.3 1,465,054 6/18/2020
4.14.2 968,816 6/16/2020
4.14.1 12,745,558 4/28/2020
4.14.0 1,153,856 4/24/2020
4.13.1 42,856,853 10/19/2019
4.13.0 9,944,846 8/31/2019
4.12.0 12,873,474 6/20/2019
4.11.0 4,410,475 5/27/2019
4.11.0-rc2 5,180 5/27/2019
4.11.0-rc1 194,678 4/19/2019
4.10.1 29,250,329 12/3/2018
4.10.0 13,122,553 9/8/2018
4.9.0 8,948,556 7/13/2018
4.8.3 5,205,561 6/9/2018
4.8.2 12,376,888 2/23/2018
4.8.1 5,001,427 1/8/2018
4.8.0 3,281,265 12/24/2017
4.8.0-rc1 49,464 12/8/2017
4.7.145 7,040,451 11/6/2017
4.7.142 2,610,532 10/10/2017
4.7.137 1,407,345 10/3/2017
4.7.127 846,801 9/25/2017
4.7.99 6,151,520 7/17/2017
4.7.63 1,681,957 6/21/2017
4.7.58 72,137 6/20/2017
4.7.49 368,359 6/18/2017
4.7.46 73,370 6/18/2017
4.7.25 1,322,745 6/2/2017
4.7.12 274,435 5/30/2017
4.7.11 5,831 5/30/2017
4.7.10 1,165,462 5/6/2017
4.7.9 416,397 4/29/2017
4.7.8 1,791,888 3/26/2017
4.7.7 27,382 3/25/2017
4.7.1 1,556,375 2/28/2017
4.7.0 9,884,252 2/22/2017
4.6.62-alpha 5,843 2/21/2017
4.6.39-alpha 13,151 2/18/2017
4.6.38-alpha 744,570 8/20/2016
4.6.36-alpha 204,374 7/20/2016
4.6.25-alpha 107,524 6/6/2016
4.5.30 3,760,192 1/9/2017
4.5.29 1,119,144 12/10/2016
4.5.28 1,876,100 11/10/2016
4.5.23 1,149,938 10/11/2016
4.5.22 780,425 9/20/2016
4.5.21 1,528,608 8/12/2016
4.5.20 10,203 8/12/2016
4.5.19 92,304 8/10/2016
4.5.18 7,074 8/10/2016
4.5.16 807,226 7/18/2016
4.5.13 188,081 7/11/2016
4.5.10 698,762 6/21/2016
4.5.9 660,393 6/9/2016
4.5.9-alpha 10,398 5/22/2016
4.5.8 689,239 5/26/2016
4.5.7 9,050 5/26/2016
4.5.7-alpha 4,299 5/22/2016
4.5.6-alpha 4,484 5/22/2016
4.5.3 935,650 5/25/2016
4.5.0 264,877 5/24/2016
4.2.1510.2205 7,693,757 10/22/2015
4.2.1507.118 2,775,717 7/1/2015
4.2.1506.2515 147,408 6/25/2015
4.2.1506.2016 66,583 6/20/2015
4.2.1502.911 3,002,628 2/9/2015
4.2.1409.1722 2,211,036 9/17/2014
4.2.1408.717 900,323 8/7/2014
4.2.1408.619 26,747 8/6/2014
4.2.1402.2112 2,305,178 2/21/2014
4.2.1312.1622 911,752 12/17/2013
4.2.1312.1621 6,238 12/16/2013
4.2.1312.1615 6,810 12/16/2013
4.2.1312.1416 20,393 12/14/2013
4.2.1312.1323 7,426 12/14/2013
4.2.1312.1319 48,403 12/13/2013
4.1.1311.615 369,564 11/18/2013
4.1.1309.1617 629,081 9/16/2013
4.1.1309.919 286,011 9/9/2013
4.1.1309.801 13,920 9/8/2013
4.1.1309.800 6,475 9/8/2013
4.1.1308.2321 874,854 8/23/2013
4.1.1308.2316 9,001 8/23/2013
4.1.1308.2120 1,334,172 8/21/2013
4.0.10827 4,746,309 2/9/2011
3.1.416.3 495,989 2/9/2011