Refactoring and Design Skills for Test Driven Development SA2013 by Roy Osherove
--> SUT
public class LoginManager
{
private IReadOnlyCollection<string> users;
public LoginManager()
{
users = new[] { "john", "clare", "Mary", "Tom" };
}
public bool IsLoginOk(string user, string password)
{
log(user);
return users.Contains(user);
}
protected virtual void log(string user)
{
Logger.Log(user);
}
}
public static class Logger
{
public static void Log(string message)
{
}
}
--> Test
public class LoginManagerShould
{
private LoginManagerTesteable loginManager;
[SetUp]
public void SetUp()
{
loginManager = new LoginManagerTesteable();
}
[Test]
public void return_false_when_user_is_empty()
{
var result = loginManager.IsLoginOk(String.Empty, "password");
Assert.IsFalse(result);
}
[Test]
public void return_false_when_user_is_null()
{
var result = loginManager.IsLoginOk(null, "password");
Assert.IsFalse(result);
}
[Test]
public void return_true_when_user_is_valid()
{
var result = loginManager.IsLoginOk("Tom", "password");
Assert.IsTrue(result);
}
}
class LoginManagerTesteable : LoginManager
{
protected override void log(string user)
{
}
}
No hay comentarios:
Publicar un comentario