public void ToXMLTest() { AttackCollectionValue target = new AttackCollectionValue(); target.FromXML(LoadableXML); string expected = LoadableXML; string actual; actual = target.ToXML(); Assert.AreEqual(expected, actual); }
public void RemoveAttackTest1() { AttackCollectionValue target = new AttackCollectionValue(); target.FromXML(LoadableXML); AttackCollectionValue.AttackValue attack = null; bool expected = true; bool actual; int remainingCapabilityPercentage = 40; attack = target.GetCurrentAttacks()[1]; actual = target.RemoveAttack(attack); Assert.AreEqual(expected, actual); Assert.AreEqual(remainingCapabilityPercentage, target.GetCurrentAttacks()[1].percentageApplied); }
public void FromXMLTest() { AttackCollectionValue target = new AttackCollectionValue(); bool caughtException = false; try { target.FromXML(LoadableXML); } catch (System.Exception ex) { caughtException = true; } Assert.IsTrue(!caughtException, "Error creating FromXML"); Assert.IsTrue(target.GetCurrentAttacks().Count == 3, "Incorrect Amount of attacks populated"); Assert.IsTrue(target.GetCurrentPercentageApplied("Missile") == 100, "Incorrect Percentage Applied for Missile"); target.FromXML(""); Assert.IsTrue(target.GetCurrentAttacks().Count == 0, "Incorrect Amount of attacks populated"); Assert.IsTrue(target.GetCurrentPercentageApplied("Missile") == 0, "Incorrect Percentage Applied for Missile"); }
public void GetCurrentPercentageAppliedTest() { AttackCollectionValue target = new AttackCollectionValue(); string capabilityName = "Missile"; target.FromXML(LoadableXML); int expected = 100; int actual; actual = target.GetCurrentPercentageApplied(capabilityName); Assert.AreEqual(expected, actual); capabilityName = "Guns"; expected = 80; actual = target.GetCurrentPercentageApplied(capabilityName); Assert.AreEqual(expected, actual); capabilityName = "Nonexistant"; expected = 0; actual = target.GetCurrentPercentageApplied(capabilityName); Assert.AreEqual(expected, actual); }
public void RemoveAttackTest() { AttackCollectionValue target = new AttackCollectionValue(); target.FromXML(LoadableXML); string capabilityName = "Missile"; string targetObjectId = "MyTarget"; string attackingObjectId = "MyAttacker"; int attackStartTime = 8; int remainingCapabilityPercentage = 40; bool expected = true; bool actual; actual = target.RemoveAttack(capabilityName, targetObjectId, attackingObjectId, attackStartTime); Assert.AreEqual(expected, actual); Assert.AreEqual(remainingCapabilityPercentage, target.GetCurrentAttacks()[1].percentageApplied); }
/// <summary> /// Takes an xml string, and returns a DataValue object. /// Returns null if the xml doesn't represent a DataValue. /// </summary> /// <param name="xml"></param> /// <returns></returns> public static DataValue XMLDeserialize(string xml) { Match m = typeregex.Match(xml); if (m.Success) { Group g = m.Groups[1]; string dataType = g.ToString(); switch (dataType) { case "StringType": StringValue sv = new StringValue(); sv.FromXML(xml); return sv; case "DoubleType": DoubleValue dv = new DoubleValue(); dv.FromXML(xml); return dv; case "IntegerType": IntegerValue iv = new IntegerValue(); iv.FromXML(xml); return iv; case "BooleanType": BooleanValue bv = new BooleanValue(); bv.FromXML(xml); return bv; case "LocationType": LocationValue lv = new LocationValue(); lv.FromXML(xml); return lv; case "VelocityType": VelocityValue vv = new VelocityValue(); vv.FromXML(xml); return vv; case "AttributeCollectionType": AttributeCollectionValue av = new AttributeCollectionValue(); av.FromXML(xml); return av; case "CustomAttributesType": CustomAttributesValue cav = new CustomAttributesValue(); cav.FromXML(xml); return cav; case "StringListType": StringListValue slv = new StringListValue(); slv.FromXML(xml); return slv; case "PolygonType": PolygonValue polyv = new PolygonValue(); polyv.FromXML(xml); return polyv; case "StateTableType": StateTableValue stv = new StateTableValue(); stv.FromXML(xml); return stv; case "CapabilityType": CapabilityValue cv = new CapabilityValue(); cv.FromXML(xml); return cv; case "VulnerabilityType": VulnerabilityValue vv2 = new VulnerabilityValue(); vv2.FromXML(xml); return vv2; case "ConeType": ConeValue cv2 = new ConeValue(); cv2.FromXML(xml); return cv2; case "SensorType": SensorValue sv2 = new SensorValue(); sv2.FromXML(xml); return sv2; case "SensorArrayType": SensorArrayValue sav = new SensorArrayValue(); sav.FromXML(xml); return sav; case "EmitterType": EmitterValue ev = new EmitterValue(); ev.FromXML(xml); return ev; case "RangeRingDisplayType": RangeRingDisplayValue rrdv = new RangeRingDisplayValue(); rrdv.FromXML(xml); return rrdv; case "AttackCollectionType": AttackCollectionValue attCV = new AttackCollectionValue(); attCV.FromXML(xml); return attCV; case "WrapperType": WrapperValue wrapper = new WrapperValue(); wrapper.FromXML(xml); return wrapper; case "ClassificationDisplayRulesType": ClassificationDisplayRulesValue cdrv = new ClassificationDisplayRulesValue(); cdrv.FromXML(xml); return cdrv; default: return null; } } else { return null; } }