Created
January 18, 2013 08:29
-
-
Save ThomasArdal/4563160 to your computer and use it in GitHub Desktop.
A test using callbacks instead of Verify from Moq.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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