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 AddAttackTest()
        {
            AttackCollectionValue target = new AttackCollectionValue();
            AttackCollectionValue.AttackValue attack = new AttackCollectionValue.AttackValue(8, 5, "MyTarget", "MyAttacker", "Missile", 60, false); 
            AttackCollectionValue.AttackValue secondAttack = new AttackCollectionValue.AttackValue(10, 5, "MyTarget", "MyAttacker", "Guns", 80, false);
            AttackCollectionValue.AttackValue thirdAttack = new AttackCollectionValue.AttackValue(11, 5, "MyTarget", "MyAttacker", "Missile", 60, false);
            string errorMessage = string.Empty; 
            string errorMessageExpected = string.Empty; // TODO: Initialize to an appropriate value
            bool expected = true; 
            bool actual;
            //Add Attack 1
            actual = target.AddAttack(attack, out errorMessage);
            Assert.AreEqual(errorMessageExpected, errorMessage);
            Assert.AreEqual(expected, actual);

            //Add Attack 2
            actual = target.AddAttack(secondAttack, out errorMessage);
            Assert.AreEqual(errorMessageExpected, errorMessage);
            Assert.AreEqual(expected, actual);

            //Add Attack 3
            errorMessageExpected = "Applying 40% instead of 60%, as that's all available";
            actual = target.AddAttack(thirdAttack, out errorMessage);
            Assert.AreEqual(errorMessageExpected, errorMessage);
            Assert.AreEqual(expected, actual);
           
            //Add Attack 4
            AttackCollectionValue.AttackValue fourthAttack = new AttackCollectionValue.AttackValue(12, 5, "MyTarget", "MyAttacker", "Missile", 60, false);
            expected = false;
            errorMessageExpected = "There is no more available percentage to apply for this capability.  Try again later.";
            actual = target.AddAttack(thirdAttack, out errorMessage);
            Assert.AreEqual(errorMessageExpected, errorMessage);
            Assert.AreEqual(expected, actual);
            string serialized = target.ToXML();

            Assert.AreEqual(serialized, LoadableXML);
        }
 public void AttackCollectionValueConstructorTest()
 {
     AttackCollectionValue target = new AttackCollectionValue();
     Assert.IsTrue(target != null,"AttackCollectionValue did not correctly construct the object");
 }
        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);
 }
Example #8
0
        /// <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;
            }

        }
Example #9
0
 /// <summary>
 /// 
 /// </summary>
 /// <exclude/>
 /// <param name="dv"></param>
 /// <returns></returns>
 public static DataValue BuildFromDataValue(DataValue dv)
 {
     DataValue returnDV;
     switch (dv.dataType)
     {
         case "WrapperType":
             returnDV = DataValueFactory.BuildWrapper(((WrapperValue)dv).value);
             return returnDV;
             break;
         case "StringType":
             returnDV = DataValueFactory.BuildString(((StringValue)dv).value);
             return returnDV;
             break;
         case "IntegerType":
             returnDV = DataValueFactory.BuildInteger(((IntegerValue)dv).value);
             return returnDV;
             break;
         case "DoubleType":
             returnDV = DataValueFactory.BuildDouble(((DoubleValue)dv).value);
             return returnDV;
             break;
         case "LocationType":
             returnDV = DataValueFactory.BuildLocation(((LocationValue)dv).X, ((LocationValue)dv).Y, ((LocationValue)dv).Z, ((LocationValue)dv).exists);
             return returnDV;
             break;
         case "VelocityType":
             returnDV = DataValueFactory.BuildVelocity(((VelocityValue)dv).VX, ((VelocityValue)dv).VY, ((VelocityValue)dv).VZ);
             return returnDV;
             break;
         case "StringListType":
             returnDV = new StringListValue();
             foreach (string s in ((StringListValue)dv).strings)
             {
                 ((StringListValue)returnDV).strings.Add(s);
             }
             return returnDV;
             break;
         case "RangeRingDisplayType":
             returnDV = DataValueFactory.BuildRangeRingDisplayValue(((RangeRingDisplayValue)dv).name, ((RangeRingDisplayValue)dv).type, ((RangeRingDisplayValue)dv).isWeapon, ((RangeRingDisplayValue)dv).rangeIntensities);
             return returnDV;
             break;
         case "AttackCollectionType":
             returnDV = new AttackCollectionValue();
             String errMsg = String.Empty;
             foreach (AttackCollectionValue.AttackValue av in ((AttackCollectionValue)dv).GetCurrentAttacks())
             {
                 AttackCollectionValue.AttackValue newAttack = new AttackCollectionValue.AttackValue(av.attackStartTime, av.attackTimeWindow, av.targetObjectId, av.attackingObjectId, av.capabilityName, av.percentageApplied, av.isSelfdefense);
                 ((AttackCollectionValue)returnDV).AddAttack(newAttack, out errMsg);
             }
             return returnDV;
             break;
         default:
             returnDV = new DataValue();
             returnDV = dv;
             return returnDV;
     }
     return null;
 }