Created
December 19, 2018 14:30
-
-
Save efleming969/af61222d963e87e5e0aaebdeb82a7837 to your computer and use it in GitHub Desktop.
Mocking Examples
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
[Fact] | |
public void send_custom_greeting_by_email() | |
{ | |
var sut = new GreetingService(); | |
var emailGateway = new Mock<IEmailGateway>(); | |
sut.SendMail(emailGateway.Object, "Joe", "[email protected]"); | |
emailGateway.Verify(es => | |
es.Send("[email protected]", "Hello, Joe!")); | |
} |
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 send_custom_greeting_by_email() { | |
GreetingService sut = new GreetingService(); | |
EmailGateway emailGateway = mock(EmailGateway.class); | |
sut.sendMail(emailGateway, "Joe", "[email protected]"); | |
verify(emailGateway).send("[email protected]", "Hello, Joe!"); | |
} |
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( "send_custom_greeting_by_email", function () { | |
const sut = new GreetingService() | |
const emailGateway = new EmailGateway() | |
const expectation = mock( emailGateway ) | |
.expects( "send" ) | |
.withArgs( "[email protected]", "Hello, Joe!" ) | |
sut.sendMail( emailGateway, "Joe", "[email protected]" ) | |
expectation.verify() | |
} ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment