diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 56b307c..3e663b5 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -18,6 +18,10 @@ namespace Meade.net.Telescope.UnitTests { internal string telescopeRaResult = "HH:MM:SS"; internal double rightAscension = 1.2; //todo rename to RightAscension; + + internal string SiteLatitudeString = "testLatString"; + internal double SiteLatitudeValue = 123.45; + } [TestFixture] @@ -94,6 +98,9 @@ namespace Meade.net.Telescope.UnitTests private void ConnectTelescope(string productName = TelescopeList.Autostar497, string firmwareVersion = TelescopeList.Autostar497_31Ee) { + _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gt#", true)).Returns(_testProperties.SiteLatitudeString); + _utilMock.Setup(x => x.DMSToDegrees(_testProperties.SiteLatitudeString)).Returns(_testProperties.SiteLatitudeValue); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#", true)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.HMSToHours(_testProperties.telescopeRaResult)).Returns(_testProperties.rightAscension); @@ -391,8 +398,10 @@ namespace Meade.net.Telescope.UnitTests { _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_31Ee); - _telescope.Connected = expectedConnected; + if (expectedConnected) + ConnectTelescope(); + Assert.That(_telescope.Connected, Is.EqualTo(expectedConnected)); if (expectedConnected) @@ -948,7 +957,7 @@ namespace Meade.net.Telescope.UnitTests } }); - _telescope.Connected = true; + ConnectTelescope(); Assert.That(currentPrecision, Is.EqualTo(finalPrecision)); _sharedResourcesWrapperMock.Verify(x => x.SendChar(":P#"), Times.AtLeastOnce); @@ -1842,19 +1851,13 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SiteLatitude_Get_WhenConnected_ThenRetrievesAndReturnsExpectedValue() { - var siteLatitudeString = "testLatString"; - var siteLatitudeValue = 123.45; - - _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gt#", true)).Returns(siteLatitudeString); - _utilMock.Setup(x => x.DMSToDegrees(siteLatitudeString)).Returns(siteLatitudeValue); - ConnectTelescope(); var result = _telescope.SiteLatitude; _sharedResourcesWrapperMock.Verify( x => x.SendString(":Gt#", true), Times.AtLeastOnce); - Assert.That(result,Is.EqualTo(siteLatitudeValue)); + Assert.That(result,Is.EqualTo(_testProperties.SiteLatitudeValue)); } [Test] @@ -3075,5 +3078,182 @@ namespace Meade.net.Telescope.UnitTests Assert.That(isSloSlewing, Is.False); _sharedResourcesWrapperMock.Verify( x => x.SendString(":D#", true), Times.Once); } + + [Test] + public void AbortSlew_WhenParked_ThenThrowsParkedException() + { + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { _telescope.AbortSlew(); }); + } + + [Test] + public void MoveAxis_WhenParked_ThenThrowsParkedException() + { + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { _telescope.MoveAxis(TelescopeAxes.axisPrimary, 0); }); + } + + [Test] + public void PulseGuide_WhenParked_ThenThrowsParkedException() + { + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { _telescope.PulseGuide(GuideDirections.guideEast, 0); }); + } + + [Test] + public void SlewToAltAz_WhenParked_ThenThrowsParkedException() + { + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { _telescope.SlewToAltAz(0, 0); }); + } + + [Test] + public void SlewToAltAzAsync_WhenParked_ThenThrowsParkedException() + { + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { _telescope.SlewToAltAzAsync(0, 0); }); + } + + [Test] + public void SlewToCoordinates_WhenParked_ThenThrowsParkedException() + { + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { _telescope.SlewToCoordinates(0, 0); }); + } + + [Test] + public void SlewToCoordinatesAsync_WhenParked_ThenThrowsParkedException() + { + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { _telescope.SlewToCoordinatesAsync(0, 0); }); + } + + [Test] + public void SlewToTarget_WhenParked_ThenThrowsParkedException() + { + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { _telescope.SlewToTarget(); }); + } + + [Test] + public void SlewToTargetAsync_WhenParked_ThenThrowsParkedException() + { + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + } + + [Test] + public void SyncToCoordinates_WhenParked_ThenThrowsParkedException() + { + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { _telescope.SyncToCoordinates(0,0); }); + } + + [Test] + public void SyncToTarget_WhenParked_ThenThrowsParkedException() + { + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { _telescope.SyncToTarget(); }); + } + + [Test] + public void TargetDeclination_WhenParked_ThenThrowsParkedException() + { + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { _telescope.TargetDeclination = 1; }); + } + + [Test] + public void TargetRightAscension_WhenParked_ThenThrowsParkedException() + { + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { _telescope.TargetRightAscension = 1; }); + } + + [Test] + public void TrackingRate_WhenParked_ThenThrowsParkedException() + { + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { _telescope.TrackingRate = DriveRates.driveLunar; }); + } + + + [Test] + public void UTCDate_WhenParked_ThenThrowsParkedException() + { + //todo Modes + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { var date = _telescope.UTCDate; }); + } + + [Test] + public void SiteLatitude_WhenParked_ThenThrowsParkedException() + { + //todo modes + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { var lat = _telescope.SiteLatitude; }); + } + + [Test] + public void SiteLongitude_WhenParked_ThenThrowsParkedException() + { + //todo modes + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { var siteLong = _telescope.SiteLongitude; }); + } + + [Test] + public void Declination_WhenParked_ThenThrowsParkedException() + { + //todo modes + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { var dec = _telescope.Declination; }); + } + + [Test] + public void RightAscension_WhenParked_ThenThrowsParkedException() + { + //todo modes + ConnectTelescope(); + _telescope.Park(); + + Assert.Throws(() => { var ra = _telescope.RightAscension; }); + } } } \ No newline at end of file diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 8e53e16..cdb6257 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1814,7 +1814,7 @@ namespace ASCOM.Meade.net } } - private double _lastGoodSiteLatitude; + private double? _lastGoodSiteLatitude; public double SiteLatitude { get @@ -1829,15 +1829,23 @@ namespace ASCOM.Meade.net //Returns: sDD* MM# //The latitude of the current site. Positive inplies North latitude. - var siteLatitude = _utilities.DMSToDegrees(latitude); - LogMessage("SiteLatitude Get", $"{_utilitiesExtra.DegreesToDMS(siteLatitude)}"); + if (latitude != null) + { + var siteLatitude = _utilities.DMSToDegrees(latitude); + LogMessage("SiteLatitude Get", $"{_utilitiesExtra.DegreesToDMS(siteLatitude)}"); - _lastGoodSiteLatitude = siteLatitude; - return siteLatitude; + _lastGoodSiteLatitude = siteLatitude; + return siteLatitude; + } + + throw new InvalidOperationException("unable to get site latitude from telescope."); } catch (ParkedException) { - return _lastGoodSiteLatitude; + if (ParkedBehaviour == ParkedBehaviour.NoCoordinates) + throw; + + return _lastGoodSiteLatitude.Value; } } set @@ -1898,6 +1906,9 @@ namespace ASCOM.Meade.net } catch (ParkedException) { + if (ParkedBehaviour == ParkedBehaviour.NoCoordinates) + throw; + return _lastGoodSiteLongitude; } } @@ -2578,6 +2589,9 @@ namespace ASCOM.Meade.net } catch (ParkedException e) { + if (ParkedBehaviour == ParkedBehaviour.NoCoordinates) + throw; + return _clock.UtcNow; } }