Skip to content

Instantly share code, notes, and snippets.

@ThomasArdal
Created January 18, 2013 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasArdal/4563160 to your computer and use it in GitHub Desktop.
Save ThomasArdal/4563160 to your computer and use it in GitHub Desktop.
A test using callbacks instead of Verify from Moq.
[Test]
public void SomeTest() {
// Arrange
var mock = new Mock<IDependency>();
string string1 = null;
string string2 = null;
mock
.Setup(x => x.AMethodCall(It.IsAny<string>(), It.IsAny<string>()))
.Callback<string, string>((s1, s2) =>
{
string1 = s1;
string2 = s2;
});
var sut = new ServiceUnderTest(mock.Object);
// Act
sut.DoIt();
// Assert
Assert.That(string1, Is.EqualTo("Hello"));
Assert.That(string2, Is.EqualTo("World"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment