{"id":17395896,"url":"https://github.com/christianrondeau/consolescenario","last_synced_at":"2025-07-18T16:06:25.853Z","repository":{"id":151710552,"uuid":"34550893","full_name":"christianrondeau/ConsoleScenario","owner":"christianrondeau","description":"An automated test fixture for .NET console applications","archived":false,"fork":false,"pushed_at":"2015-12-15T03:25:50.000Z","size":748,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T21:47:50.016Z","etag":null,"topics":["assertions","automation","testing"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/christianrondeau.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-25T01:55:41.000Z","updated_at":"2018-05-07T03:42:24.000Z","dependencies_parsed_at":"2023-06-08T12:45:55.193Z","dependency_job_id":null,"html_url":"https://github.com/christianrondeau/ConsoleScenario","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/christianrondeau/ConsoleScenario","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christianrondeau%2FConsoleScenario","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christianrondeau%2FConsoleScenario/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christianrondeau%2FConsoleScenario/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christianrondeau%2FConsoleScenario/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/christianrondeau","download_url":"https://codeload.github.com/christianrondeau/ConsoleScenario/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christianrondeau%2FConsoleScenario/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265791684,"owners_count":23829164,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assertions","automation","testing"],"created_at":"2024-10-16T12:04:01.330Z","updated_at":"2025-07-18T16:06:25.792Z","avatar_url":"https://github.com/christianrondeau.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ConsoleScenario\n\nAn automated test fixture for .NET console applications\n\n[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/ik4jo7xeia9xnada?svg=true)](https://ci.appveyor.com/project/christianrondeau/consolescenario)\n[![Join the chat at https://gitter.im/christianrondeau/ConsoleScenario](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/christianrondeau/ConsoleScenario?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n## Overview\n\nUsing ConsoleScenario, you can run a program, define a list of expectations and input so that your tests verify both the behavior and the output.\n\n```csharp\nScenarios.Create(\"myapp.exe\", \"-argument\")\n  .Expect(\"Welcome to my app!\")\n  .ExpectPrompt(\"Do you want to continue? (y/n)\")\n  .Input(\"y\")\n  .Expect(\"You selected 'yes'\")\n  .Run(),\n```\n\n## Fluent API\n\nThese are all the expectations and console interactions supported by ConsoleScenario. You can also create your own assertions and steps.\n\nMost functions also support a `TimeSpan` parameter to define a timeout, which will kill the process.\n\nMost expectations will fail if the error stream contains something.\n\n### Basic\n\n* `.Expect(\"This line should be present\")` insures that the next line is exactly this\n* `.Expect(\"Multiple\", \"Lines\", \"At\", \"Once\")` does the same thing as several back-to-back `Expect` calls\n* `.Expect(line =\u003e line.Contains(\"something\"))` allows providing a callback, receiving the line and returning whether the assertion is true\n* `.Any(5)` ignores the line content, as long as the console indeed returns a line\n\n### Prompts and input\n\n* `.ExpectPrompt(\"Enter your name:\")` is similar to `Expect`, but won't wait for the line break\n* `.Input(\"John Doe\")` sends the characters to the console\n\n### Remaining and exit\n\n* `.ExpectNothingElse()` will fail if the console outputs more lines\n* `.IgnoreRemaining()` will ignore everything the console outputs until it closes\n* `.ExpectExitCode(-1)` will fail if the console exit code is not the provided one\n* `.IgnoreExitCode()` will not verify the exit code\n\n### Error expectations\n\n* `.ExpectError(\"Input string invalid\")` will pass if the error stream contains that string\n\n### Waiting\n\n* `.Until(line =\u003e line.Contains(\"100%\"))` will check every line until the callback returns true\n\n### Extract and late bound\n\n* `.Extract(\"Job ID: (.+)\", values =\u003e jobId = values[0])` is a shortcut to run a regex and provide the values in the callback\n* `.Expect(() =\u003e \"Starting job \" + jobId)` is the same as `Expect` but allows resolving the string at runtime, allowing the usage of `Extract` variables\n\n## Extensibility\n\nThe general principle is that the console `Input`, `Output` and `Error` streams are being managed by the `ProcessRuntime` object, which is created and inject in `Scenario` by the `Scenarios` class for you.\n\nThe `Scenario` class simply executes `IScenarioStep` instances one by one until none are left.\n\n### The `Scenario` class\n\nThe `Scenario` class is the starting point to running assertions.\n\nYou can set the `ExpectedExitCode` property to null to ignore the exit code, or to your expected exit code.\n\nAdd steps using `AddStep(step)` and/or `AddSteps(steps)`.\n\nExecute `Run()` when you are ready to run all steps.\n\n### Using the existing steps\n\n* `ReadLineAssertionStep` will read a line, run it against an `IAssertion` and repeat if specified. Most expectations use this.\n* `ReadUntilStep` will read lines until the specified condition is true\n* `InputStep` will write the specified line in the `Input` stream\n* `ReadCharsStep` will read characters until the provided string has been reached\n* `ReadErrorLineAssertionStep` is similar to `ReadLineAssertionStep`, but checks in the `Error` stream\n\n### Implementing your own `IAssertion`\n\nYou can implement your own `IAssertion`, and add it to the `Scenario` steps.\n\nOnce you have implemented your assertion, call `scenario.AddStep(new ReadLineAssertion(myAssertion))` where `myAssertion` is your assertion instance.\n\nYou can return either `AssertionResult.Pass()` or `AssertionResult.Fail(\"Message\", \"The expected value\")`\n\nFor the fluent API, you can create your own `ScenarioExtensions` class, like this:\n\n```csharp\npublic static class ScenarioExtensions\n{\n\tpublic static IScenario Input(this IScenario scenario)\n\t{\n\t\tscenario.AddStep(new ReadLineAssertionStep(new MyAssertion()));\n\t\treturn scenario;\n\t}\n}\n```\n\n### Implementing your own `IScenarioStep`\n\nIf you need very advanced control of the flow of the assertion, you can implement your own `IScenarioStep`.\n\nYou have one function to implement, `void Run(IAsyncDuplexStreamHandler asyncDuplexStreamHandler, ref int lineIndex);`.\n\nIn your implementation, you should read from `asyncDuplexStreamHandler` as necessary, and increment `lineIndex` every time a line is read.\n\nIf your assertion fails, you can throw a new `ScenarioAssertionException`.\n\n## License\n\nCopyright (c) 2015 Christian Rondeau, [MIT License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristianrondeau%2Fconsolescenario","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchristianrondeau%2Fconsolescenario","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristianrondeau%2Fconsolescenario/lists"}