Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code throws a System.ObjectDisposedException.
// The test
[TestMethod]
public void Run_With_No_Arguments_Returns_Invalid_Args()
{
var sut = new LiteDatabaseRunner(MakeDatabaseHelperMock().Object);
var actualResult = sut.Run(Array.Empty<string>());
actualResult.Should().BeGreaterThan(0);
}
// Options class
/// <summary>
/// Command line options specification.
/// </summary>
class CommandLineOptions
{
public CommandLineOptions()
{
UpgradeVerb = new UpgradeOptions();
DeleteVerb = new DeleteOptions();
CreateVerb = new CreateOptions();
}
[VerbOption("upgrade",
HelpText = "Upgrade the Xsensior Lite database schema.")]
public UpgradeOptions UpgradeVerb { get; set; }
[VerbOption("delete",
HelpText = "Delete the Xsensior Lite database. Will delete *all* data.")]
public DeleteOptions DeleteVerb { get; set; }
[VerbOption("create",
HelpText = "Create a new Xsensior Lite database.")]
public CreateOptions CreateVerb { get; set; }
[HelpVerbOption]
public string GetUsage(string verb)
{
return HelpText.AutoBuild(this, verb);
}
}
class DeleteOptions
{
}
class CreateOptions
{
}
class UpgradeOptions
{
}
// Parser code
var options = new CommandLineOptions();
if (!Parser.Default.ParseArguments(args, options,
delegate(string verb, object subOptions)
{
invokedVerb = verb;
invokedVerbInstance = subOptions;
}))
{
if (invokedVerb != "help")
Console.Error.WriteLine("Error: Missing command.");
return Parser.DefaultExitCodeFail;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment