GivenARootedCommandResolver.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. using Microsoft.DotNet.CommandFactory;
  4. namespace Microsoft.DotNet.Tests
  5. {
  6. public class GivenARootedCommandResolver
  7. {
  8. [Fact]
  9. public void It_returns_null_when_CommandName_is_null()
  10. {
  11. var rootedCommandResolver = new RootedCommandResolver();
  12. var commandResolverArguments = new CommandResolverArguments()
  13. {
  14. CommandName = null,
  15. CommandArguments = null
  16. };
  17. var result = rootedCommandResolver.Resolve(commandResolverArguments);
  18. result.Should().BeNull();
  19. }
  20. [Fact]
  21. public void It_returns_null_when_CommandName_is_not_rooted()
  22. {
  23. var rootedCommandResolver = new RootedCommandResolver();
  24. var commandResolverArguments = new CommandResolverArguments()
  25. {
  26. CommandName = "some/relative/path",
  27. CommandArguments = null
  28. };
  29. var result = rootedCommandResolver.Resolve(commandResolverArguments);
  30. result.Should().BeNull();
  31. }
  32. [Fact]
  33. public void It_returns_a_CommandSpec_with_CommandName_as_Path_when_CommandName_is_rooted()
  34. {
  35. var rootedCommandResolver = new RootedCommandResolver();
  36. var commandResolverArguments = new CommandResolverArguments()
  37. {
  38. CommandName = "/some/rooted/path",
  39. CommandArguments = null
  40. };
  41. var result = rootedCommandResolver.Resolve(commandResolverArguments);
  42. result.Should().NotBeNull();
  43. result.Path.Should().Be(commandResolverArguments.CommandName);
  44. }
  45. [Fact]
  46. public void It_escapes_CommandArguments_when_returning_a_CommandSpec()
  47. {
  48. var rootedCommandResolver = new RootedCommandResolver();
  49. var commandResolverArguments = new CommandResolverArguments()
  50. {
  51. CommandName = "/some/rooted/path",
  52. CommandArguments = new[] { "arg with space" }
  53. };
  54. var result = rootedCommandResolver.Resolve(commandResolverArguments);
  55. result.Should().NotBeNull();
  56. result.Path.Should().Be(commandResolverArguments.CommandName);
  57. result.Args.Should().Be("\"arg with space\"");
  58. }
  59. [Fact]
  60. public void It_returns_a_CommandSpec_with_Args_as_stringEmpty_when_returning_a_CommandSpec_and_CommandArguments_are_null()
  61. {
  62. var rootedCommandResolver = new RootedCommandResolver();
  63. var commandResolverArguments = new CommandResolverArguments()
  64. {
  65. CommandName = "/some/rooted/path",
  66. CommandArguments = null
  67. };
  68. var result = rootedCommandResolver.Resolve(commandResolverArguments);
  69. result.Should().NotBeNull();
  70. result.Path.Should().Be(commandResolverArguments.CommandName);
  71. result.Args.Should().Be(string.Empty);
  72. }
  73. }
  74. }