Moq 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
No packages depend on Moq.
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 | 13 | 09/26/2024 |
4.20.70 | 139 | 03/26/2024 |
4.20.69 | 3 | 04/29/2024 |
4.18.4 | 3 | 04/29/2024 |
4.18.3 | 6 | 04/05/2024 |
4.18.2 | 4 | 04/29/2024 |
4.18.1 | 5 | 04/29/2024 |
4.18.0 | 2 | 06/20/2024 |
4.17.2 | 3 | 04/29/2024 |
4.17.1 | 4 | 04/29/2024 |
4.16.1 | 7 | 03/27/2024 |
4.16.0 | 5 | 04/29/2024 |
4.15.2 | 5 | 04/02/2024 |
4.15.1 | 3 | 04/29/2024 |
4.14.7 | 4 | 04/29/2024 |
4.14.6 | 3 | 04/29/2024 |
4.14.5 | 3 | 04/29/2024 |
4.14.4 | 5 | 04/29/2024 |
4.14.3 | 4 | 04/29/2024 |
4.14.2 | 5 | 03/30/2024 |
4.14.1 | 3 | 04/29/2024 |
4.14.0 | 5 | 04/29/2024 |
4.13.1 | 5 | 04/11/2024 |
4.13.0 | 5 | 04/29/2024 |
4.12.0 | 5 | 04/29/2024 |
4.11.0 | 3 | 04/29/2024 |
4.11.0-rc2 | 3 | 04/29/2024 |
4.11.0-rc1 | 4 | 04/29/2024 |
4.10.1 | 3 | 04/29/2024 |
4.10.0 | 3 | 04/29/2024 |
4.9.0 | 4 | 04/29/2024 |
4.8.3 | 3 | 04/29/2024 |
4.8.2 | 4 | 04/29/2024 |
4.8.1 | 6 | 04/29/2024 |
4.8.0 | 4 | 04/29/2024 |
4.8.0-rc1 | 4 | 04/29/2024 |
4.7.145 | 4 | 04/29/2024 |
4.7.142 | 3 | 04/29/2024 |
4.7.137 | 3 | 04/29/2024 |
4.7.127 | 4 | 04/29/2024 |
4.7.99 | 5 | 04/29/2024 |
4.7.63 | 4 | 04/29/2024 |
4.7.58 | 4 | 04/29/2024 |
4.7.49 | 3 | 04/29/2024 |
4.7.46 | 4 | 04/29/2024 |
4.7.25 | 4 | 04/29/2024 |
4.7.12 | 5 | 04/29/2024 |
4.7.11 | 4 | 04/29/2024 |
4.7.10 | 4 | 04/29/2024 |
4.7.9 | 4 | 04/29/2024 |
4.7.8 | 4 | 04/29/2024 |
4.7.7 | 4 | 04/29/2024 |
4.7.1 | 3 | 04/29/2024 |
4.7.0 | 5 | 04/29/2024 |
4.6.62-alpha | 3 | 04/29/2024 |
4.6.39-alpha | 7 | 04/29/2024 |
4.6.38-alpha | 3 | 04/29/2024 |
4.6.36-alpha | 3 | 04/29/2024 |
4.6.25-alpha | 4 | 04/29/2024 |
4.5.30 | 4 | 04/29/2024 |
4.5.29 | 3 | 04/29/2024 |
4.5.28 | 3 | 04/29/2024 |
4.5.23 | 5 | 04/07/2024 |
4.5.22 | 4 | 04/29/2024 |
4.5.21 | 4 | 04/29/2024 |
4.5.20 | 4 | 04/29/2024 |
4.5.19 | 6 | 04/29/2024 |
4.5.18 | 4 | 04/29/2024 |
4.5.16 | 3 | 04/29/2024 |
4.5.13 | 3 | 04/29/2024 |
4.5.10 | 5 | 03/25/2024 |
4.5.9 | 5 | 04/29/2024 |
4.5.9-alpha | 3 | 04/29/2024 |
4.5.8 | 3 | 04/29/2024 |
4.5.7 | 3 | 04/29/2024 |
4.5.7-alpha | 6 | 04/29/2024 |
4.5.6-alpha | 4 | 04/29/2024 |
4.5.3 | 4 | 04/29/2024 |
4.5.0 | 4 | 04/29/2024 |
4.2.1510.2205 | 4 | 04/29/2024 |
4.2.1507.118 | 3 | 04/29/2024 |
4.2.1506.2515 | 3 | 04/29/2024 |
4.2.1506.2016 | 5 | 04/11/2024 |
4.2.1502.911 | 5 | 04/01/2024 |
4.2.1409.1722 | 4 | 04/29/2024 |
4.2.1408.717 | 4 | 04/29/2024 |
4.2.1408.619 | 4 | 04/29/2024 |
4.2.1402.2112 | 4 | 04/29/2024 |
4.2.1312.1622 | 3 | 04/29/2024 |
4.2.1312.1621 | 4 | 04/29/2024 |
4.2.1312.1615 | 4 | 04/29/2024 |
4.2.1312.1416 | 3 | 04/29/2024 |
4.2.1312.1323 | 4 | 04/29/2024 |
4.2.1312.1319 | 4 | 04/29/2024 |
4.1.1311.615 | 3 | 04/29/2024 |
4.1.1309.1617 | 4 | 04/29/2024 |
4.1.1309.919 | 3 | 04/29/2024 |
4.1.1309.801 | 4 | 04/29/2024 |
4.1.1309.800 | 5 | 04/29/2024 |
4.1.1308.2321 | 4 | 04/29/2024 |
4.1.1308.2316 | 4 | 04/06/2024 |
4.1.1308.2120 | 3 | 04/29/2024 |
4.0.10827 | 3 | 04/29/2024 |
3.1.416.3 | 6 | 04/29/2024 |