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.
- Convention over configuration
- Small fingerprint
- Testable
- Mustache view engine
- Razor view engine (plugable)
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
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 ...";
}
}
C> program.exe -Help Using: Program.exe ...
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);
}
}
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());
}
}
Introducing Consolas - a console application framework for .NET
Consolas makes use of the following OSS projects:
- SimpleInjector released under the MIT license: https://simpleinjector.codeplex.com/license
- Nustache released under the MIT license: https://raw.githubusercontent.com/jdiamond/Nustache/master/LICENSE.txt
- RazorEngine released under the Microsoft Public License (Ms-PL): http://razorengine.codeplex.com/license
- NUnit released under the NUnit licence: http://nunit.org/nuget/license.html
- Should released under the Apache 2.0 license: https://github.com/erichexter/Should/blob/master/license.txt
- NSubstitute released under the BSD license: https://raw.githubusercontent.com/nsubstitute/NSubstitute/master/LICENSE.txt
- Cake released under the MIT license: https://github.com/cake-build/cake/blob/develop/LICENSE