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
Showing the top 20 packages that depend on Moq.
Packages | Downloads |
---|---|
AWSSDK.SecretsManager.Caching
The AWS Secrets Manager .NET caching client enables in-process caching of secrets for C# applications.
|
5 |
AWSSDK.SecretsManager.Caching
The AWS Secrets Manager .NET caching client enables in-process caching of secrets for C# applications.
|
4 |
https://github.com/moq/moq/blob/main/changelog.md
.NET Framework 4.6.2
- Castle.Core (>= 5.1.1)
- System.Threading.Tasks.Extensions (>= 4.5.4)
.NET Standard 2.0
- Castle.Core (>= 5.1.1)
- System.Threading.Tasks.Extensions (>= 4.5.4)
.NET Standard 2.1
- Castle.Core (>= 5.1.1)
.NET 6.0
- Castle.Core (>= 5.1.1)
Version | Downloads | Last updated |
---|---|---|
4.20.72 | 3 | 09/13/2024 |
4.20.71 | 3 | 09/03/2024 |
4.20.70 | 7 | 01/21/2024 |
4.20.69 | 10 | 10/11/2023 |
4.18.4 | 10 | 05/18/2023 |
4.18.3 | 2 | 08/23/2023 |
4.18.2 | 9 | 11/04/2022 |
4.18.1 | 6 | 03/30/2023 |
4.18.0 | 3 | 05/15/2023 |
4.17.2 | 15 | 03/11/2022 |
4.17.1 | 2 | 08/23/2023 |
4.16.1 | 49 | 03/19/2021 |
4.16.0 | 5 | 11/22/2021 |
4.15.2 | 4 | 08/24/2023 |
4.15.1 | 2 | 08/24/2023 |
4.14.7 | 4 | 08/24/2023 |
4.14.6 | 5 | 08/21/2023 |
4.14.5 | 3 | 08/23/2023 |
4.14.4 | 3 | 08/23/2023 |
4.14.3 | 1 | 08/23/2023 |
4.14.2 | 4 | 08/26/2023 |
4.14.1 | 3 | 08/23/2023 |
4.14.0 | 2 | 08/26/2023 |
4.13.1 | 3 | 08/24/2023 |
4.13.0 | 14 | 01/13/2021 |
4.12.0 | 67 | 12/09/2019 |
4.11.0 | 3 | 08/21/2023 |
4.11.0-rc2 | 3 | 08/24/2023 |
4.11.0-rc1 | 6 | 08/21/2023 |
4.10.1 | 545 | 11/14/2019 |
4.10.0 | 66 | 11/15/2019 |
4.9.0 | 4 | 08/24/2023 |
4.8.3 | 5 | 08/24/2023 |
4.8.2 | 2 | 08/25/2023 |
4.8.1 | 5 | 08/23/2023 |
4.8.0 | 1 | 05/15/2023 |
4.8.0-rc1 | 4 | 06/14/2023 |
4.7.145 | 3 | 08/23/2023 |
4.7.142 | 2 | 05/17/2023 |
4.7.137 | 3 | 05/13/2023 |
4.7.127 | 3 | 08/23/2023 |
4.7.99 | 2 | 08/23/2023 |
4.7.63 | 2 | 05/17/2023 |
4.7.58 | 2 | 08/21/2023 |
4.7.49 | 4 | 08/21/2023 |
4.7.46 | 3 | 08/22/2023 |
4.7.25 | 20 | 07/23/2023 |
4.7.12 | 3 | 08/24/2023 |
4.7.11 | 1 | 08/26/2023 |
4.7.10 | 1 | 08/26/2023 |
4.7.9 | 4 | 08/22/2023 |
4.7.8 | 4 | 02/20/2024 |
4.7.7 | 4 | 08/23/2023 |
4.7.1 | 2 | 08/24/2023 |
4.7.0 | 5 | 08/23/2023 |
4.6.62-alpha | 3 | 08/27/2023 |
4.6.39-alpha | 3 | 07/11/2024 |
4.6.38-alpha | 6 | 08/24/2023 |
4.6.36-alpha | 8 | 08/24/2023 |
4.6.25-alpha | 6 | 05/17/2023 |
4.5.30 | 7 | 08/23/2023 |
4.5.29 | 4 | 08/24/2023 |
4.5.28 | 3 | 08/24/2023 |
4.5.23 | 4 | 08/21/2023 |
4.5.22 | 7 | 08/23/2023 |
4.5.21 | 5 | 08/23/2023 |
4.5.20 | 4 | 08/22/2023 |
4.5.19 | 3 | 08/22/2023 |
4.5.18 | 4 | 08/27/2023 |
4.5.16 | 4 | 08/25/2023 |
4.5.13 | 5 | 08/24/2023 |
4.5.10 | 2 | 08/24/2023 |
4.5.9 | 6 | 12/07/2023 |
4.5.9-alpha | 6 | 05/16/2023 |
4.5.8 | 5 | 05/18/2023 |
4.5.7 | 7 | 08/23/2023 |
4.5.7-alpha | 4 | 06/13/2023 |
4.5.6-alpha | 3 | 06/14/2023 |
4.5.3 | 6 | 08/24/2023 |
4.5.0 | 3 | 08/23/2023 |
4.2.1510.2205 | 6 | 04/08/2021 |
4.2.1507.118 | 3 | 12/20/2023 |
4.2.1506.2515 | 3 | 08/22/2023 |
4.2.1506.2016 | 4 | 08/22/2023 |
4.2.1502.911 | 6 | 08/21/2023 |
4.2.1409.1722 | 4 | 08/26/2023 |
4.2.1408.717 | 5 | 08/22/2023 |
4.2.1408.619 | 6 | 05/16/2023 |
4.2.1402.2112 | 5 | 05/15/2023 |
4.2.1312.1622 | 6 | 08/24/2023 |
4.2.1312.1621 | 2 | 08/24/2023 |
4.2.1312.1615 | 4 | 08/23/2023 |
4.2.1312.1416 | 3 | 02/20/2024 |
4.2.1312.1323 | 5 | 05/13/2023 |
4.2.1312.1319 | 3 | 08/26/2023 |
4.1.1311.615 | 5 | 08/24/2023 |
4.1.1309.1617 | 3 | 08/24/2023 |
4.1.1309.919 | 5 | 08/24/2023 |
4.1.1309.801 | 6 | 05/18/2023 |
4.1.1309.800 | 4 | 08/22/2023 |
4.1.1308.2321 | 3 | 08/23/2023 |
4.1.1308.2316 | 2 | 05/16/2023 |
4.1.1308.2120 | 4 | 08/25/2023 |
4.0.10827 | 3 | 08/23/2023 |
3.1.416.3 | 6 | 08/24/2023 |