Skip to content

Instantly share code, notes, and snippets.

@GreenIcicle
Created April 22, 2013 17:59
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 GreenIcicle/5437116 to your computer and use it in GitHub Desktop.
Save GreenIcicle/5437116 to your computer and use it in GitHub Desktop.
Code Example: Implementation of a factory method for unit tests, used in http://blog.zuehlke.com/?p=1421
private Controller CreateSubject(
            string[] names = null,
            IDataSource dataSource = null)
{
    names = names ?? new[] { "Alice", "Bob", "Alfred" };
    if (dataSource == null)
    {
        var mock = new Mock<IDataSource>();
        mock.Setup(x => x.GetNames()).Returns(names);
        dataSource = mock.Object;
    }
    return new Controller(dataSource);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment