Пример #1
0
        public void TestOpenFitActivityCsvFile()
        {
            var file    = FitParserHelpers.ReadFitCsvFile(@"TestData\Activity.csv");
            var records = file.Records;

            Assert.AreEqual(32, records.Count);
            var record1 = file.Records[0];

            Assert.AreEqual("Definition", record1.Type);
            Assert.AreEqual(0, record1.LocalNumber);
            Assert.AreEqual("file_id", record1.Message);
            var field1 = record1.Fields[0];

            Assert.AreEqual("serial_number", field1.Name);
            Assert.AreEqual("1", field1.Value);
            Assert.AreEqual(String.Empty, field1.Units);
            var record32 = file.Records[31];

            Assert.AreEqual("Data", record32.Type);
            Assert.AreEqual(5, record32.LocalNumber);
            Assert.AreEqual("activity", record32.Message);
            var field2 = record32.Fields[1];

            Assert.AreEqual("total_timer_time", field2.Name);
            Assert.AreEqual("13.749", field2.Value);
            Assert.AreEqual("s", field2.Units);
        }
Пример #2
0
        private void TestActivityFitFile(string filename, int expectedTotalMessages, int expectedTotalDefinitions)
        {
            // Read the answer CSV file
            var file = FitParserHelpers.ReadFitCsvFile(TESTDATA_PATH + filename + ".csv");

            // Decode a Fit file
            var fileStream = System.IO.File.OpenRead(TESTDATA_PATH + filename + ".fit");

            Assert.IsNotNull(fileStream);

            var decode = new Decode();

            Assert.IsNotNull(decode);

            var mesgBroadcaster = new MesgBroadcaster();

            Assert.IsNotNull(mesgBroadcaster);

            Assert.IsTrue(decode.IsFIT(fileStream));

            // Note that it is possible to have something that fails an integrity check, but we can still attempt to parse it
            Assert.IsTrue(decode.CheckIntegrity(fileStream));

            // Connect the Broadcaster to our event (message) source (in this case the Decoder)
            decode.MesgEvent           += mesgBroadcaster.OnMesg;
            decode.MesgDefinitionEvent += mesgBroadcaster.OnMesgDefinition;

            int totalMessages = 0, totalDefinitions = 0;
            int currentRecord = 0;

            mesgBroadcaster.MesgEvent += (sender, args) =>
            {
                foreach (var field in args.mesg.fields)
                {
                    string fieldName             = FitParserHelpers.ConvertPascalCaseToRubyCase(field.Name);
                    var    record                = file.Records[currentRecord];
                    string fieldValue            = ConvertField(field.GetValue()).ToString();
                    var    csvField              = record.GetField(fieldName);
                    string diagnosticFieldString = FormatFieldString(currentRecord, record, args.mesg.fields);
                    Assert.IsNotNull(csvField, diagnosticFieldString);
                    Assert.AreEqual(csvField.Value.ToString(), fieldValue, diagnosticFieldString);
                }
                totalMessages++;
                currentRecord++;
            };

            mesgBroadcaster.MesgDefinitionEvent += (sender, args) =>
            {
                foreach (var field in args.mesgDef.GetFields())
                {
                    var record = file.Records[currentRecord];
                }
                totalDefinitions++;
                currentRecord++;
            };

            Assert.IsTrue(decode.Read(fileStream));
            Assert.AreEqual(expectedTotalMessages, totalMessages);
            Assert.AreEqual(expectedTotalDefinitions, totalDefinitions);

            fileStream.Close();
        }