diff --git a/BenchtopParser/ProgramConfig.cs b/BenchtopParser/ProgramConfig.cs index 1bc25f6..b3999e2 100644 --- a/BenchtopParser/ProgramConfig.cs +++ b/BenchtopParser/ProgramConfig.cs @@ -21,6 +21,13 @@ namespace BenchtopParser { public Dictionary U = new Dictionary(); public Dictionary X = new Dictionary(); + public string Name() { + if (M != null && M["Name"] != null && M["Name"].value != null) { + return M["Name"].value; + } + return ""; + } + public void AddToGroup(String group, Configuration config) { // UGLY - but helpful later. // TODO: Find out what the config names are and MAKE A MAP @@ -40,17 +47,24 @@ namespace BenchtopParser { case "T": this.T.Add(name, config); break; case "U": this.U.Add(name, config); break; case "X": this.X.Add(name, config); break; + default: throw new Exception($"No group {group} configured. Please fix configuration"); } } } public class Configuration { - public String? name { get; set; } + public String name { get; set; } public String? value { get; set; } public String? unit { get; set; } public String? type { get; set; } //possible values are: a, c, f, i. Which I presume are Array, Characters, Float, Integer + public Configuration(string name, string? value, string? unit, string? type) { + this.name = name; + this.value = value; + this.unit = unit; + this.type = type; + } public Configuration(List config, String data) { String[] nameValue = data.Split("="); diff --git a/BenchtopParserTests/Program_Config_Tests.cs b/BenchtopParserTests/Program_Config_Tests.cs index 5db233b..a625d92 100644 --- a/BenchtopParserTests/Program_Config_Tests.cs +++ b/BenchtopParserTests/Program_Config_Tests.cs @@ -34,5 +34,19 @@ namespace BenchtopParserTests { Exception ex = Assert.Throws(delegate { new BenchtopParser.ProgramConfig("broken"); }); Assert.That(ex.Message, Is.EqualTo("Invalid Program Config, please provide an I28 Program Config file data")); } + + [Test] + public void Test_ProgramConfig_AddToGroup() { + // Adds the "namename" config to X group + BenchtopParser.Configuration config = new BenchtopParser.Configuration("namename", "b", "c", "d"); + String group = "x"; //testing force upper check too. + BenchtopParser.Program program = new BenchtopParser.Program(); + + program.ProgramNumber = "P1"; + program.AddToGroup(group, config); + + var check = program.X["namename"]; + Assert.That(check, Is.EqualTo(config)); + } } } \ No newline at end of file