コード例 #1
0
        public void FormattingThrowsOnNonCommandGroup()
        {
            var    argType = new CommandGroupArgumentType(typeof(CommandGroup <SimpleCommandType>));
            Action a       = () => argType.Format(3);

            a.Should().Throw <InvalidCastException>();
        }
コード例 #2
0
        public void SimpleCompletionWorks()
        {
            var argType = new CommandGroupArgumentType(typeof(CommandGroup <SimpleCommandType>));

            argType.GetCompletions(new ArgumentCompletionContext(), "N")
            .Should().ContainSingle()
            .And.Equal(nameof(SimpleCommandType.Nested));
        }
コード例 #3
0
        public void FormattingThrowsOnNoSelection()
        {
            var argType = new CommandGroupArgumentType(typeof(CommandGroup <SimpleCommandType>));

            var    group = new CommandGroup <SimpleCommandType>(null);
            Action a     = () => argType.Format(group);

            a.Should().Throw <ArgumentOutOfRangeException>();
        }
コード例 #4
0
        public void FormattingWorksOnSelection()
        {
            var argType = new CommandGroupArgumentType(typeof(CommandGroup <SimpleCommandType>));
            var group   = new CommandGroup <SimpleCommandType>(null)
            {
                Selection = SimpleCommandType.Nested
            };

            argType.Format(group).Should().Be(nameof(SimpleCommandType.Nested));
        }
コード例 #5
0
        public void TestThatDependentTypesAreCorrect()
        {
            var argType = new CommandGroupArgumentType(typeof(CommandGroup <SimpleCommandType>));

            argType.DependentTypes.Should().ContainSingle();

            var dependentType = argType.DependentTypes.First();
            var enumType      = dependentType.Should().BeAssignableTo <IEnumArgumentType>().Which;

            enumType.Type.Should().Be(typeof(SimpleCommandType));
        }
コード例 #6
0
        public void ParsingTopLevelLeafCommandSucceeds()
        {
            var argType = new CommandGroupArgumentType(typeof(CommandGroup <SimpleCommandType>));

            argType.TryParse(ArgumentParseContext.Default, "Foo", out object result).Should().BeTrue();
            var group = result.Should()
                        .BeOfType <CommandGroup <SimpleCommandType> >()
                        .Which;

            group.HasSelection.Should().BeTrue();
            group.Selection.Should().Be(SimpleCommandType.Foo);
            group.Execute().Should().Be(CommandResult.Success);
            group.InstantiatedCommand
            .Should().NotBeNull()
            .And.BeOfType <FooCommand>()
            .Which.CallCount.Should().Be(1);
        }
コード例 #7
0
        public void ParsingNestedGroupCommandSucceeds()
        {
            var argType = new CommandGroupArgumentType(typeof(CommandGroup <SimpleCommandType>));

            argType.TryParse(ArgumentParseContext.Default, "Nested", out object result).Should().BeTrue();
            var group = result.Should()
                        .BeOfType <CommandGroup <SimpleCommandType> >()
                        .Which;

            group.HasSelection.Should().BeTrue();
            group.Selection.Should().Be(SimpleCommandType.Nested);

            var nestedGroup = group.InstantiatedCommand
                              .Should().NotBeNull()
                              .And.BeAssignableTo <ICommandGroup>()
                              .Which;

            nestedGroup.HasSelection.Should().BeFalse();
            nestedGroup.ExecuteAsync(CancellationToken.None).Result.Should().Be(CommandResult.UsageError);
        }
コード例 #8
0
        public void ConstructorThrowsWhenInnerTypeIsNotEnum()
        {
            Action a = () => { var x = new CommandGroupArgumentType(typeof(CommandGroup <Guid>)); };

            a.Should().Throw <ArgumentOutOfRangeException>();
        }
コード例 #9
0
        public void ConstructorThrowsOnNonCommandGroupType()
        {
            Action a = () => { var x = new CommandGroupArgumentType(typeof(List <int>)); };

            a.Should().Throw <ArgumentOutOfRangeException>();
        }
コード例 #10
0
        public void ConstructorThrowsOnDifferentArityGenericType()
        {
            Action a = () => { var x = new CommandGroupArgumentType(typeof(Tuple <int, int>)); };

            a.Should().Throw <ArgumentOutOfRangeException>();
        }
コード例 #11
0
        public void ParsingThrowsOnInvalidCommand()
        {
            var argType = new CommandGroupArgumentType(typeof(CommandGroup <SimpleCommandType>));

            argType.TryParse(ArgumentParseContext.Default, "NotACommand", out object result).Should().BeFalse();
        }
コード例 #12
0
        public void DisplayNameIsCorrect()
        {
            var argType = new CommandGroupArgumentType(typeof(CommandGroup <SimpleCommandType>));

            argType.DisplayName.Should().Be(nameof(SimpleCommandType));
        }
コード例 #13
0
        public void ConstructorThrowsOnNonGenericType()
        {
            Action a = () => { var x = new CommandGroupArgumentType(typeof(int)); };

            a.ShouldThrow <ArgumentOutOfRangeException>();
        }