public void CommandLine_ProjectArgument_GetsPassedToHandler() { // Arrange var sut = FormatCommand.CreateCommandLineOptions(); var handlerWasCalled = false; sut.Handler = CommandHandler.Create(new TestCommandHandlerDelegate(TestCommandHandler)); void TestCommandHandler( string workspace, bool folder, string verbosity, bool check, string[] include, string[] exclude, string report, bool includeGenerated) { handlerWasCalled = true; Assert.Equal("workspaceValue", workspace); Assert.Equal("detailed", verbosity); }; // Act var result = sut.Invoke(new[] { "--verbosity", "detailed", "workspace" }); // Assert Assert.True(handlerWasCalled); }
public void CommandLine_OptionsAreParsedCorrectly() { // Arrange var sut = FormatCommand.CreateCommandLineOptions(); // Act var result = sut.Parse(new[] { "--folder", "folder", "--workspace", "workspace", "--include", "include1", "include2", "--exclude", "exclude1", "exclude2", "--check", "--report", "report", "--verbosity", "verbosity", "--include-generated" }); // Assert Assert.Equal(1, result.Errors.Count); // folder and workspace can not be combined Assert.Equal(0, result.UnmatchedTokens.Count); Assert.Equal(0, result.UnparsedTokens.Count); Assert.Equal("folder", result.ValueForOption("folder")); Assert.Equal("workspace", result.ValueForOption("workspace")); Assert.Collection(result.ValueForOption <IEnumerable <string> >("include"), i0 => Assert.Equal("include1", i0), i1 => Assert.Equal("include2", i1)); Assert.Collection(result.ValueForOption <IEnumerable <string> >("exclude"), i0 => Assert.Equal("exclude1", i0), i1 => Assert.Equal("exclude2", i1)); Assert.True(result.ValueForOption <bool>("check")); Assert.Equal("report", result.ValueForOption("report")); Assert.Equal("verbosity", result.ValueForOption("verbosity")); Assert.True(result.ValueForOption <bool>("include-generated")); }
public void CommandLine_BinaryLog_FailsIfFolderIsSpecified() { // Arrange var sut = FormatCommand.CreateCommandLineOptions(); // Act var result = sut.Parse(new[] { "--folder", "--binarylog" }); // Assert Assert.Equal(1, result.Errors.Count); }
public void CommandLine_AnalyzerOptions_CanSpecifyBothWithDefaults() { // Arrange var sut = FormatCommand.CreateCommandLineOptions(); // Act var result = sut.Parse(new[] { "--fix-analyzers", "--fix-style" }); // Assert Assert.Equal(0, result.Errors.Count); }
public void CommandLine_Diagnostics_FailsIfDiagnosticNoSpecified() { // Arrange var sut = FormatCommand.CreateCommandLineOptions(); // Act var result = sut.Parse(new[] { "--diagnostics" }); // Assert Assert.Equal(1, result.Errors.Count); }
public void CommandLine_ProjectWorkspaceAndFolderCanNotBeCombined2() { // Arrange var sut = FormatCommand.CreateCommandLineOptions(); // Act var result = sut.Parse(new[] { "--workspace", "workspace", "--folder", "folder" }); // Assert Assert.Equal(1, result.Errors.Count); }
public void CommandLine_InvalidArgumentsDontCrashTheValidators() { // Arrange var sut = FormatCommand.CreateCommandLineOptions(); // Act var result = sut.Parse(new[] { "--workspace", "workspace1", "--workspace", "workspace2" }); // Assert Assert.Equal(2, result.Errors.Count); }
public void CommandLine_ProjectArgument_FailesIfSpecifiedTwice() { // Arrange var sut = FormatCommand.CreateCommandLineOptions(); // Act var result = sut.Parse(new[] { "projectValue1", "projectValue2" }); // Assert Assert.Equal(1, result.Errors.Count); }
public void CommandLine_ProjectArgumentAndFolderCanNotBeCombined1() { // Arrange var sut = FormatCommand.CreateCommandLineOptions(); // Act var result = sut.Parse(new[] { "projectValue", "--folder", "folder" }); // Assert Assert.Equal(1, result.Errors.Count); }
public void CommandLine_Diagnostics_DoesNotFailIfMultipleDiagnosticAreSpecified() { // Arrange var sut = FormatCommand.CreateCommandLineOptions(); // Act var result = sut.Parse(new[] { "--diagnostics", "RS0016", "RS0017", "RS0018" }); // Assert Assert.Equal(0, result.Errors.Count); }
public void CommandLine_FolderValidation_FailsIfFixStyleSpecified() { // Arrange var sut = FormatCommand.CreateCommandLineOptions(); // Act var result = sut.Parse(new[] { "--folder", "--fix-style" }); // Assert Assert.Equal(1, result.Errors.Count); }
public void CommandLine_ProjectArgument_Simple() { // Arrange var sut = FormatCommand.CreateCommandLineOptions(); // Act var result = sut.Parse(new[] { "projectValue" }); // Assert Assert.Equal(0, result.Errors.Count); Assert.Equal("projectValue", result.CommandResult.GetArgumentValueOrDefault("project")); }
public void CommandLine_ProjectArgument_Simple() { // Arrange var sut = FormatCommand.CreateCommandLineOptions(); // Act var result = sut.Parse(new[] { "workspaceValue" }); // Assert Assert.Equal(0, result.Errors.Count); Assert.Equal("workspaceValue", result.ValueForArgument("workspace")); }
public void CommandLine_BinaryLog_DoesNotFailIfPathIsSpecified() { // Arrange var sut = FormatCommand.CreateCommandLineOptions(); // Act var result = sut.Parse(new[] { "--binarylog", "log" }); // Assert Assert.Equal(0, result.Errors.Count); Assert.True(result.WasOptionUsed("--binarylog")); }
public void CommandLine_ProjectArgument_WithOption_AfterArgument() { // Arrange var sut = FormatCommand.CreateCommandLineOptions(); // Act var result = sut.Parse(new[] { "projectValue", "--verbosity", "verbosity" }); // Assert Assert.Equal(0, result.Errors.Count); Assert.Equal("projectValue", result.CommandResult.GetArgumentValueOrDefault("project")); Assert.Equal("verbosity", result.ValueForOption("verbosity")); }
public void CommandLine_ProjectArgument_WithOption_BeforeArgument() { // Arrange var sut = FormatCommand.CreateCommandLineOptions(); // Act var result = sut.Parse(new[] { "--verbosity", "detailed", "workspaceValue" }); // Assert Assert.Equal(0, result.Errors.Count); Assert.Equal("workspaceValue", result.CommandResult.GetArgumentValueOrDefault("workspace")); Assert.Equal("detailed", result.ValueForOption("verbosity")); }
// If this test fails that means FormatCommand options have changed, ensure the FormatCommand.Handler has been updated to match. public async Task CommandLine_AllArguments_Bind() { // Arrange var uniqueExitCode = 143; var sut = FormatCommand.CreateCommandLineOptions(); sut.Handler = CommandHandler.Create(new FormatCommand.Handler(TestRun)); Task <int> TestRun( string workspace, bool folder, bool fixWhitespace, string fixStyle, string fixAnalyzers, string verbosity, bool check, string[] include, string[] exclude, string report, bool includeGenerated, IConsole console = null) { Assert.Equal("./src", workspace); Assert.False(folder); Assert.True(fixWhitespace); Assert.Equal("warn", fixStyle); Assert.Equal("info", fixAnalyzers); Assert.Equal("diag", verbosity); Assert.True(check); Assert.Equal(new[] { "*.cs" }, include); Assert.Equal(new[] { "*.vb" }, exclude); Assert.Equal("report.json", report); Assert.True(includeGenerated); return(Task.FromResult(uniqueExitCode)); }; var args = @" ./src --fix-whitespace --fix-style warn --fix-analyzers info --verbosity diag --check --include *.cs --exclude *.vb --report report.json --include-generated".Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); // Act var parseResult = sut.Parse(args); var result = await sut.InvokeAsync(args); // Assert Assert.Equal(0, parseResult.Errors.Count); Assert.Equal(uniqueExitCode, result); }