LaptopCommandTests.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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", "drive", "--help")).Item1);
  40. // GPU help
  41. Assert.Contains("Manage GPUs", (await ExecuteAsync("laptops", "gpu", "--help")).Item1);
  42. // NIC help
  43. Assert.Contains("Manage network interface cards", (await ExecuteAsync("laptops", "nic", "--help")).Item1);
  44. Assert.Contains("Add a NIC to a Laptop", (await ExecuteAsync("laptops", "nic", "add", "--help")).Item1);
  45. Assert.Contains("Update a Laptop NIC", (await ExecuteAsync("laptops", "nic", "set", "--help")).Item1);
  46. Assert.Contains("Remove a NIC from a Laptop", (await ExecuteAsync("laptops", "nic", "del", "--help")).Item1);
  47. Assert.Contains("Rename a Laptop", (await ExecuteAsync("laptops", "rename", "--help")).Item1);
  48. }
  49. [Fact]
  50. public async Task rename_successfully_updates_name() {
  51. await ExecuteAsync("laptops", "add", "lap01");
  52. (var output, var yaml) = await ExecuteAsync("laptops", "rename", "lap01", "lap01-new");
  53. Assert.Equal("Laptop 'lap01' renamed to 'lap01-new'.\n", output);
  54. Assert.Contains("name: lap01-new", yaml);
  55. }
  56. }