An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# Verify.Moq

[![Discussions](https://img.shields.io/badge/Verify-Discussions-yellow?svg=true&label=)](https://github.com/orgs/VerifyTests/discussions)
[![Build status](https://img.shields.io/appveyor/build/SimonCropp/Verify-Moq)](https://ci.appveyor.com/project/SimonCropp/Verify-Moq)
[![NuGet Status](https://img.shields.io/nuget/v/Verify.Moq.svg)](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.

[![Entity Framework Extensions](https://raw.githubusercontent.com/VerifyTests/Verify.Moq/refs/heads/main/docs/zzz.png)](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