Skip to content

Instantly share code, notes, and snippets.

@efleming969
Created December 19, 2018 14:30
Show Gist options
  • Save efleming969/af61222d963e87e5e0aaebdeb82a7837 to your computer and use it in GitHub Desktop.
Save efleming969/af61222d963e87e5e0aaebdeb82a7837 to your computer and use it in GitHub Desktop.
Mocking Examples
[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!"));
}
@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!");
}
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