12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- // Licensed to the .NET Foundation under one or more agreements.
- // The .NET Foundation licenses this file to you under the MIT license.
- using Microsoft.DotNet.Cli.Utils;
- using Microsoft.DotNet.CommandFactory;
- namespace Microsoft.DotNet.Tests
- {
- public class CommandObjectTests : SdkTest
- {
- public CommandObjectTests(ITestOutputHelper output) : base(output)
- {
- }
- [Fact]
- public void WhenItCannotResolveCommandItThrows()
- {
- Action a = () => { CommandFactoryUsingResolver.Create(new ResolveNothingCommandResolverPolicy(), "non-exist-command", Array.Empty<string>()); };
- a.Should().Throw<CommandUnknownException>();
- }
- [Fact]
- public void WhenItCannotResolveCommandButCommandIsInListOfKnownToolsItThrows()
- {
- Action a = () => { CommandFactoryUsingResolver.Create(new ResolveNothingCommandResolverPolicy(), "non-exist-command", Array.Empty<string>()); };
- a.Should().Throw<CommandUnknownException>();
- }
- private class ResolveNothingCommandResolverPolicy : ICommandResolverPolicy
- {
- public CompositeCommandResolver CreateCommandResolver()
- {
- var compositeCommandResolver = new CompositeCommandResolver();
- compositeCommandResolver.AddCommandResolver(new ResolveNothingCommandResolver());
- return compositeCommandResolver;
- }
- }
- private class ResolveNothingCommandResolver : ICommandResolver
- {
- public CommandSpec Resolve(CommandResolverArguments arguments)
- {
- return null;
- }
- }
- }
- }
|