Exemplo n.º 1
0
        public void OptionBuilder_CreateOption_Command_Found_No_Options()
        {
            string expectedCommand    = "Storage";
            string expectedSubCommand = "GetData";

            int expectedNumberOfOptions = 0;

            string environmentSetting = $"{{\"UseLiveClient\": \"True\"}}";
            NullLogger <Microsoft.Extensions.Logging.ILogger> logger = new NullLogger <Microsoft.Extensions.Logging.ILogger>();

            BuildEnvironment(environmentSetting);

            CfgCommand    command    = TestDataBuilder.CreateCfgCommand(expectedCommand);
            CfgSubCommand subCommand = TestDataBuilder.CreateCfgSubCommand(expectedSubCommand);

            command.SubCommands.Add(subCommand);

            CfgCommandList commandList = new CfgCommandList();

            commandList.Commands = new List <CfgCommand>();
            commandList.Commands.Add(command);

            OptionBuilder builder = OptionBuilder.Instance(logger);

            builder.CfgCommands = commandList;

            GetDataHandler handler = new GetDataHandler(new NullLogger <GetDataHandler>());

            List <IOption> selectableOptions = builder.BuildAvailableOptions(handler);

            Assert.AreEqual(expectedNumberOfOptions, selectableOptions.Count);
        }
Exemplo n.º 2
0
        public static CfgSubCommand CreateCfgSubCommand(string subCommandName)
        {
            CfgSubCommand subCommand = new CfgSubCommand()
            {
                Name    = subCommandName,
                Options = new List <CfgOption>()
            };

            return(subCommand);
        }
Exemplo n.º 3
0
        public void OptionBuilder_CreateOption_Command_Found_One_Option()
        {
            string expectedCommand     = "Storage";
            string expectedSubCommand  = "GetData";
            string expectedOption      = "TestOption";
            string expectedDataType    = "string";
            string expectedDescription = "Option test description";
            string expectedApiName     = "TestApiName";

            int expectedNumberOfOptions = 1;

            string environmentSetting = $"{{\"UseLiveClient\": \"True\"}}";
            NullLogger <Microsoft.Extensions.Logging.ILogger> logger = new NullLogger <Microsoft.Extensions.Logging.ILogger>();

            BuildEnvironment(environmentSetting);

            CfgCommand    command    = TestDataBuilder.CreateCfgCommand(expectedCommand);
            CfgSubCommand subCommand = TestDataBuilder.CreateCfgSubCommand(expectedSubCommand);

            command.SubCommands.Add(subCommand);
            CfgOption option = TestDataBuilder.CreateCfgOption(expectedOption, expectedDataType, expectedDescription, expectedApiName);

            subCommand.Options.Add(option);

            CfgCommandList commandList = new CfgCommandList();

            commandList.Commands = new List <CfgCommand>();
            commandList.Commands.Add(command);

            OptionBuilder builder = OptionBuilder.Instance(logger);

            builder.CfgCommands = commandList;

            GetDataHandler handler = new GetDataHandler(new NullLogger <GetDataHandler>());

            List <IOption> selectableOptions = builder.BuildAvailableOptions(handler);

            Assert.AreEqual(expectedNumberOfOptions, selectableOptions.Count);
            IOption selectableOption = selectableOptions[0];

            Assert.AreEqual(expectedOption, selectableOption.Name);
            Assert.AreEqual(expectedDescription, selectableOption.Description);
            Assert.AreEqual(expectedApiName, selectableOption.ApiName);
            Assert.IsFalse(selectableOption.IsAssigned);
            Assert.IsInstanceOfType(selectableOption, typeof(NumberOption <string>));
        }
Exemplo n.º 4
0
        /// <summary>
        ///  Builds the parameters that can be used by a sub command.
        /// </summary>
        /// <param name="commandHandler">The SubCommand for which the parameters are build</param>
        /// <returns>List of sub command parameters</returns>
        public List <IOption> BuildAvailableOptions(ISubCommandHandler commandHandler)
        {
            List <IOption> subCommandOptions = new List <IOption>();

            // the defintion file shall be only be read at startup
            if (_instance.CfgCommands == null)
            {
                _instance.LoadCommandFile();
            }

            if (CfgCommands.Commands == null || CfgCommands.Commands.Count == 0)
            {
                _logger.LogError("There is not define any cli commands, check command definition file");
            }
            else
            {
                // find defined sub command with options and build an option list
                CfgSubCommand cfgCubCommand = CfgCommands.Commands.FirstOrDefault(x => x.Name == commandHandler.CommandProvider)?
                                              .SubCommands.FirstOrDefault(y => y.Name == commandHandler.Name);

                if (cfgCubCommand != null && cfgCubCommand.Options != null)
                {
                    List <CfgOption> cfgOptions = cfgCubCommand.Options;

                    foreach (CfgOption cfgOption in cfgOptions)
                    {
                        IOption option = CreateOption(cfgOption);
                        if (option != null)
                        {
                            subCommandOptions.Add(CreateOption(cfgOption));
                        }
                    }
                }
            }

            return(subCommandOptions);
        }