I thought I'd attempt a code kata that simulates an ATM machine on the command line. I decided to drive the design using TDD. I've run into an interesting scenario and I'm curious about what others have done in this scenario.

If you look (down at the bottom) at my AtmMachine class, you'll notice that I'm exiting my while loop on purpose so that my tests don't time out. This feels like a code smell to me and I'd like to know if others do things like this.

My current feelings are split betweeen:

  1. "I'm doing it wrong" by attempting to unit test ongoing execution
  2. The inability to write a unit test for it implies that "while" is the wrong construct

Here are the unit tests that I have for the atm machine so far:

[TestClass]
public class when_atm_starts
{
    private static readonly string WELCOME_MSG = "Welcome to Al Banco de Ruiz!";

    private AtmMachine _atm;
    private Mock<IAtmInput> _inputMock;
    private Mock<IAtmOutput> _outputMock;
    private Mock<ILogger> _loggerMock;
    private Mock<ICommandFactory> _cmdFactoryMock;


    [TestInitialize]
    public void BeforeEachTest()
    {
        _inputMock = new Mock<IAtmInput>();
        _outputMock = new Mock<IAtmOutput>();
        _loggerMock = new Mock<ILogger>();
        _cmdFactoryMock = new Mock<ICommandFactory>();

        _atm = new AtmMachine(_inputMock.Object, _outputMock.Object, _loggerMock.Object, _cmdFactoryMock.Object);
    }


    [TestMethod]
    public void no_one_should_be_logged_in()
    {
        this.SetupForCancelledUser();

        _atm.Start();

        Assert.IsNull(_atm.CurrentUser);
    }

    [TestMethod]
    public void should_print_welcome_to_output()
    {
        this.SetupForCancelledUser();

        _atm.Start();

        _outputMock.Verify(o => o.Write(WELCOME_MSG));
    }

    [TestMethod]
    public void should_execute_login_command()
    {
        Mock<
Edit
Report