CommandObjectTests.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.Cli.Utils;
  4. using Microsoft.DotNet.CommandFactory;
  5. namespace Microsoft.DotNet.Tests
  6. {
  7. public class CommandObjectTests : SdkTest
  8. {
  9. public CommandObjectTests(ITestOutputHelper output) : base(output)
  10. {
  11. }
  12. [Fact]
  13. public void WhenItCannotResolveCommandItThrows()
  14. {
  15. Action a = () => { CommandFactoryUsingResolver.Create(new ResolveNothingCommandResolverPolicy(), "non-exist-command", Array.Empty<string>()); };
  16. a.Should().Throw<CommandUnknownException>();
  17. }
  18. [Fact]
  19. public void WhenItCannotResolveCommandButCommandIsInListOfKnownToolsItThrows()
  20. {
  21. Action a = () => { CommandFactoryUsingResolver.Create(new ResolveNothingCommandResolverPolicy(), "non-exist-command", Array.Empty<string>()); };
  22. a.Should().Throw<CommandUnknownException>();
  23. }
  24. private class ResolveNothingCommandResolverPolicy : ICommandResolverPolicy
  25. {
  26. public CompositeCommandResolver CreateCommandResolver()
  27. {
  28. var compositeCommandResolver = new CompositeCommandResolver();
  29. compositeCommandResolver.AddCommandResolver(new ResolveNothingCommandResolver());
  30. return compositeCommandResolver;
  31. }
  32. }
  33. private class ResolveNothingCommandResolver : ICommandResolver
  34. {
  35. public CommandSpec Resolve(CommandResolverArguments arguments)
  36. {
  37. return null;
  38. }
  39. }
  40. }
  41. }