Moq 4.20.69Prefix Reserved
dotnet add package Moq --version 4.20.69
NuGet\Install-Package Moq -Version 4.20.69
<PackageReference Include="Moq" Version="4.20.69" />
paket add Moq --version 4.20.69
#r "nuget: Moq, 4.20.69"
// 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("220.127.116.11")) .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("18.104.22.168"); // Verify that the given method was indeed called with the expected value at most once mock.Verify(library => library.DownloadExists("22.214.171.124"), 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("126.96.36.199") == true); // Exercise the instance returned by Mock.Of by calling methods on it... bool download = lovable.DownloadExists("188.8.131.52"); // 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("184.108.40.206"));
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!
|Product||Versions 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.|
NuGet packages (745)
Showing the top 5 NuGet packages that depend on Moq:
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
An auto-mocking container that generates mocks using Moq
Autofac extension for automocking and creation of mock objects in 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.
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:
Windows system utilities to maximize productivity
The Free Software Media System
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.
Launcher for Windows, an alternative to Alfred and Launchy.
Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET Foundation community project.