public void EqualsTest(string type) { UnitArmor unitArmor = new UnitArmor() { Type = type, }; Assert.AreEqual(unitArmor, unitArmor); }
public void NotSameObjectTest() { UnitArmor unitArmor = new UnitArmor() { Type = "merc", }; Assert.AreNotEqual(new List <string>() { "asdf" }, unitArmor); }
public void NotEqualsTest(string type) { UnitArmor unitArmor = new UnitArmor() { Type = "merc", }; Assert.AreNotEqual(unitArmor, new UnitArmor() { Type = type, }); }
public void EqualsMethodTests() { UnitArmor unitArmor = new UnitArmor() { Type = "Hero", }; Assert.IsFalse(unitArmor.Equals((int?)null)); Assert.IsFalse(unitArmor.Equals(5)); Assert.IsTrue(unitArmor.Equals(obj: unitArmor)); }
public void OperatorEqualTest(string type, string type2) { UnitArmor unitArmor = new UnitArmor() { Type = type, }; UnitArmor unitArmor2 = new UnitArmor() { Type = type2, }; #pragma warning disable SA1131 // Use readable conditions Assert.IsFalse(null ! == unitArmor2); #pragma warning restore SA1131 // Use readable conditions Assert.IsFalse(unitArmor2 == null !); Assert.IsTrue(null ! == (Announcer)null !); Assert.IsTrue(unitArmor == unitArmor2); Assert.AreEqual(unitArmor.GetHashCode(), unitArmor2 !.GetHashCode()); }
/// <summary> /// Sets the <see cref="Unit"/>'s armor data. /// </summary> /// <param name="element">The <see cref="JsonElement"/> to read from.</param> /// <param name="unit">The data to be set from <paramref name="element"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="unit"/> is <see langword="null"/>.</exception> protected virtual void SetUnitArmor(JsonElement element, Unit unit) { if (unit is null) { throw new ArgumentNullException(nameof(unit)); } if (element.TryGetProperty("armor", out JsonElement armorElement)) { foreach (JsonProperty armorProperty in armorElement.EnumerateObject()) { UnitArmor unitArmor = new UnitArmor { Type = armorProperty.Name, BasicArmor = armorProperty.Value.GetProperty("basic").GetInt32(), AbilityArmor = armorProperty.Value.GetProperty("ability").GetInt32(), SplashArmor = armorProperty.Value.GetProperty("splash").GetInt32(), }; unit.Armor.Add(unitArmor); } } }
public IEnumerable <UnitArmor> CreateArmorCollection(XElement armorLinkElement) { if (armorLinkElement is null) { throw new ArgumentNullException(nameof(armorLinkElement)); } string?armorLink = armorLinkElement.Attribute("value")?.Value; if (string.IsNullOrEmpty(armorLink)) { return(new List <UnitArmor>()); } XElement?armorElement = GameData.MergeXmlElements(_gameData.Elements("CArmor").Where(x => x.Attribute("id")?.Value == armorLink)); if (armorElement == null) { return(new List <UnitArmor>()); } HashSet <UnitArmor> armorList = new HashSet <UnitArmor>(); foreach (XElement armorSetElement in armorElement.Elements()) { string?index = armorSetElement.Attribute("index")?.Value; if (string.IsNullOrEmpty(index)) { continue; } UnitArmor unitArmor = new UnitArmor { Type = index, }; foreach (XElement armorMitigationTableElement in armorSetElement.Elements("ArmorMitigationTable")) { string type = armorMitigationTableElement.Attribute("index")?.Value ?? string.Empty; string?value = armorMitigationTableElement.Attribute("value")?.Value; if (type.Equals("basic", StringComparison.OrdinalIgnoreCase) && int.TryParse(value, out int valueInt)) { unitArmor.BasicArmor = valueInt; } else if (type.Equals("ability", StringComparison.OrdinalIgnoreCase) && int.TryParse(value, out valueInt)) { unitArmor.AbilityArmor = valueInt; } else if (type.Equals("splash", StringComparison.OrdinalIgnoreCase) && int.TryParse(value, out valueInt)) { unitArmor.SplashArmor = valueInt; } } if (unitArmor.BasicArmor > 0 || unitArmor.AbilityArmor > 0 || unitArmor.SplashArmor > 0) { if (armorList.Contains(unitArmor)) { armorList.Remove(unitArmor); } armorList.Add(unitArmor); } } return(armorList); }