From 86bbb3067b3953084bc8fcb4da496250fc5d1b6d Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Mon, 25 Jul 2022 00:16:15 -0400 Subject: [PATCH] Add exception test --- BenchtopParser/Parser.cs | 3 +++ BenchtopParserTests/UnitTest1.cs | 8 +++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/BenchtopParser/Parser.cs b/BenchtopParser/Parser.cs index 1209f6f..e77da6a 100644 --- a/BenchtopParser/Parser.cs +++ b/BenchtopParser/Parser.cs @@ -6,6 +6,9 @@ foreach (var line in program_config.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) { var config_line = line.Split("\t").ToList(); + if (config_line.Count() < 2) { + throw new Exception("Invalid Program Config, please provide an I28 Program Config file data"); + } config_line.RemoveAt(0); // Remove random hex value config_line.RemoveAt(0); // Remove L column if (config_line[0].StartsWith("Start,")) { diff --git a/BenchtopParserTests/UnitTest1.cs b/BenchtopParserTests/UnitTest1.cs index 3eeec47..d0ce939 100644 --- a/BenchtopParserTests/UnitTest1.cs +++ b/BenchtopParserTests/UnitTest1.cs @@ -13,12 +13,10 @@ namespace BenchtopParserTests { Assert.IsNotNull(configs); } + [Test] public void Test_ProgramConfig_Throw_ErrorOrder() { - String program_config = File.ReadAllText( - Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Program Config.txt") - ); - var configs = BenchtopParser.Parser.I28_ProgramConfig(program_config); - Assert.IsNotNull(configs); + Exception ex = Assert.Throws(delegate { BenchtopParser.Parser.I28_ProgramConfig("broken"); }); + Assert.That(ex.Message, Is.EqualTo("Invalid Program Config, please provide an I28 Program Config file data")); } } } \ No newline at end of file