diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index ca26daf..ab017f5 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1527,5 +1527,94 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.EqualTo(declination)); } + + [Test] + public void TargetRightAscension_Set_WhenNotConnected_ThenThrowsException() + { + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE); + + var exception = Assert.Throws(() => { _telescope.TargetRightAscension = 0; }); + Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: TargetRightAscension Set")); + } + + [Test] + public void TargetRightAscension_Set_WhenValueTooHigh_ThenThrowsException() + { + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE); + _telescope.Connected = true; + + var exception = Assert.Throws(() => { _telescope.TargetRightAscension = 24; }); + Assert.That(exception.Message, Is.EqualTo("Right ascension value cannot be greater than 23:59:59")); + } + + [Test] + public void TargetRightAscension_Set_WhenValueTooLow_ThenThrowsException() + { + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE); + _telescope.Connected = true; + + var exception = Assert.Throws(() => { _telescope.TargetRightAscension = -0.1; }); + Assert.That(exception.Message, Is.EqualTo("Right ascension value cannot be below 0")); + } + + [Test] + public void TargetRightAscension_Set_WhenTelescopeReportsInvalidRA_ThenThrowsException() + { + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE); + _telescope.Connected = true; + + _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny())).Returns("0"); + + var exception = Assert.Throws(() => { _telescope.TargetRightAscension = 1; }); + Assert.That(exception.Message, Is.EqualTo("Failed to set TargetRightAscension.")); + } + + [TestCase(5.5, "05:30:00", ":Sr05:30:00#")] + [TestCase(10, "10:00:00", ":Sr10:00:00#")] + public void TargetRightAscension_Set_WhenValueOK_ThenSetsNewTargetDeclination(double rightAscension, string hms, string commandString) + { + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE); + _telescope.Connected = true; + + _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(hms); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1"); + + _telescope.TargetRightAscension = rightAscension; + + _sharedResourcesWrapperMock.Verify(x => x.SendChar(commandString), Times.Once); + } + + [Test] + public void TargetRightAscension_Get_WhenTargetNotSet_ThenThrowsException() + { + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE); + _telescope.Connected = true; + + var exception = Assert.Throws(() => { var result = _telescope.TargetRightAscension; }); + Assert.That(exception.Message, Is.EqualTo("Target not set")); + } + + [TestCase(15, "15:00:00", ":Sr15:00:00#")] + public void TargetRightAscension_Get_WhenValueOK_ThenSetsNewTargetDeclination(double rightAscension, string hms, string commandString) + { + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE); + _telescope.Connected = true; + + _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(hms); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1"); + + _telescope.TargetRightAscension = rightAscension; + + var result = _telescope.TargetRightAscension; + + Assert.That(result, Is.EqualTo(rightAscension)); + } } } diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 6b7e8ce..5169308 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1686,14 +1686,13 @@ namespace ASCOM.Meade.net set { LogMessage("TargetRightAscension Set", $"{value}"); + CheckConnected("TargetRightAscension Set"); if (value < 0) throw new InvalidValueException("Right ascension value cannot be below 0"); if (value >= 24) throw new InvalidValueException("Right ascension value cannot be greater than 23:59:59"); - - CheckConnected("TargetRightAscension Set"); //todo implement the low precision version var hms = _utilities.HoursToHMS(value, ":", ":", ":", 2);