public void Fit_Converter_Builds_Valid_DeviceInfoMesg([Values(5)] int major, [Values(0, -1, 3, 12)] int minor) { var info = new GarminDeviceInfo() { ManufacturerId = 1, Name = "test", ProductID = 2, UnitId = 3, Version = new GarminDeviceVersion() { VersionMajor = major, VersionMinor = minor, } }; var converter = new ConverterInstance(); var mesg = converter.GetDeviceInfo(info, new Dynastream.Fit.DateTime(System.DateTime.Now)); mesg.GetSerialNumber().Should().Be(info.UnitId); mesg.GetManufacturer().Should().Be(info.ManufacturerId); mesg.GetProduct().Should().Be(info.ProductID); mesg.GetDeviceIndex().Should().Be(0); mesg.GetSourceType().Should().Be(SourceType.Local); var version = mesg.GetSoftwareVersion(); if (minor <= 0) { version.Should().Be(5.0f); } else if (minor == 3) { version.Should().Be(5.3f); } else if (minor == 12) { version.Should().Be(5.12f); } }
public void Fit_Converter_Creates_Valid_Fit(string filename, PreferredLapType lapType) { var workoutPath = Path.Join(DataDirectory, $"{filename}.json"); var settings = new Settings() { Format = new Format() { Running = new Running() { PreferredLapType = lapType }, Cycling = new Cycling() { PreferredLapType = lapType } } }; var converter = new ConverterInstance(settings); var convertedMesgs = converter.ConvertForTest(workoutPath); convertedMesgs.Should().NotBeNullOrEmpty(); var dest = Path.Join(DataDirectory, $"test_output_{filename}.fit"); try { using (FileStream fitDest = new FileStream(dest, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) { var validator = new Encode(ProtocolVersion.V20); validator.Open(fitDest); validator.Write(convertedMesgs); // validates while writing validator.Close(); } } finally { System.IO.File.Delete(dest); } }
protected override void UpdateValue(object newValue) { if (this.ConverterInstance != null) { if (!dataLoaded) { //selected items?? List <string> selectedStrings = new List <string>(); if (newValue != null) { if (newValue.GetType() == typeof(string)) { if (!string.IsNullOrEmpty(newValue.ToString())) { string strValue = newValue.ToString(); if (strValue.Contains(";")) { char[] sep = new char[] { ';' }; foreach (string strSep in strValue.Split(sep)) { if (strSep != "") { selectedStrings.Add(strSep); } } } else { //nur 1 element drin selectedStrings.Add(strValue); } } } } dataLoaded = true; RuntimeServiceProvider serviceProvider = new RuntimeServiceProvider(this); foreach (object o in this.ConverterInstance.GetStandardValues(serviceProvider)) { if (o is NameValueItem) { NameValueItem nvi = o as NameValueItem; ListViewItem lvi = new ListViewItem(nvi.Name); lvi.Tag = nvi; lvi.ImageKey = nvi.ItemType; listview.Items.Add(lvi); ListViewItem.ListViewSubItem slvi = new ListViewItem.ListViewSubItem(); slvi.Text = nvi.Description; lvi.SubItems.Add(slvi); if (ConverterInstance != null) { if (!ConverterInstance.IsValid(serviceProvider, nvi)) { lvi.ForeColor = Color.Gray; } //select a default value, if only one selection is allowed if ((selectedStrings.Count == 0) && !withCheckboxes) { if (listview.SelectedItems.Count == 0) { //ITypeDescriptorContext context = serviceProvider.GetService(typeof(ITypeDescriptorContext)) as ITypeDescriptorContext; if (ConverterInstance.IsValid(serviceProvider, nvi)) { lvi.Selected = true; } } } } if (selectedStrings.Contains(nvi.ToString())) { if (withCheckboxes) { lvi.Checked = true; } else { lvi.Selected = true; } } } else { NameValueItem nvi = new NameValueItem(); nvi.Name = o.ToString(); nvi.Value = o.ToString(); ListViewItem lvi = new ListViewItem(o.ToString()); lvi.Tag = nvi; lvi.ImageKey = o.ToString(); listview.Items.Add(lvi); if (selectedStrings.Contains(nvi.ToString())) { if (withCheckboxes) { lvi.Checked = true; } else { lvi.Selected = true; } } } } //if only one item is available, go to the next wizard page, if there is only 1 visible control on the wizard page if (listview.Items.Count == 1) { int controlcount = 0; foreach (Control control in this.WizardPage.Controls) { if (control.Visible) { if (control.GetType() == typeof(Panel)) { //ignore the button panel } else { controlcount++; } } } if (controlcount == 1) { //I'm the only one control on the wizard page if (this.WizardPage.Wizard.NextPage != null) { this.WizardPage.Wizard.OnNext(); //this.WizardPage.Wizard.GotoPage(this.WizardPage.Wizard.NextPageFromPage(this.WizardPage)); } } } } } base.SetValue(newValue); }