예제 #1
0
        public void DescribeParameterWithAliases_AliasesDescribed()
        {
            var parameters = CommandReflection.Describe <ArgumentWithAlias>().Arguments;

            ValidateParameterDescription <int>(
                parameters.First(),
                "MyProperty",
                'p');
        }
예제 #2
0
        private CommandInfo ValidateCommandDescription <T>(
            string name = null)
        {
            var info = CommandReflection.Describe <T>();

            info.Should().NotBeNull();
            info.Type.Should().Be <T>();
            info.Description.Should().BeNull();
            info.Name.Should().Be(name ?? typeof(T).Name);
            info.Arguments.Should().BeEmpty();

            return(info);
        }
예제 #3
0
        public void DescribeCommandInvalidExecuteReturn_Exception()
        {
            try
            {
                CommandReflection.Describe <InvalidExecuteReturn>();
            }
            catch (CommandReflectionException ex)
            {
                ex.InnerException.Should().NotBeNull();
                ex.InnerException.Message.Should().Be("the Execute function must return an int.");

                throw ex;
            }
        }
예제 #4
0
        public void DescribeCommandWithNoExecute_Exception()
        {
            try
            {
                CommandReflection.Describe <NoExecute>();
            }
            catch (CommandReflectionException ex)
            {
                ex.InnerException.Should().NotBeNull();
                ex.InnerException.Message.Should().Contain("The command must implement a public Execute function");

                throw ex;
            }
        }
예제 #5
0
        public void DescribeCommandInvalidExecuteParametersAsync_Exception()
        {
            try
            {
                CommandReflection.Describe <InvalidExecuteParametersAsync>();
            }
            catch (CommandReflectionException ex)
            {
                ex.InnerException.Should().NotBeNull();
                ex.InnerException.Message.Should().Contain("The Execute function must accept a CommandExecutionContext parameter");

                throw ex;
            }
        }
예제 #6
0
        public void DescribeCommandInvalidExecuteReturnAsync_Exception()
        {
            try
            {
                CommandReflection.Describe <InvalidExecuteReturnAsync>();
            }
            catch (CommandReflectionException ex)
            {
                ex.InnerException.Should().NotBeNull();
                ex.InnerException.Message.Should().Contain("The async Execute function must return a Task<int>");

                throw ex;
            }
        }
예제 #7
0
        public void RegisterCommand(Type type)
        {
            // describe command

            var info = CommandReflection.Describe(type);

            // check for duplicate command

            var duplicateCmd = _commands.Where(c => c.Name.Equals(info.Name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

            if (duplicateCmd != null)
            {
                throw new ArgumentException($"Cannot register command type {type.FullName} because a command with the same name is already registered :: {duplicateCmd.Type.FullName}");
            }

            _commands.Add(info);
        }
예제 #8
0
 public void DescribeCommandOfWrongBaseType_Exception()
 {
     CommandReflection.Describe <CommandWithWrongBase>();
 }
예제 #9
0
        public void DescribeWithOneParameter_ParameterDescribed()
        {
            var parameters = CommandReflection.Describe <ArgumentAttributeCmd>().Arguments;

            ValidateParameterDescription <int>(parameters.First(), "MyName");
        }
예제 #10
0
        public void DescribeWithOneEmptyParameter_ParameterDescribed()
        {
            var parameters = CommandReflection.Describe <EmptyArgumentAttribute>().Arguments;

            ValidateParameterDescription <string>(parameters.First(), "TestArg");
        }