public void TestSerializeSTTargetExtensions() { XmlDocument testDocument = new XmlDocument(); XmlNode database; XmlAttribute attribute; Workout placeholderWorkout = new Workout("Test", PluginMain.GetApplication().Logbook.ActivityCategories[0]); RegularStep placeholderStep = new RegularStep(placeholderWorkout); ILogbook logbook = PluginMain.GetApplication().Logbook; placeholderWorkout.Steps.AddStepToRoot(placeholderStep); // Setup document testDocument.AppendChild(testDocument.CreateXmlDeclaration("1.0", "UTF-8", "no")); database = testDocument.CreateNode(XmlNodeType.Element, "TrainingCenterDatabase", null); testDocument.AppendChild(database); attribute = testDocument.CreateAttribute("xmlns", "xsi", GarminFitnessPlugin.Constants.xmlns); attribute.Value = "http://www.w3.org/2001/XMLSchema-instance"; database.Attributes.Append(attribute); // Cadence ST zone BaseCadenceTarget cadenceTarget = new BaseCadenceTarget(placeholderStep); cadenceTarget.ConcreteTarget = new CadenceZoneSTTarget(logbook.CadenceZones[0].Zones[2], cadenceTarget); cadenceTarget.Serialize(database, "CadenceSTTarget1", testDocument); Assert.GreaterOrEqual(placeholderWorkout.STExtensions.Count, 1, "Missing step extension node for CadenceST target"); Assert.AreEqual(cadenceSTTargetExtensionResult1, placeholderWorkout.STExtensions[placeholderWorkout.STExtensions.Count - 1].OuterXml, "Invalid CadenceST target extension serialization"); // Speed ST zone BaseSpeedTarget speedTarget = new BaseSpeedTarget(placeholderStep); speedTarget.ConcreteTarget = new SpeedZoneSTTarget(logbook.SpeedZones[0].Zones[1], speedTarget); speedTarget.Serialize(database, "SpeedSTTarget1", testDocument); Assert.GreaterOrEqual(placeholderWorkout.STExtensions.Count, 1, "Missing step extension node for SpeedST target"); Assert.AreEqual(speedSTTargetExtensionResult1, placeholderWorkout.STExtensions[placeholderWorkout.STExtensions.Count - 1].OuterXml, "Invalid SpeedST target extension serialization"); // HR ST zone BaseHeartRateTarget hrTarget = new BaseHeartRateTarget(placeholderStep); hrTarget.ConcreteTarget = new HeartRateZoneSTTarget(logbook.HeartRateZones[0].Zones[2], hrTarget); hrTarget.Serialize(database, "HRSTTarget1", testDocument); placeholderWorkout.Category = logbook.ActivityCategories[0].SubCategories[1]; hrTarget.ConcreteTarget = new HeartRateZoneSTTarget(logbook.HeartRateZones[1].Zones[2], hrTarget); hrTarget.Serialize(database, "HRSTTarget3", testDocument); hrTarget.ConcreteTarget = new HeartRateZoneSTTarget(logbook.HeartRateZones[1].Zones[4], hrTarget); hrTarget.Serialize(database, "HRSTTarget4", testDocument); Assert.GreaterOrEqual(placeholderWorkout.STExtensions.Count, 3, "Missing step extension node for HRST target"); Assert.AreEqual(hrSTTargetExtensionResult1, placeholderWorkout.STExtensions[placeholderWorkout.STExtensions.Count - 3].OuterXml, "Invalid HRST target extension serialization"); Assert.AreEqual(hrSTTargetExtensionResult2, placeholderWorkout.STExtensions[placeholderWorkout.STExtensions.Count - 1].OuterXml, "Invalid HRST target extension serialization"); Assert.AreEqual(placeholderWorkout.STExtensions[placeholderWorkout.STExtensions.Count - 1].LastChild.FirstChild.InnerText, placeholderWorkout.STExtensions[placeholderWorkout.STExtensions.Count - 2].LastChild.FirstChild.InnerText, "Matching HRST target extension are not identical"); Assert.AreNotEqual(placeholderWorkout.STExtensions[placeholderWorkout.STExtensions.Count - 1].LastChild.FirstChild.InnerText, placeholderWorkout.STExtensions[placeholderWorkout.STExtensions.Count - 3].LastChild.FirstChild.InnerText, "Mismatching HRST target extension are identical"); // Power ST zone BasePowerTarget powerTarget = new BasePowerTarget(placeholderStep); powerTarget.ConcreteTarget = new PowerZoneSTTarget(logbook.PowerZones[0].Zones[3], powerTarget); powerTarget.Serialize(database, "PowerSTTarget1", testDocument); Assert.GreaterOrEqual(placeholderWorkout.STExtensions.Count, 1, "Missing step extension node for PowerST target"); Assert.AreEqual(powerSTTargetExtensionResult1, placeholderWorkout.STExtensions[placeholderWorkout.STExtensions.Count - 1].OuterXml, "Invalid PowerST target extension serialization"); }
public void TestTCXSerialization() { XmlDocument testDocument = new XmlDocument(); XmlNode database; XmlAttribute attribute; Workout placeholderWorkout = new Workout("Test", PluginMain.GetApplication().Logbook.ActivityCategories[0]); RegularStep placeholderStep = new RegularStep(placeholderWorkout); ILogbook logbook = PluginMain.GetApplication().Logbook; bool exportHRAsMax = Options.Instance.ExportSportTracksHeartRateAsPercentMax; bool exportPowerAsFTP = Options.Instance.ExportSportTracksPowerAsPercentFTP; int targetPosition1; int targetPosition2; // This is required to determine the step's id in the workout during serialization placeholderWorkout.Steps.AddStepToRoot(placeholderStep); // Setup document testDocument.AppendChild(testDocument.CreateXmlDeclaration("1.0", "UTF-8", "no")); database = testDocument.CreateNode(XmlNodeType.Element, "TrainingCenterDatabase", null); testDocument.AppendChild(database); attribute = testDocument.CreateAttribute("xmlns", "xsi", GarminFitnessPlugin.Constants.xmlns); attribute.Value = "http://www.w3.org/2001/XMLSchema-instance"; database.Attributes.Append(attribute); // No target NullTarget noTarget = new NullTarget(placeholderStep); noTarget.Serialize(database, "NoTarget", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(noTargetResult); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid no target serialization"); // Cadence targets BaseCadenceTarget cadenceTarget = new BaseCadenceTarget(placeholderStep); // Cadence range cadenceTarget.ConcreteTarget = new CadenceRangeTarget(80, 90, cadenceTarget); cadenceTarget.Serialize(database, "CadenceRangeTarget1", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(cadenceRangeTargetResult1); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid CadenceRange target serialization"); cadenceTarget.ConcreteTarget = new CadenceRangeTarget(60, 120, cadenceTarget); cadenceTarget.Serialize(database, "CadenceRangeTarget2", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(cadenceRangeTargetResult2); Assert.GreaterOrEqual(targetPosition2, 0, "Invalid CadenceRange target serialization"); Assert.Greater(targetPosition2, targetPosition1, "CadenceRange target serializations don't differ"); // Cadence ST zone cadenceTarget.ConcreteTarget = new CadenceZoneSTTarget(logbook.CadenceZones[0].Zones[2], cadenceTarget); cadenceTarget.Serialize(database, "CadenceSTTarget1", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(cadenceSTTargetResult1); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid CadenceST target serialization"); cadenceTarget.ConcreteTarget = new CadenceZoneSTTarget(logbook.CadenceZones[0].Zones[4], cadenceTarget); cadenceTarget.Serialize(database, "CadenceSTTarget2", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(cadenceSTTargetResult2); Assert.GreaterOrEqual(targetPosition2, 0, "Invalid CadenceST target serialization"); Assert.Greater(targetPosition2, targetPosition1, "CadenceST target serializations don't differ"); // Speed targets BaseSpeedTarget speedTarget = new BaseSpeedTarget(placeholderStep); // Speed range placeholderWorkout.Category = logbook.ActivityCategories[0].SubCategories[2]; speedTarget.ConcreteTarget = new SpeedRangeTarget(20, 30, Length.Units.Kilometer, Speed.Units.Speed, speedTarget); speedTarget.Serialize(database, "SpeedRangeTarget1", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(speedRangeTargetResult1); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid SpeedRange target serialization"); speedTarget.ConcreteTarget = new SpeedRangeTarget(20, 30, Length.Units.Mile, Speed.Units.Speed, speedTarget); speedTarget.Serialize(database, "SpeedRangeTarget2", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(speedRangeTargetResult2); Assert.GreaterOrEqual(targetPosition2, 0, "Invalid SpeedRange target serialization"); Assert.Greater(targetPosition2, targetPosition1, "SpeedRange target serializations don't differ"); placeholderWorkout.Category = logbook.ActivityCategories[0].SubCategories[3]; speedTarget.ConcreteTarget = new SpeedRangeTarget(20, 30, Length.Units.Kilometer, Speed.Units.Speed, speedTarget); speedTarget.Serialize(database, "SpeedRangeTarget3", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(speedRangeTargetResult3); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid SpeedRange pace target serialization"); speedTarget.ConcreteTarget = new SpeedRangeTarget(7.5, 15, Length.Units.Mile, Speed.Units.Pace, speedTarget); speedTarget.Serialize(database, "SpeedRangeTarget4", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(speedRangeTargetResult4); Assert.GreaterOrEqual(targetPosition2, 0, "Invalid SpeedRRange pace target serialization"); Assert.Greater(targetPosition2, targetPosition1, "SpeedRange pace target serializations don't differ"); // Speed Garmin zone speedTarget.ConcreteTarget = new SpeedZoneGTCTarget(1, speedTarget); speedTarget.Serialize(database, "SpeedGTCTarget1", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(speedGTCTargetResult1); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid SpeedGTC target serialization"); speedTarget.ConcreteTarget = new SpeedZoneGTCTarget(3, speedTarget); speedTarget.Serialize(database, "SpeedGTCTarget2", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(speedGTCTargetResult2); Assert.GreaterOrEqual(targetPosition2, 0, "Invalid SpeedGTC target serialization"); Assert.Greater(targetPosition2, targetPosition1, "SpeedGTC target serializations don't differ"); // Speed ST zone placeholderWorkout.Category = logbook.ActivityCategories[0].SubCategories[2]; Options.Instance.ExportSportTracksHeartRateAsPercentMax = false; speedTarget.ConcreteTarget = new SpeedZoneSTTarget(logbook.SpeedZones[0].Zones[1], speedTarget); speedTarget.Serialize(database, "SpeedSTTarget1", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(speedSTTargetResult1); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid SpeedRST target serialization"); speedTarget.ConcreteTarget = new SpeedZoneSTTarget(logbook.SpeedZones[0].Zones[2], speedTarget); speedTarget.Serialize(database, "SpeedSTTarget2", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(speedSTTargetResult2); Assert.GreaterOrEqual(targetPosition2, 0, "Invalid SpeedRST target serialization"); Assert.Greater(targetPosition2, targetPosition1, "SpeedRST target serializations don't differ"); placeholderWorkout.Category = logbook.ActivityCategories[0].SubCategories[3]; speedTarget.ConcreteTarget = new SpeedZoneSTTarget(logbook.SpeedZones[0].Zones[1], speedTarget); speedTarget.Serialize(database, "SpeedSTTarget3", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(speedSTTargetResult3); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid SpeedRST %Max target serialization"); speedTarget.ConcreteTarget = new SpeedZoneSTTarget(logbook.SpeedZones[0].Zones[2], speedTarget); speedTarget.Serialize(database, "SpeedSTTarget4", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(speedSTTargetResult4); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid SpeedRST %Max target serialization"); Assert.GreaterOrEqual(targetPosition2, targetPosition1, "SpeedST %Max target serializations don't differ"); // Heart rate targets BaseHeartRateTarget hrTarget = new BaseHeartRateTarget(placeholderStep); // HR range hrTarget.ConcreteTarget = new HeartRateRangeTarget(130, 170, false, hrTarget); hrTarget.Serialize(database, "HRRangeTarget1", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(hrRangeTargetResult1); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid HRRange target serialization"); hrTarget.ConcreteTarget = new HeartRateRangeTarget(100, 190, false, hrTarget); hrTarget.Serialize(database, "HRRangeTarget2", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(hrRangeTargetResult2); Assert.GreaterOrEqual(targetPosition2, 0, "Invalid HRRange target serialization"); Assert.Greater(targetPosition2, targetPosition1, "HRRange target serializations don't differ"); hrTarget.ConcreteTarget = new HeartRateRangeTarget(50, 70, true, hrTarget); hrTarget.Serialize(database, "HRRangeTarget3", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(hrRangeTargetResult3); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid HRRange %Max target serialization"); hrTarget.ConcreteTarget = new HeartRateRangeTarget(75, 95, true, hrTarget); hrTarget.Serialize(database, "HRRangeTarget4", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(hrRangeTargetResult4); Assert.GreaterOrEqual(targetPosition2, 0, "Invalid HRRange %Max target serialization"); Assert.Greater(targetPosition2, targetPosition1, "HRRange %Max target serializations don't differ"); // HR Garmin zone hrTarget.ConcreteTarget = new HeartRateZoneGTCTarget(1, hrTarget); hrTarget.Serialize(database, "HRGTCTarget1", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(hrGTCTargetResult1); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid HRGTC target serialization"); hrTarget.ConcreteTarget = new HeartRateZoneGTCTarget(3, hrTarget); hrTarget.Serialize(database, "HRGTCTarget2", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(hrGTCTargetResult2); Assert.GreaterOrEqual(targetPosition2, 0, "Invalid HRGTC target serialization"); Assert.Greater(targetPosition2, targetPosition1, "HRGTC target serializations don't differ"); // HR ST zone Options.Instance.ExportSportTracksHeartRateAsPercentMax = false; hrTarget.ConcreteTarget = new HeartRateZoneSTTarget(logbook.HeartRateZones[0].Zones[2], hrTarget); hrTarget.Serialize(database, "HRSTTarget1", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(hrSTTargetResult1); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid HRRST target serialization"); hrTarget.ConcreteTarget = new HeartRateZoneSTTarget(logbook.HeartRateZones[0].Zones[4], hrTarget); hrTarget.Serialize(database, "HRSTTarget2", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(hrSTTargetResult2); Assert.GreaterOrEqual(targetPosition2, 0, "Invalid HRRST target serialization"); Assert.Greater(targetPosition2, targetPosition1, "HRRST target serializations don't differ"); placeholderWorkout.Category = logbook.ActivityCategories[0].SubCategories[1]; Options.Instance.ExportSportTracksHeartRateAsPercentMax = true; hrTarget.ConcreteTarget = new HeartRateZoneSTTarget(logbook.HeartRateZones[1].Zones[2], hrTarget); hrTarget.Serialize(database, "HRSTTarget3", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(hrSTTargetResult3); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid HRRST %Max target serialization"); hrTarget.ConcreteTarget = new HeartRateZoneSTTarget(logbook.HeartRateZones[1].Zones[4], hrTarget); hrTarget.Serialize(database, "HRSTTarget4", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(hrSTTargetResult4); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid HRRST %Max target serialization"); Assert.GreaterOrEqual(targetPosition2, targetPosition1, "HRST %Max target serializations don't differ"); // Power targets BasePowerTarget powerTarget = new BasePowerTarget(placeholderStep); // Power range powerTarget.ConcreteTarget = new PowerRangeTarget(150, 200, false, powerTarget); powerTarget.Serialize(database, "PowerRangeTarget1", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(powerRangeTargetResult1); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid PowerRange target serialization"); powerTarget.ConcreteTarget = new PowerRangeTarget(300, 400, false, powerTarget); powerTarget.Serialize(database, "PowerRangeTarget2", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(powerRangeTargetResult2); Assert.GreaterOrEqual(targetPosition2, 0, "Invalid PowerRange target serialization"); Assert.Greater(targetPosition2, targetPosition1, "PowerRange target serializations don't differ"); powerTarget.ConcreteTarget = new PowerRangeTarget(67, 80, true, powerTarget); powerTarget.Serialize(database, "PowerRangeTarget3", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(powerRangeTargetResult3); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid PowerRange %FTP target serialization"); powerTarget.ConcreteTarget = new PowerRangeTarget(120, 160, true, powerTarget); powerTarget.Serialize(database, "PowerRangeTarget4", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(powerRangeTargetResult4); Assert.GreaterOrEqual(targetPosition2, 0, "Invalid PowerRRange %FTP target serialization"); Assert.Greater(targetPosition2, targetPosition1, "PowerRange %FTP target serializations don't differ"); // Power Garmin zone powerTarget.ConcreteTarget = new PowerZoneGTCTarget(1, powerTarget); powerTarget.Serialize(database, "PowerGTCTarget1", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(powerGTCTargetResult1); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid PowerGTC target serialization"); powerTarget.ConcreteTarget = new PowerZoneGTCTarget(3, powerTarget); powerTarget.Serialize(database, "PowerGTCTarget2", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(powerGTCTargetResult2); Assert.GreaterOrEqual(targetPosition2, 0, "Invalid PowerGTC target serialization"); Assert.Greater(targetPosition2, targetPosition1, "PowerGTC target serializations don't differ"); // Power ST zone placeholderWorkout.Category = logbook.ActivityCategories[0].SubCategories[4]; Options.Instance.ExportSportTracksPowerAsPercentFTP = false; powerTarget.ConcreteTarget = new PowerZoneSTTarget(logbook.PowerZones[0].Zones[1], powerTarget); powerTarget.Serialize(database, "PowerSTTarget1", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(powerSTTargetResult1); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid PowerST target serialization"); powerTarget.ConcreteTarget = new PowerZoneSTTarget(logbook.PowerZones[0].Zones[3], powerTarget); powerTarget.Serialize(database, "PowerSTTarget2", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(powerSTTargetResult2); Assert.GreaterOrEqual(targetPosition2, 0, "Invalid PowerST target serialization"); Assert.Greater(targetPosition2, targetPosition1, "PowerST target serializations don't differ"); Options.Instance.ExportSportTracksPowerAsPercentFTP = true; powerTarget.ConcreteTarget = new PowerZoneSTTarget(logbook.PowerZones[0].Zones[1], powerTarget); powerTarget.Serialize(database, "PowerSTTarget3", testDocument); targetPosition1 = testDocument.InnerXml.IndexOf(powerSTTargetResult3); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid PowerST %FTP target serialization"); powerTarget.ConcreteTarget = new PowerZoneSTTarget(logbook.PowerZones[0].Zones[3], powerTarget); powerTarget.Serialize(database, "PowerSTTarget4", testDocument); targetPosition2 = testDocument.InnerXml.IndexOf(powerSTTargetResult4); Assert.GreaterOrEqual(targetPosition1, 0, "Invalid PowerST %FTP target serialization"); Assert.GreaterOrEqual(targetPosition2, targetPosition1, "PowerST %FTP target serializations don't differ"); // Make sure to reset options to previous values Options.Instance.ExportSportTracksHeartRateAsPercentMax = exportHRAsMax; Options.Instance.ExportSportTracksPowerAsPercentFTP = exportPowerAsFTP; }