Ejemplo n.º 1
0
        public void DescribeParameterWithAliases_AliasesDescribed()
        {
            var parameters = CommandReflection.Describe <ArgumentWithAlias>().Arguments;

            ValidateParameterDescription <int>(
                parameters.First(),
                "MyProperty",
                'p');
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 8
0
 public void DescribeCommandOfWrongBaseType_Exception()
 {
     CommandReflection.Describe <CommandWithWrongBase>();
 }
Ejemplo n.º 9
0
        public void DescribeWithOneParameter_ParameterDescribed()
        {
            var parameters = CommandReflection.Describe <ArgumentAttributeCmd>().Arguments;

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

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