public static CfgOption CreateCfgOption(string name, string dataType, string description, string apiName) { CfgOption option = new CfgOption() { Name = name, DataType = dataType, Description = description, Apiname = apiName }; return(option); }
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>)); }
private static IOption CreateOption(CfgOption cfgOption) { Type t = GetSystemType(cfgOption.DataType, out var baseType); // create option according to defined type if (t != null) { var combinedType = baseType.MakeGenericType(t); IOption option = (IOption)Activator.CreateInstance(combinedType); option.Description = cfgOption.Description; option.Name = cfgOption.Name; option.IsAssigned = false; option.ApiName = cfgOption.Apiname; return(option); } else { _logger.LogError($"The defined data type: {cfgOption.DataType} for option: {cfgOption.Name} is not valid"); return(null); } }