public void ErrorOnMissingColumnsOnMiddleRow()
        {
            var h = new LeMondConcreateProviderCtorHelper(missingColumnsMiddleRow);
            var provider = new LeMondGForceCsvDataProvider(h.SourceName, h.Parser, h.FirstRow);
            Assert.AreEqual(new DateTime(2012, 01, 02, 16, 31, 0, DateTimeKind.Local), provider.StartTime);

            // lines
            Exception e = ExceptionAssert.Throws<Exception>(() => provider.DataLines.Single());
            StringAssert.Contains(e.Message, "Missing data on row 1");
        }
        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));
            }
        }
        public void TestMissingColumnsOnLastRow()
        {
            var h = new LeMondConcreateProviderCtorHelper(missingColumnsLastRow);
            var provider = new LeMondGForceCsvDataProvider(h.SourceName, h.Parser, h.FirstRow);
            Assert.AreEqual(new DateTime(2012, 01, 02, 16, 31, 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 void TestConvertSpeedToKilometersPerHour()
 {
     var h = new LeMondConcreateProviderCtorHelper(goodOneDataPoint);
     var provider = new LeMondGForceCsvDataProvider(h.SourceName, h.Parser, h.FirstRow);
     double d = provider.ConvertSpeedToKilometersPerHour(10.0);
     Assert.AreEqual(10.0, d);
 }
 public void TestConvertDistanceToKilometers()
 {
     var h = new LeMondConcreateProviderCtorHelper(goodOneDataPoint);
     var provider = new LeMondGForceCsvDataProvider(h.SourceName, h.Parser, h.FirstRow);
     double d = provider.ConvertDistanceToKilometers(3.1);
     Assert.AreEqual(3.1, d);
 }