Skip to content

Instantly share code, notes, and snippets.

@ChrisMissal
Last active August 29, 2015 14:17
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 ChrisMissal/7abc8ace31c93252b150 to your computer and use it in GitHub Desktop.
Save ChrisMissal/7abc8ace31c93252b150 to your computer and use it in GitHub Desktop.
CLI Code Spike – Rethinking how I interact with the command line via C# a little bit. I have some spike code in which all these tests pass. Thoughts?
public class CommandResolutionTests
{
public void should_resolve_text_to_command()
{
"samplecommand".Called<SampleCommand>();
}
public void should_call_command_hello()
{
"samplecommand hello".Called<SampleCommand>()
.Received().Hello();
}
public void should_call_command_save_with_file()
{
"samplecommand save --file=guybowling.png".Called<SampleCommand>()
.Received().Save(Arg.Is<SampleCommand.SaveArgs>(x => x.File == "guybowling.png"));
}
public void should_call_command_save_with_output()
{
"samplecommand save --output=ProfilePic.png".Called<SampleCommand>()
.Received().Save(Arg.Is<SampleCommand.SaveArgs>(x => x.Output == "ProfilePic.png"));
}
}
public class SampleCommand
{
public virtual string Hello()
{
return @"Hello World";
}
public virtual void Save(SaveArgs args)
{
// do stuff
}
public class SaveArgs
{
public string File { get; set; }
public string Output { get; set; }
}
}
@gregsohl
Copy link

The idea command line parser solution will have a fluent WebAPI written in F#, running the generated commands through Mass Transit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment