コード例 #1
0
        public void TestRepeatStepTCXDeserialization()
        {
            XmlDocument testDocument = new XmlDocument();
            XmlNode readNode;
            XmlNode database;
            Workout placeholderWorkout = new Workout("Test", PluginMain.GetApplication().Logbook.ActivityCategories[0]);
            RepeatStep repeatStep = new RepeatStep(placeholderWorkout);

            // Setup document
            testDocument.AppendChild(testDocument.CreateXmlDeclaration("1.0", "UTF-8", "no"));
            database = testDocument.CreateNode(XmlNodeType.Element, "TrainingCenterDatabase", null);
            testDocument.AppendChild(database);
            XmlAttribute attribute = testDocument.CreateAttribute("xmlns", "xsi", GarminFitnessPlugin.Constants.xmlns);
            attribute.Value = "http://www.w3.org/2001/XMLSchema-instance";
            database.Attributes.Append(attribute);
            readNode = testDocument.CreateElement("TestNode");
            database.AppendChild(readNode);

            // Single child
            readNode.InnerXml = repeatStepTestResult1;
            repeatStep.Deserialize(readNode.FirstChild);
            Assert.AreEqual(1, repeatStep.StepsToRepeat.Count, "Invalid step count deserialized for repeat step with single child");
            Assert.IsTrue(repeatStep.StepsToRepeat[0] is RegularStep, "Invalid child step deserialized for repeat step with single child");

            // Multiple children
            readNode.InnerXml = repeatStepTestResult2;
            repeatStep.Deserialize(readNode.FirstChild);
            Assert.AreEqual(2, repeatStep.StepsToRepeat.Count, "Invalid step count deserialized for repeat step with multiple children");
            Assert.IsTrue(repeatStep.StepsToRepeat[0] is RegularStep, "Invalid child step deserialized for repeat step with multiple children");
            Assert.IsTrue(repeatStep.StepsToRepeat[1] is RegularStep, "Invalid child step deserialized for repeat step with multiple children");

            // Nested repeat step
            readNode.InnerXml = repeatStepTestResult3;
            repeatStep.Deserialize(readNode.FirstChild);
            Assert.AreEqual(3, repeatStep.StepsToRepeat.Count, "Invalid step count deserialized for repeat step with nested repeat child");
            Assert.IsTrue(repeatStep.StepsToRepeat[0] is RegularStep, "Invalid child step deserialized for repeat step with nested repeat child");
            Assert.IsTrue(repeatStep.StepsToRepeat[1] is RegularStep, "Invalid child step deserialized for repeat step with nested repeat child");
            Assert.IsTrue(repeatStep.StepsToRepeat[2] is RepeatStep, "Invalid child step deserialized for repeat step with nested repeat child");
            RepeatStep tempRepeat = repeatStep.StepsToRepeat[2] as RepeatStep;
            Assert.AreEqual(1, tempRepeat.StepsToRepeat.Count, "Invalid child step deserialized for repeat step with nested repeat child");
            Assert.IsTrue(tempRepeat.StepsToRepeat[0] is RegularStep, "Invalid child step deserialized for repeat step with nested repeat child");

            // Regular step after repeat
            readNode.InnerXml = repeatStepTestResult4;
            repeatStep.Deserialize(readNode.FirstChild);
            Assert.AreEqual(4, repeatStep.StepsToRepeat.Count, "Invalid step count deserialized for repeat step with step after nested repeat child");
            Assert.IsTrue(repeatStep.StepsToRepeat[3] is RegularStep, "Invalid child step deserialized for repeat step with step after nested repeat child");
        }