private static void ParseArmourTypeDefinition(string gameConstantsFilePath) { Debug.Assert(gameConstantsFilePath != null, nameof(gameConstantsFilePath) + " != null"); Debug.Assert(File.Exists(gameConstantsFilePath), nameof(gameConstantsFilePath) + " must exist"); XDocument gameConstantsFile = XDocument.Load(gameConstantsFilePath); Debug.Assert(gameConstantsFile.Root != null, "gameConstantsFile.Root != null"); foreach (XElement xElement in gameConstantsFile.Root.Elements()) { if (!xElement.Name.ToString().Equals(Tags.ARMOR_TYPES, StringComparison.InvariantCultureIgnoreCase)) { continue; } List <Armour> damages = ArmourUtility.ParseFromString(xElement.Value); foreach (Armour damage in damages) { if (GlobalStore.ARMOUR_REGISTRY.Contains(damage)) { Debug.Assert(damage != null, nameof(commons.damage) + " != null"); Log.Warning( $"Found duplicated damage type definition \"{damage.Name}\" was previously defined."); continue; } GlobalStore.ARMOUR_REGISTRY.Add(damage); } break; } }
public void ParseFromString_Test() { List <Armour> l = ArmourUtility.ParseFromString(ARMOUR_STRING); Assert.IsNotNull(l); Assert.IsTrue(l.Any()); Assert.AreEqual(53, l.Count); }
public void ParseFromString_TestNullEmptyOrWhitespace() { List <Armour> l0 = ArmourUtility.ParseFromString(null); Assert.IsNotNull(l0); Assert.IsFalse(l0.Any()); List <Armour> l1 = ArmourUtility.ParseFromString(string.Empty); Assert.IsNotNull(l1); Assert.IsFalse(l1.Any()); List <Armour> l2 = ArmourUtility.ParseFromString("\n \t\r\n"); Assert.IsNotNull(l2); Assert.IsFalse(l2.Any()); }