Skip to content

rickardn/Consolas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Consolas is a console application framework that simplyfies the creation of everything from simple throw away apps to bigger, more complex tools with lots of arguments.

Features

  • Convention over configuration
  • Small fingerprint
  • Testable
  • Mustache view engine
  • Razor view engine (plugable)

How to get it

Simply create a new Console Application and install the Nuget package Consolas or run the following command in the Package Manager Console

PM> Install-Package Consolas

Simple example

class Program : ConsoleApp<Program>
{
    static void Main(string[] args)
    {
        Match(args);
    }
}

public class HelpArgs
{
    public bool Help { get; set; }
}

public class HelpCommand : Command
{
    public string Execute(HelpArgs args)
    {
        return "Using: Program.exe ...";
    }
}

Consolas matching args

Running the above program from a console

C> program.exe -Help
Using: Program.exe ...

Unit testing

Unit tests

Unit testing Consolas Commands is easy:

[TestFixture]
public class GrepCommandTests
{
    [Test]
    public void Execute_ValidArgument_ReturnsGrepedText()
    {
        var command = new GrepCommand();

        var result = command.Execute(new GrepArgs
        {
            FileName = "doc.txt",
            Regex = "foo"
        });

        StringAssert.Contains("foo bar baz", result);
    }
}

End to end tests

The following is a sample testing a console application from end to end:

[TestFixture]
public class EndToEndTests
{
    private StringBuilder _consoleOut;
    private TextWriter _outWriter;

    [SetUp]
    public void Setup()
    {
        _outWriter = Console.Out;
        _consoleOut = new StringBuilder();
        Console.SetOut(new StringWriter(_consoleOut));
    }

    [TearDown]
    public void TearDown()
    {
        Console.SetOut(_outWriter);
    }

    [Test]
    public void Version()
    {
        Program.Main(new []{ "-version"});
        StringAssert.Contains("2.4.2", _consoleOut.ToString());
    }
}

Advanced examples

License

BSD 2-Clause License

Blog articles

Introducing Consolas - a console application framework for .NET

Acknowledgments

Consolas makes use of the following OSS projects: