public void TestFW25ConvertSpeedToKilometersPerHour()
 {
     var h = new LeMondConcreateProviderCtorHelper(goodOneDataPoint);
     var provider = new LeMondGForceSTNCsvDataProvider(h.SourceName, h.Parser, h.FirstRow);
     double d = provider.ConvertSpeedToKilometersPerHour(6.2);
     Assert.AreEqual(10.0, Math.Round(d, 1));
 }
 public void TestFW31ConvertDistanceToKilometers()
 {
     var h = new LeMondConcreateProviderCtorHelper(goodOneDataPoint);
     h.FirstRow[1] = Version0_31;
     var provider = new LeMondGForceSTNCsvDataProvider(h.SourceName, h.Parser, h.FirstRow);
     double d = provider.ConvertDistanceToKilometers(3.1);
     Assert.AreEqual(3.1, Math.Round(d, 1));
 }
        public void TestDateAndTimeAndLines()
        {
            var h = new LeMondConcreateProviderCtorHelper(goodOneDataPoint);
            var provider = new LeMondGForceSTNCsvDataProvider(h.SourceName, h.Parser, h.FirstRow);
            Assert.AreEqual(new DateTime(2011, 12, 30, 15, 02, 0, DateTimeKind.Local), provider.StartTime);

            // lines
            // Single() will make sure we have one and only one line
            var line = provider.DataLines.Single();
            Assert.AreEqual(line.Time, "00:00:01");
            Assert.AreEqual(line.Speed, "2.0");
            Assert.AreEqual(line.Distance, "3.0");
            Assert.AreEqual(line.Power, "4");
            Assert.AreEqual(line.HeartRate, "5");
            Assert.AreEqual(line.Rpm, "6");
            Assert.AreEqual(line.Calories, "7");
        }
        public LeMondGForceSTNCsvDataProvider(string sourceName, TextFieldParser parser, string[] firstRow)
            : base(parser)
        {
            if (firstRow.Length < 6)
            {
                throw new Exception(string.Format("Invalid gforce STN header. Header = '{0}'", string.Join(",", firstRow)));
            }

            firmwareVersion = LeMondGForceSTNCsvDataProvider.ParseFirmwareVersion(firstRow[1]);

            int year, month, day;

            LeMondGForceCsvDataProvider.ParseDate(firstRow[4], out year, out month, out day);
            int hour, minute;

            LeMondGForceCsvDataProvider.ParseTime(firstRow[5], out hour, out minute);
            StartTime = new DateTime(year, month, day, hour, minute, 0, DateTimeKind.Local);

            if (Parser.EndOfData)
            {
                throw new Exception(string.Format("The file {0} does not seem to be a valid LeMond .csv file because it is missing the data field headers.", sourceName));
            }

            firstRow = Parser.ReadFields();
            if (!(firstRow.Length >= 7 &&
                  firstRow[0] == "TIME" &&
                  firstRow[1] == "SPEED" &&
                  firstRow[2] == "DIST" &&
                  firstRow[3] == "POWER" &&
                  firstRow[4] == "HEART RATE" &&
                  firstRow[5] == "RPM" &&
                  firstRow[6] == "CALORIES"))
            {
                throw new Exception(string.Format("The file {0} does not seem to be a valid LeMond .csv file because it does not contain the correct data fields.", sourceName));
            }
        }