public void HelpArgs(string[] args) { var options = CommandLineOptions.Parse(args, _console); Assert.True(options.IsHelp); Assert.Contains("Usage: dotnet watch ", _console.GetOutput()); }
private string PrintDifference(string expected, string actual) { var testConsole = new TestConsole(); StringDiffer.PrintFirstDifference(expected, actual, testConsole); return(testConsole.GetOutput()); }
public void ShouldPrintStartGuessingMessage_ShowStartGuessingMessage() { var testConsole = new TestConsole("t", new [] { "t" }); var expected = "Enter a number between 1 & 100..\n"; View sut = new View(testConsole, null); sut.ShowStartGuessingMessage(); Assert.EndsWith(expected + "\n", testConsole.GetOutput()); }
public void ShouldPrintMenuMessage_ShowMenu() { var testConsole = new TestConsole("t", new [] { "t" }); var expected = "Hello, Would you like to start a New Game?\n 'p' = Play\n 'e' = Exit"; View sut = new View(testConsole, null); sut.ShowMenu(); Assert.EndsWith(expected + "\n", testConsole.GetOutput()); }
public void ShouldPrintErrorMessage_AskForAction() { var testConsole = new TestConsole("jhkjh", new [] { "" }); var expected = "Invalid choice, try again."; View sut = new View(testConsole, null); sut.AskForAction(); Assert.EndsWith(expected + "\n", testConsole.GetOutput()); }
public void ShouldPrintGuessTooLowMessage_ShowGameOutcome(int x, int y, int z) { var mockModel = new Mock <GuessModel>(x); var testConsole = new TestConsole("t", new [] { "test" }); var expected = $"Your guess is Too Low. Guesses left: ({z})"; View sut = new View(testConsole, mockModel.Object); sut.ShowGameOutcome(x, y, z); Assert.EndsWith(expected + "\n", testConsole.GetOutput()); }
public void ShouldPrintWinnerMessage_ShowGameOutcome(int x, int y, int z) { var mockModel = new Mock <GuessModel>(x); mockModel.Setup(m => m.HasWon()).Returns(true); var testConsole = new TestConsole("t", new [] { "test" }); var expected = $"Congrats!! You guessed it!! The right answer is {x}."; View sut = new View(testConsole, mockModel.Object); sut.ShowGameOutcome(x, y, z); Assert.EndsWith(expected + "\n", testConsole.GetOutput()); }
public void ShouldPrintOutOfGuessesMessage_ShowGameOutcome(int x, int y, int z) { var mockModel = new Mock <GuessModel>(x); mockModel.Setup(m => m.GetRemainingGuesses()).Returns(z); var testConsole = new TestConsole("t", new [] { "test" }); var expected = $"You Lost, this time!!"; View sut = new View(testConsole, mockModel.Object); sut.ShowGameOutcome(x, y, z); Assert.EndsWith(expected + "\n", testConsole.GetOutput()); }
public void WritesToStandardStreams() { var testConsole = new TestConsole(); var reporter = new ConsoleReporter(testConsole, verbose: true, quiet: false); // stdout reporter.Verbose("verbose"); Assert.Equal("verbose" + EOL, testConsole.GetOutput()); testConsole.Clear(); reporter.Output("out"); Assert.Equal("out" + EOL, testConsole.GetOutput()); testConsole.Clear(); reporter.Warn("warn"); Assert.Equal("warn" + EOL, testConsole.GetOutput()); testConsole.Clear(); // stderr reporter.Error("error"); Assert.Equal("error" + EOL, testConsole.GetError()); testConsole.Clear(); }
public async Task ConsoleCancelKey() { var console = new TestConsole(_output); var testAsset = _testAssetsManager.CopyTestAsset(AppName) .WithSource() .Path; using var watchableApp = new WatchableApp(testAsset, _output); using var app = new Program(console, testAsset); var run = app.RunAsync(new[] { "run" }); await console.CancelKeyPressSubscribed.TimeoutAfter(TimeSpan.FromSeconds(30)); console.ConsoleCancelKey(); var exitCode = await run.TimeoutAfter(TimeSpan.FromSeconds(30)); Assert.Contains("Shutdown requested. Press Ctrl+C again to force exit.", console.GetOutput()); Assert.Equal(0, exitCode); }
public void Error_MissingId(string id) { var project = Path.Combine(_fixture.CreateProject(id), "TestProject.csproj"); var secretManager = CreateProgram(); secretManager.RunInternal("list", "-p", project, "--verbose"); Assert.Contains(Resources.FormatError_ProjectMissingId(project), _console.GetOutput()); }
public async Task ConsoleCancelKey() { _tempDir .WithCSharpProject("testproj") .WithTargetFrameworks("netcoreapp5.0") .Dir() .WithFile("Program.cs") .Create(); using (var app = new Program(_console, _tempDir.Root)) { var run = app.RunAsync(new[] { "run" }); await _console.CancelKeyPressSubscribed.TimeoutAfter(TimeSpan.FromSeconds(30)); _console.ConsoleCancelKey(); var exitCode = await run.TimeoutAfter(TimeSpan.FromSeconds(30)); Assert.Contains("Shutdown requested. Press Ctrl+C again to force exit.", _console.GetOutput()); Assert.Equal(0, exitCode); } }
public void List_NoTokensForNewProject() { var project = Path.Combine(_fixture.CreateProject(), "TestProject.csproj"); var app = new Program(_console); app.Run(new[] { "list", "--project", project }); Assert.Contains("No JWTs created yet!", _console.GetOutput()); }