From 987972828272ce745d2dcdb70e348fe18e7fd51c Mon Sep 17 00:00:00 2001 From: Mercanuis Date: Sun, 10 Nov 2019 16:17:47 +0900 Subject: [PATCH] Clean up of TODOs, adding tests to DialogEngineTests --- DialogEngine/DialogGenerator.cs | 4 +-- DialogEngine/DialogManager.cs | 2 +- .../Printers/AbstractDialogPrinter.cs | 3 +- DialogEngine/Printers/Custom/BattlePrinter.cs | 3 +- DialogEngine/Printers/Custom/CustomPrinter.cs | 2 +- DialogEngine/Utilities/Utilities.cs | 4 +-- ...gGeneratorTest.cs => DialogEngineTests.cs} | 30 ++++++++++++++----- DialogEngineTests/DialogEngineTests.csproj | 3 ++ DialogEngineTests/TestData/InvalidFile.txt | 2 ++ Errors/{Errors.cs => DialogException.cs} | 0 Errors/{UtilErrors.cs => UtilityException.cs} | 10 +++---- 11 files changed, 40 insertions(+), 23 deletions(-) rename DialogEngineTests/{DialogGeneratorTest.cs => DialogEngineTests.cs} (78%) create mode 100644 DialogEngineTests/TestData/InvalidFile.txt rename Errors/{Errors.cs => DialogException.cs} (100%) rename Errors/{UtilErrors.cs => UtilityException.cs} (63%) diff --git a/DialogEngine/DialogGenerator.cs b/DialogEngine/DialogGenerator.cs index b654f32..ddaa47a 100644 --- a/DialogEngine/DialogGenerator.cs +++ b/DialogEngine/DialogGenerator.cs @@ -48,9 +48,9 @@ private void GenerateDialogMap() { printerType = DialogConstants.GetPrinterType(line); } - catch(UtilErrors err) + catch (UtilityException err) { - Console.WriteLine("Error Occurred during type retrival: " + err.Message); + Console.WriteLine("Error Occurred during type retrival: " + err.Message); printerType = DialogConstants.GENERAL_PRINTER; } diff --git a/DialogEngine/DialogManager.cs b/DialogEngine/DialogManager.cs index 2e2708c..d926960 100644 --- a/DialogEngine/DialogManager.cs +++ b/DialogEngine/DialogManager.cs @@ -41,7 +41,7 @@ public IDialogPrinter GetForScript(string filePath) printer = new RepeatingPrinter(gen.GetLines()); break; case BATTLE: - printer = new BattlePrinter(gen.GetLines()); + printer = new CustomPrinter(gen.GetLines()); break; } } diff --git a/DialogEngine/Printers/AbstractDialogPrinter.cs b/DialogEngine/Printers/AbstractDialogPrinter.cs index e30d1f2..c0a1d7e 100644 --- a/DialogEngine/Printers/AbstractDialogPrinter.cs +++ b/DialogEngine/Printers/AbstractDialogPrinter.cs @@ -1,7 +1,6 @@ namespace DialogEngine.Printers { - //TODO: Should this be public or internal - public abstract class AbstractDialogPrinter : IDialogPrinter + internal abstract class AbstractDialogPrinter : IDialogPrinter { public virtual string GetDialogLine() { diff --git a/DialogEngine/Printers/Custom/BattlePrinter.cs b/DialogEngine/Printers/Custom/BattlePrinter.cs index 817d7a0..afee753 100644 --- a/DialogEngine/Printers/Custom/BattlePrinter.cs +++ b/DialogEngine/Printers/Custom/BattlePrinter.cs @@ -2,7 +2,8 @@ namespace DialogEngine.Printers.Custom { - public class BattlePrinter : CustomPrinter + //TODO: need to determine how to best use this. Right now this is only an extension of the CustomPrinter. Does this need to be moved to the BattleEngine? + class BattlePrinter : CustomPrinter { const int DAMAGE_TAKEN_TEXT = 0; const int DAMAGE_DEALT_TEXT = 1; diff --git a/DialogEngine/Printers/Custom/CustomPrinter.cs b/DialogEngine/Printers/Custom/CustomPrinter.cs index 38b3708..58b44c8 100644 --- a/DialogEngine/Printers/Custom/CustomPrinter.cs +++ b/DialogEngine/Printers/Custom/CustomPrinter.cs @@ -9,7 +9,7 @@ namespace DialogEngine.Printers.Custom /// and then use specified dialog to format the parameters correctly. /// /// - public class CustomPrinter : AbstractDialogPrinter + class CustomPrinter : AbstractDialogPrinter { private readonly Dictionary dialogMap; diff --git a/DialogEngine/Utilities/Utilities.cs b/DialogEngine/Utilities/Utilities.cs index c891a99..2da5d67 100644 --- a/DialogEngine/Utilities/Utilities.cs +++ b/DialogEngine/Utilities/Utilities.cs @@ -6,7 +6,7 @@ class Utilities } - class DialogConstants + public class DialogConstants { public const string GENERAL_PRINTER = "General"; public const string REPEATING_PRINTER = "Repeating"; @@ -28,7 +28,7 @@ public static string GetPrinterType(string fileLine) return BATTLE_PRINTER; } - throw new UtilErrors("File type was not found"); + throw new UtilityException("File type was not found"); } } } diff --git a/DialogEngineTests/DialogGeneratorTest.cs b/DialogEngineTests/DialogEngineTests.cs similarity index 78% rename from DialogEngineTests/DialogGeneratorTest.cs rename to DialogEngineTests/DialogEngineTests.cs index 4c5f037..1bd6dac 100644 --- a/DialogEngineTests/DialogGeneratorTest.cs +++ b/DialogEngineTests/DialogEngineTests.cs @@ -1,5 +1,5 @@ using DialogEngine.Printers; -using DialogEngine.Printers.Custom; +using DialogEngine.Utilities; using Errors; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; @@ -9,13 +9,17 @@ namespace DialogEngine { [TestClass] - public class DialogGeneratorTest + public class DialogEngineTests { private readonly string FILEPATH = Path.Combine(Environment.CurrentDirectory, @"TestData\", "GeneralPrintFile.txt"); - private readonly string BAD_FILEPATH = Path.Combine(Environment.CurrentDirectory, @"TestData\", "BAD.txt"); private readonly string REPEATING_FILEPATH = Path.Combine(Environment.CurrentDirectory, @"TestData\", "RepeatingPrintFile.txt"); private readonly string BATTLE_FILEPATH = Path.Combine(Environment.CurrentDirectory, @"TestData\", "BattleText.txt"); + private readonly string BAD_FILEPATH = Path.Combine(Environment.CurrentDirectory, @"TestData\", "BAD.txt"); + private readonly string INVALID_FILE_PATH = Path.Combine(Environment.CurrentDirectory, @"TestData\", "Invalidfile.txt"); + + + [TestMethod] public void TestGenerator_BadFilePath() { @@ -81,20 +85,30 @@ public void TestRepeatingPrinter() public void TestBattlePrinter() { DialogManager mgmr = new DialogManager(); - BattlePrinter underTest = (BattlePrinter)mgmr.GetForScript(BATTLE_FILEPATH); + IDialogPrinter underTest = mgmr.GetForScript(BATTLE_FILEPATH); string[] dmgTakenParams = new string[] { "Terra", "25" }; - Assert.AreEqual("Terra takes 25 points of damage.", underTest.GetDamageTaken(dmgTakenParams)); + Assert.AreEqual("Terra takes 25 points of damage.", string.Format(underTest.GetDialogLine(0), dmgTakenParams)); string[] dmgDealtParams = new string[] { "Setzer", "Goblin", "12" }; - Assert.AreEqual("Setzer hits the Goblin for 12 points of damage.", underTest.GetDamageDealt(dmgDealtParams)); + Assert.AreEqual("Setzer hits the Goblin for 12 points of damage.", string.Format(underTest.GetDialogLine(1), dmgDealtParams)); string[] magDealtParams = new string[] { "Celes", "Ice", "Magitec Armor MkII", "150" }; - Assert.AreEqual("Celes casts Ice! The Magitec Armor MkII takes 150 points of damage.", underTest.GetMagicDamageDealt(magDealtParams)); + Assert.AreEqual("Celes casts Ice! The Magitec Armor MkII takes 150 points of damage.", string.Format(underTest.GetDialogLine(2), magDealtParams)); //Check to see if extra parameters are ignored, in case they're accidentially sent string[] dmgTakenParams2 = new string[] { "Terra", "25", "35" }; - Assert.AreEqual("Terra takes 25 points of damage.", underTest.GetDamageTaken(dmgTakenParams2)); + Assert.AreEqual("Terra takes 25 points of damage.", string.Format(underTest.GetDialogLine(0), dmgTakenParams2)); + } + + [TestMethod] + public void TestInvalidType() + { + DialogManager mgmr = new DialogManager(); + IDialogPrinter underTest = mgmr.GetForScript(INVALID_FILE_PATH); + Assert.AreEqual("This should be findable, but exception was thrown", underTest.GetDialogLine()); + Assert.AreEqual("____END____", underTest.GetDialogLine()); + } } } diff --git a/DialogEngineTests/DialogEngineTests.csproj b/DialogEngineTests/DialogEngineTests.csproj index e33585f..44bf189 100644 --- a/DialogEngineTests/DialogEngineTests.csproj +++ b/DialogEngineTests/DialogEngineTests.csproj @@ -24,6 +24,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/DialogEngineTests/TestData/InvalidFile.txt b/DialogEngineTests/TestData/InvalidFile.txt new file mode 100644 index 0000000..a275380 --- /dev/null +++ b/DialogEngineTests/TestData/InvalidFile.txt @@ -0,0 +1,2 @@ +DIALOG_TYPE=Invalid +This should be findable, but exception was thrown \ No newline at end of file diff --git a/Errors/Errors.cs b/Errors/DialogException.cs similarity index 100% rename from Errors/Errors.cs rename to Errors/DialogException.cs diff --git a/Errors/UtilErrors.cs b/Errors/UtilityException.cs similarity index 63% rename from Errors/UtilErrors.cs rename to Errors/UtilityException.cs index c77a13e..32dd9be 100644 --- a/Errors/UtilErrors.cs +++ b/Errors/UtilityException.cs @@ -1,23 +1,21 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Errors { - public class UtilErrors : Exception + public class UtilityException : Exception { private const string ERROR_MSG = "UtilityException"; /// /// Generic Constructor for UtilError /// - public UtilErrors() + public UtilityException() { } - public UtilErrors(string message) + public UtilityException(string message) : base(String.Format("{0}: {1}", ERROR_MSG, message)) - { + { } } }