Adds Verify support for verifying Moq types.
moq
Перейти к файлу
Simon Cropp b0b8b6eacb refs and cleanup 2024-09-13 22:39:37 +10:00
.github refs or cleanup 2024-03-03 10:49:25 +11:00
src refs and cleanup 2024-09-13 22:39:37 +10:00
.gitignore init 2022-03-15 20:22:58 +11:00
license.txt init 2022-03-15 20:22:58 +11:00
readme.md Update readme.md 2024-08-15 21:53:37 +10:00

readme.md

Verify.Moq

Discussions Build status NuGet Status

Adds Verify support for verifying Moq types.

See Milestones for release notes.

NuGet package

https://nuget.org/packages/Verify.Moq/

Usage

[ModuleInitializer]
public static void Init() =>
    VerifyMoq.Initialize();

snippet source | anchor

Given an interface:

public interface ITarget
{
    string Method(int a, int b);
}

snippet source | anchor

The Mock and its invocations can then be verified:

[Fact]
public Task Test()
{
    var mock = new Mock<ITarget>();

    mock.Setup(_ => _.Method(It.IsAny<int>(), It.IsAny<int>()))
        .Returns("response");

    var target = mock.Object;
    target.Method(1, 2);
    return Verify(mock);
}

snippet source | anchor

Will result in:

[
  {
    Method: ITarget.Method(int a, int b),
    Arguments: [
      1,
      2
    ],
    ReturnValue: response
  }
]

snippet source | anchor