protected DeviceInfoMesg GetDeviceInfoMesg(GarminDeviceInfo deviceInfo, Dynastream.Fit.DateTime startTime) { var deviceInfoMesg = new DeviceInfoMesg(); deviceInfoMesg.SetTimestamp(startTime); deviceInfoMesg.SetSerialNumber(deviceInfo.UnitId); deviceInfoMesg.SetManufacturer(deviceInfo.ManufacturerId); deviceInfoMesg.SetProduct(deviceInfo.ProductID); deviceInfoMesg.SetDeviceIndex(0); deviceInfoMesg.SetSourceType(SourceType.Local); deviceInfoMesg.SetProductName(deviceInfo.Name); if (deviceInfo.Version.VersionMinor <= 0) { deviceInfoMesg.SetSoftwareVersion(deviceInfo.Version.VersionMajor); } else { var adjustedMinor = deviceInfo.Version.VersionMinor < 10 ? deviceInfo.Version.VersionMinor * 10 : deviceInfo.Version.VersionMinor; var minor = adjustedMinor / 100; deviceInfoMesg.SetSoftwareVersion((float)(deviceInfo.Version.VersionMajor + minor)); } return(deviceInfoMesg); }
public void GetDeviceInfo_ChoosesUserDevice_WhenProvided(FitnessDiscipline sport) { // SETUP var mocker = new AutoMocker(); var config = new Settings() { Format = new Format() { DeviceInfoPath = "somePath" } }; mocker.Use(config); var converter = mocker.CreateInstance <ConverterInstance>(); var fileHandler = mocker.GetMock <IFileHandling>(); GarminDeviceInfo outDevice = new GarminDeviceInfo() { Name = "UserDevice", // Max 20 Chars ProductID = GarminProduct.Amx, UnitId = 1, Version = new GarminDeviceVersion() { VersionMajor = 11, VersionMinor = 10, BuildMajor = 0, BuildMinor = 0, } }; fileHandler.Setup(x => x.TryDeserializeXml <GarminDeviceInfo>("somePath", out outDevice)) .Returns(true); // ACT var deviceInfo = converter.GetDeviceInfo1(sport); // ASSERT deviceInfo.Name.Should().Be("UserDevice"); deviceInfo.ProductID.Should().Be(GarminProduct.Amx); deviceInfo.UnitId.Should().Be(1); deviceInfo.Version.Should().NotBeNull(); deviceInfo.Version.VersionMajor.Should().Be(11); deviceInfo.Version.VersionMinor.Should().Be(10); deviceInfo.Version.BuildMajor.Should().Be(0); deviceInfo.Version.BuildMinor.Should().Be(0); }
protected GarminDeviceInfo GetDeviceInfo(FitnessDiscipline sport) { GarminDeviceInfo userProvidedDeviceInfo = null; var userDevicePath = _config.Format.DeviceInfoPath; if (!string.IsNullOrEmpty(userDevicePath)) { if (_fileHandler.TryDeserializeXml(userDevicePath, out userProvidedDeviceInfo)) { return(userProvidedDeviceInfo); } } if (sport == FitnessDiscipline.Cycling) { return(CyclingDevice); } return(DefaultDevice); }
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 GetDeviceInfo_FallsBackToDefault_WhenUserDeviceFailsToDeserialize() { // SETUP var mocker = new AutoMocker(); var config = new Settings() { Format = new Format() { DeviceInfoPath = "somePath" } }; mocker.Use(config); var converter = mocker.CreateInstance <ConverterInstance>(); var fileHandler = mocker.GetMock <IFileHandling>(); GarminDeviceInfo outDevice = null; fileHandler.Setup(x => x.TryDeserializeXml <GarminDeviceInfo>("somePath", out outDevice)) .Callback(() => { outDevice = new GarminDeviceInfo();; }) .Returns(false); // ACT var deviceInfo = converter.GetDeviceInfo1(FitnessDiscipline.Bike_Bootcamp); // ASSERT deviceInfo.Name.Should().Be("Forerunner 945"); deviceInfo.ProductID.Should().Be(GarminProduct.Fr945); deviceInfo.UnitId.Should().Be(1); deviceInfo.Version.Should().NotBeNull(); deviceInfo.Version.VersionMajor.Should().Be(19); deviceInfo.Version.VersionMinor.Should().Be(2); deviceInfo.Version.BuildMajor.Should().Be(0); deviceInfo.Version.BuildMinor.Should().Be(0); }
public DeviceInfoMesg GetDeviceInfo(GarminDeviceInfo deviceInfo, Dynastream.Fit.DateTime startTime) { return(this.GetDeviceInfoMesg(deviceInfo, startTime)); }