https://github.com/verifytests/verify.moq
Adds Verify support for verifying Moq types.
https://github.com/verifytests/verify.moq
moq
Last synced: 4 months ago
JSON representation
Adds Verify support for verifying Moq types.
- Host: GitHub
- URL: https://github.com/verifytests/verify.moq
- Owner: VerifyTests
- License: mit
- Created: 2022-03-15T08:08:58.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-04-14T11:24:13.000Z (about 1 year ago)
- Last Synced: 2025-04-14T12:29:47.544Z (about 1 year ago)
- Topics: moq
- Language: C#
- Homepage:
- Size: 357 KB
- Stars: 14
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/FUNDING.yml
- License: license.txt
Awesome Lists containing this project
README
#
Verify.Moq
[](https://github.com/orgs/VerifyTests/discussions)
[](https://ci.appveyor.com/project/SimonCropp/Verify-Moq)
[](https://www.nuget.org/packages/Verify.Moq/)
Adds [Verify](https://github.com/VerifyTests/Verify) support for verifying [Moq](https://github.com/moq/moq4) types.
**See [Milestones](../../milestones?state=closed) for release notes.**
## Sponsors
### Entity Framework Extensions
[Entity Framework Extensions](https://entityframework-extensions.net/?utm_source=simoncropp&utm_medium=Verify.Moq) is a major sponsor and is proud to contribute to the development this project.
[](https://entityframework-extensions.net/?utm_source=simoncropp&utm_medium=Verify.Moq)
## NuGet
* https://nuget.org/packages/Verify.Moq
## Usage
```cs
[ModuleInitializer]
public static void Init() =>
VerifyMoq.Initialize();
```
snippet source | anchor
Given an interface:
```cs
public interface ITarget
{
string Method(int a, int b);
}
```
snippet source | anchor
The Mock and its invocations can then be verified:
```cs
[Test]
public Task Test()
{
var mock = new Mock();
mock.Setup(_ => _.Method(It.IsAny(), It.IsAny()))
.Returns("response");
var target = mock.Object;
target.Method(1, 2);
return Verify(mock);
}
```
snippet source | anchor
Results in:
```txt
[
{
Method: ITarget.Method(int a, int b),
Arguments: {
Arguments: {
a: 1,
b: 2
}
},
ReturnValue: response
}
]
```
snippet source | anchor
## Scrubbing Arguments
Arguments can be scrubbed by name:
```cs
[Test]
public Task ScrubArguments()
{
var mock = new Mock();
mock.Setup(_ => _.Method(It.IsAny(), It.IsAny()))
.Returns("response");
var target = mock.Object;
target.Method(1, 2);
return Verify(mock)
.ScrubMember("a");
}
```
snippet source | anchor
Results in:
```txt
[
{
Method: ITarget.Method(int a, int b),
Arguments: {
Arguments: {
a: {Scrubbed},
b: 2
}
},
ReturnValue: response
}
]
```
snippet source | anchor