LaptopCommandTests.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Tests.EndToEnd.Infra;
  2. using Xunit.Abstractions;
  3. namespace Tests.EndToEnd.LaptopTests;
  4. [Collection("Yaml CLI tests")]
  5. public class LaptopCommandTests(TempYamlCliFixture fs, ITestOutputHelper outputHelper)
  6. : IClassFixture<TempYamlCliFixture> {
  7. private async Task<(string, string)> ExecuteAsync(params string[] args) {
  8. var output = await YamlCliTestHost.RunAsync(
  9. args,
  10. fs.Root,
  11. outputHelper,
  12. "config.yaml"
  13. );
  14. var yaml = await File.ReadAllTextAsync(Path.Combine(fs.Root, "config.yaml"));
  15. return (output, yaml);
  16. }
  17. [Fact]
  18. public async Task describe_outputs_expected_information() {
  19. await ExecuteAsync("laptops", "add", "lap01");
  20. await ExecuteAsync("laptops", "set", "lap01", "--model", "ThinkPad X1 Carbon");
  21. (var output, var _) = await ExecuteAsync("laptops", "describe", "lap01");
  22. Assert.Contains("lap01", output);
  23. }
  24. [Fact]
  25. public async Task help_commands_do_not_throw() {
  26. Assert.Contains("Manage Laptop computers", (await ExecuteAsync("laptops", "--help")).Item1);
  27. Assert.Contains("Add a new Laptop", (await ExecuteAsync("laptops", "add", "--help")).Item1);
  28. Assert.Contains("List all Laptops", (await ExecuteAsync("laptops", "list", "--help")).Item1);
  29. Assert.Contains("Retrieve a Laptop", (await ExecuteAsync("laptops", "get", "--help")).Item1);
  30. Assert.Contains("Show detailed information", (await ExecuteAsync("laptops", "describe", "--help")).Item1);
  31. Assert.Contains("Delete a Laptop", (await ExecuteAsync("laptops", "del", "--help")).Item1);
  32. Assert.Contains("Show a summarized hardware report",
  33. (await ExecuteAsync("laptops", "summary", "--help")).Item1);
  34. Assert.Contains("Display the dependency tree", (await ExecuteAsync("laptops", "tree", "--help")).Item1);
  35. // CPU help
  36. Assert.Contains("Manage CPUs", (await ExecuteAsync("laptops", "cpu", "--help")).Item1);
  37. Assert.Contains("Add a CPU", (await ExecuteAsync("laptops", "cpu", "add", "--help")).Item1);
  38. // Drives help
  39. Assert.Contains("Manage storage drives", (await ExecuteAsync("laptops", "drives", "--help")).Item1);
  40. // GPU help
  41. Assert.Contains("Manage GPUs", (await ExecuteAsync("laptops", "gpu", "--help")).Item1);
  42. }
  43. }