Last active
July 21, 2017 09:17
-
-
Save digitalbricklayer/7103320 to your computer and use it in GitHub Desktop.
Code throws a System.ObjectDisposedException.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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