Skip to content

Instantly share code, notes, and snippets.

@ignu
Created March 4, 2010 18:49
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 ignu/322013 to your computer and use it in GitHub Desktop.
Save ignu/322013 to your computer and use it in GitHub Desktop.
[TestFixture]
public class WebServiceTest
{
[Test]
public void should_call_authentication_service()
{
service.MyMethod();
Verify<IAuthenticationService>(a => a.Authenticate(username, password)).WasCalled();
}
}
[TestFixture]
public class AuthenticationServiceTest
{
[Test]
[ExpectedException(typeof(UnauthorizedAccessException))]
public void should_throw_when_user_not_found()
{
Mock<IUserRepository>().Expect(u => u.FindByUserName("i")).Returns(null);
authenticationService.Authenticate("i", "notMyPassword");
}
[Test]
[ExpectedException(typeof(UnauthorizedAccessException))]
public void should_throw_when_invalid_password()
{
Mock<IUserRepository>().Expect(u => u.FindByUserName("i")).Returns(new User("i", "password"));
authenticationService.Authenticate("i", "notMyPassword");
}
[Test]
public void should_return_true_when_valid_password()
{
Mock<IUserRepository>().Expect(u => u.FindByUserName("i")).Returns(new User("i", "password"));
authenticationService.Authenticate("i", "password").ShouldBeTrue();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment