FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

VerifyTests/Verify.Moq: Adds Verify support for verifying Moq types. · GitHub

Latest commit

 

History

776 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Verify.Moq

Adds Verify support for verifying Moq types.

See Milestones for release notes.

Sponsors

Entity Framework Extensions

Entity Framework Extensions is a major sponsor and is proud to contribute to the development this project.

Developed using JetBrains IDEs

NuGet

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:

[Test]
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

Results in:

[
  {
    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:

[Test]
public Task ScrubArguments()
{
    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)
        .ScrubMember("a");
}

snippet source | anchor

Results in:

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

snippet source | anchor

About

Adds Verify support for verifying Moq types.

Topics

Resources

Stars

14 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages


Back | FazBrowse Home | New Git URL