Skip to content

Instantly share code, notes, and snippets.

@asierba
Last active January 20, 2025 16:29
Show Gist options
  • Select an option

  • Save asierba/ad9978c8b548f3fcef40 to your computer and use it in GitHub Desktop.

Select an option

Save asierba/ad9978c8b548f3fcef40 to your computer and use it in GitHub Desktop.

Revisions

  1. asierba renamed this gist Aug 22, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. asierba created this gist Aug 19, 2015.
    23 changes: 23 additions & 0 deletions Unit test the console in c#
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    class Program
    {
    public static void Main(string[] args)
    {
    Console.WriteLine("What's your name?");
    var name = Console.ReadLine();
    Console.WriteLine(string.Format("Hello {0}!!", name));
    }

    [Test]
    public void something()
    {
    var output = new StringWriter();
    Console.SetOut(output);

    var input = new StringReader("Somebody");
    Console.SetIn(input);

    Program.Main(new string[] { });

    Assert.That(output.ToString(), Is.EqualTo(string.Format("What's your name?{0}Hello Somebody!!{0}", Environment.NewLine)));
    }
    }