Removed the alignmode check as it is not supported on all telescopes.

Added current RA and dec to the log when the telescope connects.
This commit is contained in:
2019-10-05 11:23:10 +01:00
parent 3dc87e3724
commit 7f8c2cb559
2 changed files with 109 additions and 94 deletions
@@ -192,10 +192,10 @@ namespace Meade.net.Telescope.UnitTests
[TestCase("4", "#:GP#", "Parents")] [TestCase("4", "#:GP#", "Parents")]
public void Action_Site_GetName_WhenCallingWithValidValues_ThenSelectsCorrectSite(string site, string telescopeCommand, string siteName) public void Action_Site_GetName_WhenCallingWithValidValues_ThenSelectsCorrectSite(string site, string telescopeCommand, string siteName)
{ {
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString(telescopeCommand)).Returns(siteName); _sharedResourcesWrapperMock.Setup(x => x.SendString(telescopeCommand)).Returns(siteName);
ConnectTelescope();
string parameters = $"GetName {site}"; string parameters = $"GetName {site}";
var result = _telescope.Action("site", parameters); var result = _telescope.Action("site", parameters);
@@ -221,10 +221,11 @@ namespace Meade.net.Telescope.UnitTests
[TestCase("4", "#:SPParents#", "Parents")] [TestCase("4", "#:SPParents#", "Parents")]
public void Action_Site_SetName_WhenCallingWithValidValues_ThenSelectsCorrectSite(string site, string telescopeCommand, string siteName) public void Action_Site_SetName_WhenCallingWithValidValues_ThenSelectsCorrectSite(string site, string telescopeCommand, string siteName)
{ {
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendChar(telescopeCommand)).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar(telescopeCommand)).Returns("1");
ConnectTelescope();
string parameters = $"SetName {site} {siteName}"; string parameters = $"SetName {site} {siteName}";
_telescope.Action("site", parameters); _telescope.Action("site", parameters);
@@ -334,10 +335,10 @@ namespace Meade.net.Telescope.UnitTests
string expectedMessage = "expected result message"; string expectedMessage = "expected result message";
string sendMessage = "test blind Message"; string sendMessage = "test blind Message";
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage)).Returns(() => expectedMessage); _sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage)).Returns(() => expectedMessage);
ConnectTelescope();
var actualMessage = _telescope.CommandString(sendMessage, true); var actualMessage = _telescope.CommandString(sendMessage, true);
_sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage), Times.Once);
@@ -348,9 +349,6 @@ namespace Meade.net.Telescope.UnitTests
[TestCase(false)] [TestCase(false)]
public void Connected_Get_ReturnsExpectedValue(bool expectedConnected) public void Connected_Get_ReturnsExpectedValue(bool expectedConnected)
{ {
const char ack = (char)6;
_sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString())).Returns("P");
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497);
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_31Ee); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_31Ee);
_telescope.Connected = expectedConnected; _telescope.Connected = expectedConnected;
@@ -370,10 +368,6 @@ namespace Meade.net.Telescope.UnitTests
var productName = TelescopeList.LX200GPS; var productName = TelescopeList.LX200GPS;
var firmware = string.Empty; var firmware = string.Empty;
const char ack = (char)6;
_sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString())).Returns("P");
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName);
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware);
_telescope.Connected = true; _telescope.Connected = true;
@@ -416,9 +410,6 @@ namespace Meade.net.Telescope.UnitTests
[Test] [Test]
public void Connected_Set_SettingFalseWhenTrue_ThenDisconnects() public void Connected_Set_SettingFalseWhenTrue_ThenDisconnects()
{ {
const char ack = (char)6;
_sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString())).Returns("P");
ConnectTelescope(); ConnectTelescope();
_sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny<string>(), It.IsAny<string>()), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
@@ -606,11 +597,11 @@ namespace Meade.net.Telescope.UnitTests
[TestCase("G", AlignmentModes.algGermanPolar)] [TestCase("G", AlignmentModes.algGermanPolar)]
public void AlignmentMode_Get_WhenScopeInAltAz_ReturnsAltAz(string telescopeMode, AlignmentModes alignmentMode) public void AlignmentMode_Get_WhenScopeInAltAz_ReturnsAltAz(string telescopeMode, AlignmentModes alignmentMode)
{ {
ConnectTelescope();
const char ack = (char)6; const char ack = (char)6;
_sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString())).Returns(telescopeMode); _sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString())).Returns(telescopeMode);
ConnectTelescope();
var actualResult = _telescope.AlignmentMode; var actualResult = _telescope.AlignmentMode;
Assert.That(actualResult, Is.EqualTo(alignmentMode)); Assert.That(actualResult, Is.EqualTo(alignmentMode));
@@ -814,9 +805,6 @@ namespace Meade.net.Telescope.UnitTests
[TestCase("Low", true, false)] [TestCase("Low", true, false)]
public void Precision_Set_WhenConnectedAndPrecisionSetHighScopeIsLow_ThenTelescopePrecisionChanged(string desiredPresision, bool telescopePrecision, bool finalPrecision) public void Precision_Set_WhenConnectedAndPrecisionSetHighScopeIsLow_ThenTelescopePrecisionChanged(string desiredPresision, bool telescopePrecision, bool finalPrecision)
{ {
const char ack = (char)6;
_sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString())).Returns("P");
_profileProperties.Precision = desiredPresision; _profileProperties.Precision = desiredPresision;
var currentPrecision = telescopePrecision; var currentPrecision = telescopePrecision;
@@ -959,15 +947,34 @@ namespace Meade.net.Telescope.UnitTests
public void Declination_Get_WhenConnected_ThenReadsValueFromScope(string declincationString) public void Declination_Get_WhenConnected_ThenReadsValueFromScope(string declincationString)
{ {
var expectedResult = 12.34; var expectedResult = 12.34;
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GD#")).Returns(declincationString); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GD#")).Returns(declincationString);
_utilMock.Setup(x => x.DMSToDegrees(declincationString)).Returns(expectedResult); _utilMock.Setup(x => x.DMSToDegrees(declincationString)).Returns(expectedResult);
ConnectTelescope();
var actualResult = _telescope.Declination; var actualResult = _telescope.Declination;
Assert.That(actualResult, Is.EqualTo(expectedResult)); Assert.That(actualResult, Is.EqualTo(expectedResult));
} }
[Test]
public void Declination_Get_WhenConnected_ThenReturnsExpectedResult()
{
var telescopeRaResult = "s12*3456";
var dmsResult = 1.2;
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GD#")).Returns(telescopeRaResult);
_utilMock.Setup(x => x.DMSToDegrees(telescopeRaResult)).Returns(dmsResult);
ConnectTelescope();
var result = _telescope.Declination;
_sharedResourcesWrapperMock.Verify(x => x.SendString("#:GD#"), Times.Exactly(2));
_utilMock.Verify(x => x.DMSToDegrees(telescopeRaResult), Times.Exactly(2));
Assert.That(result, Is.EqualTo(dmsResult));
}
[Test] [Test]
public void DeclinationRate_Get_ThenReturns0() public void DeclinationRate_Get_ThenReturns0()
{ {
@@ -1393,15 +1400,15 @@ namespace Meade.net.Telescope.UnitTests
var telescopeRaResult = "HH:MM:SS"; var telescopeRaResult = "HH:MM:SS";
var hmsResult = 1.2; var hmsResult = 1.2;
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GR#")).Returns(telescopeRaResult); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GR#")).Returns(telescopeRaResult);
_utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult);
ConnectTelescope();
var result = _telescope.RightAscension; var result = _telescope.RightAscension;
_sharedResourcesWrapperMock.Verify( x => x.SendString("#:GR#"), Times.Once); _sharedResourcesWrapperMock.Verify( x => x.SendString("#:GR#"), Times.Exactly(2));
_utilMock.Verify( x => x.HMSToHours(telescopeRaResult), Times.Once); _utilMock.Verify( x => x.HMSToHours(telescopeRaResult), Times.Exactly(2));
Assert.That(result,Is.EqualTo(hmsResult)); Assert.That(result,Is.EqualTo(hmsResult));
} }
@@ -1522,10 +1529,11 @@ namespace Meade.net.Telescope.UnitTests
var siteLatitudeString = "testLatString"; var siteLatitudeString = "testLatString";
var siteLatitudeValue = 123.45; var siteLatitudeValue = 123.45;
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:Gt#")).Returns(siteLatitudeString); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:Gt#")).Returns(siteLatitudeString);
_utilMock.Setup(x => x.DMSToDegrees(siteLatitudeString)).Returns(siteLatitudeValue); _utilMock.Setup(x => x.DMSToDegrees(siteLatitudeString)).Returns(siteLatitudeValue);
ConnectTelescope();
var result = _telescope.SiteLatitude; var result = _telescope.SiteLatitude;
_sharedResourcesWrapperMock.Verify( x => x.SendString("#:Gt#"), Times.Once); _sharedResourcesWrapperMock.Verify( x => x.SendString("#:Gt#"), Times.Once);
@@ -1562,10 +1570,10 @@ namespace Meade.net.Telescope.UnitTests
[TestCase(20.75)] [TestCase(20.75)]
public void SiteLatitude_Set_WhenValueSetAndTelescopRejects_ThenExceptionThrown(double siteLatitude) public void SiteLatitude_Set_WhenValueSetAndTelescopRejects_ThenExceptionThrown(double siteLatitude)
{ {
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny<string>())).Returns("0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny<string>())).Returns("0");
ConnectTelescope();
var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.SiteLatitude = siteLatitude; }); var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.SiteLatitude = siteLatitude; });
Assert.That(exception.Message, Is.EqualTo("Failed to set site latitude.")); Assert.That(exception.Message, Is.EqualTo("Failed to set site latitude."));
@@ -1575,10 +1583,10 @@ namespace Meade.net.Telescope.UnitTests
[TestCase(20.75, "#:St+20*45#")] [TestCase(20.75, "#:St+20*45#")]
public void SiteLatitude_Set_WhenValidValues_ThenValueSentToTelescope(double siteLatitude, string expectedCommand) public void SiteLatitude_Set_WhenValidValues_ThenValueSentToTelescope(double siteLatitude, string expectedCommand)
{ {
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendChar(expectedCommand)).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar(expectedCommand)).Returns("1");
ConnectTelescope();
_telescope.SiteLatitude = siteLatitude; _telescope.SiteLatitude = siteLatitude;
_sharedResourcesWrapperMock.Verify(x => x.SendChar(expectedCommand), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendChar(expectedCommand), Times.Once);
@@ -1605,11 +1613,11 @@ namespace Meade.net.Telescope.UnitTests
{ {
var telescopeLongitude = "testLongitude"; var telescopeLongitude = "testLongitude";
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:Gg#")).Returns(telescopeLongitude); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:Gg#")).Returns(telescopeLongitude);
_utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue);
ConnectTelescope();
var result = _telescope.SiteLongitude; var result = _telescope.SiteLongitude;
Assert.That(result, Is.EqualTo(expectedResult)); Assert.That(result, Is.EqualTo(expectedResult));
@@ -1643,9 +1651,10 @@ namespace Meade.net.Telescope.UnitTests
[Test] [Test]
public void SiteLongitude_Set_WhenConnectedAndTelescopeFails_ThenThrowsException() public void SiteLongitude_Set_WhenConnectedAndTelescopeFails_ThenThrowsException()
{ {
_sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny<string>())).Returns("0");
ConnectTelescope(); ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny<string>())).Returns("0");
var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.SiteLongitude = 10; }); var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.SiteLongitude = 10; });
Assert.That(exception.Message, Is.EqualTo("Failed to set site longitude.")); Assert.That(exception.Message, Is.EqualTo("Failed to set site longitude."));
@@ -1654,10 +1663,10 @@ namespace Meade.net.Telescope.UnitTests
[TestCase(10, "#:Sg350*00#")] [TestCase(10, "#:Sg350*00#")]
public void SiteLongitude_Set_WhenConnectedAndTelescopeFails_ThenThrowsException(double longitude, string expectedCommand) public void SiteLongitude_Set_WhenConnectedAndTelescopeFails_ThenThrowsException(double longitude, string expectedCommand)
{ {
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendChar(expectedCommand)).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar(expectedCommand)).Returns("1");
ConnectTelescope();
_telescope.SiteLongitude = longitude; _telescope.SiteLongitude = longitude;
_sharedResourcesWrapperMock.Verify(x => x.SendChar(expectedCommand), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendChar(expectedCommand), Times.Once);
@@ -1683,10 +1692,10 @@ namespace Meade.net.Telescope.UnitTests
[Test] [Test]
public void SyncToTarget_WhenSyncToTargetFails_ThenThrowsException() public void SyncToTarget_WhenSyncToTargetFails_ThenThrowsException()
{ {
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:CM#")).Returns(string.Empty); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:CM#")).Returns(string.Empty);
ConnectTelescope();
var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.SyncToTarget(); } ); var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.SyncToTarget(); } );
Assert.That(exception.Message, Is.EqualTo("Unable to perform sync")); Assert.That(exception.Message, Is.EqualTo("Unable to perform sync"));
@@ -1696,10 +1705,10 @@ namespace Meade.net.Telescope.UnitTests
[Test] [Test]
public void SyncToTarget_WhenSyncToTargetWorks_ThennoExceptionThrown() public void SyncToTarget_WhenSyncToTargetWorks_ThennoExceptionThrown()
{ {
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:CM#")).Returns(" M31 EX GAL MAG 3.5 SZ178.0'#"); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:CM#")).Returns(" M31 EX GAL MAG 3.5 SZ178.0'#");
ConnectTelescope();
Assert.DoesNotThrow(() => { _telescope.SyncToTarget(); }); Assert.DoesNotThrow(() => { _telescope.SyncToTarget(); });
_sharedResourcesWrapperMock.Verify(x => x.SendString("#:CM#"), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendString("#:CM#"), Times.Once);
@@ -1733,10 +1742,10 @@ namespace Meade.net.Telescope.UnitTests
[Test] [Test]
public void TargetDeclination_Set_WhenTelescopeReportsInvalidDec_ThenThrowsException() public void TargetDeclination_Set_WhenTelescopeReportsInvalidDec_ThenThrowsException()
{ {
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny<string>())).Returns("0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny<string>())).Returns("0");
ConnectTelescope();
var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.TargetDeclination = 50; }); var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.TargetDeclination = 50; });
Assert.That(exception.Message, Is.EqualTo("Target declination invalid")); Assert.That(exception.Message, Is.EqualTo("Target declination invalid"));
} }
@@ -1747,11 +1756,12 @@ namespace Meade.net.Telescope.UnitTests
[TestCase(50, "50*00:00", "#:Sd+50*00:00#")] [TestCase(50, "50*00:00", "#:Sd+50*00:00#")]
public void TargetDeclination_Set_WhenValueOK_ThenSetsNewTargetDeclination( double declination,string decstring, string commandString) public void TargetDeclination_Set_WhenValueOK_ThenSetsNewTargetDeclination( double declination,string decstring, string commandString)
{ {
ConnectTelescope();
_utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(decstring); _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(decstring);
_sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1");
ConnectTelescope();
_telescope.TargetDeclination = declination; _telescope.TargetDeclination = declination;
_sharedResourcesWrapperMock.Verify(x => x.SendChar(commandString),Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendChar(commandString),Times.Once);
@@ -1773,11 +1783,11 @@ namespace Meade.net.Telescope.UnitTests
[TestCase(50, "50*00:00", "#:Sd+50*00:00#")] [TestCase(50, "50*00:00", "#:Sd+50*00:00#")]
public void TargetDeclination_Get_WhenValueOK_ThenSetsNewTargetDeclination(double declination, string decstring, string commandString) public void TargetDeclination_Get_WhenValueOK_ThenSetsNewTargetDeclination(double declination, string decstring, string commandString)
{ {
ConnectTelescope();
_utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(decstring); _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(decstring);
_sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1");
ConnectTelescope();
_telescope.TargetDeclination = declination; _telescope.TargetDeclination = declination;
var result = _telescope.TargetDeclination; var result = _telescope.TargetDeclination;
@@ -1813,10 +1823,10 @@ namespace Meade.net.Telescope.UnitTests
[Test] [Test]
public void TargetRightAscension_Set_WhenTelescopeReportsInvalidRA_ThenThrowsException() public void TargetRightAscension_Set_WhenTelescopeReportsInvalidRA_ThenThrowsException()
{ {
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny<string>())).Returns("0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny<string>())).Returns("0");
ConnectTelescope();
var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.TargetRightAscension = 1; }); var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.TargetRightAscension = 1; });
Assert.That(exception.Message, Is.EqualTo("Failed to set TargetRightAscension.")); Assert.That(exception.Message, Is.EqualTo("Failed to set TargetRightAscension."));
} }
@@ -1825,11 +1835,11 @@ namespace Meade.net.Telescope.UnitTests
[TestCase(10, "10:00:00", "#:Sr10:00:00#")] [TestCase(10, "10:00:00", "#:Sr10:00:00#")]
public void TargetRightAscension_Set_WhenValueOK_ThenSetsNewTargetDeclination(double rightAscension, string hms, string commandString) public void TargetRightAscension_Set_WhenValueOK_ThenSetsNewTargetDeclination(double rightAscension, string hms, string commandString)
{ {
ConnectTelescope();
_utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(hms); _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(hms);
_sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1");
ConnectTelescope();
_telescope.TargetRightAscension = rightAscension; _telescope.TargetRightAscension = rightAscension;
_sharedResourcesWrapperMock.Verify(x => x.SendChar(commandString), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendChar(commandString), Times.Once);
@@ -1851,11 +1861,11 @@ namespace Meade.net.Telescope.UnitTests
[TestCase(15, "15:00:00", "#:Sr15:00:00#")] [TestCase(15, "15:00:00", "#:Sr15:00:00#")]
public void TargetRightAscension_Get_WhenValueOK_ThenSetsNewTargetDeclination(double rightAscension, string hms, string commandString) public void TargetRightAscension_Get_WhenValueOK_ThenSetsNewTargetDeclination(double rightAscension, string hms, string commandString)
{ {
ConnectTelescope();
_utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(hms); _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(hms);
_sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1");
ConnectTelescope();
_telescope.TargetRightAscension = rightAscension; _telescope.TargetRightAscension = rightAscension;
var result = _telescope.TargetRightAscension; var result = _telescope.TargetRightAscension;
@@ -1954,12 +1964,12 @@ namespace Meade.net.Telescope.UnitTests
public void UTCDate_Get_WhenConnected_ThenReturnsUTCDateTime(string telescopeDate, string telescopeTime, public void UTCDate_Get_WhenConnected_ThenReturnsUTCDateTime(string telescopeDate, string telescopeTime,
string telescopeUtcCorrection, int year, int month, int day, int hour, int min, int second) string telescopeUtcCorrection, int year, int month, int day, int hour, int min, int second)
{ {
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GC#")).Returns(telescopeDate); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GC#")).Returns(telescopeDate);
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GL#")).Returns(telescopeTime); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GL#")).Returns(telescopeTime);
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GG#")).Returns(telescopeUtcCorrection); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GG#")).Returns(telescopeUtcCorrection);
ConnectTelescope();
var result = _telescope.UTCDate; var result = _telescope.UTCDate;
Assert.That(result, Is.Not.Null); Assert.That(result, Is.Not.Null);
@@ -1989,11 +1999,11 @@ namespace Meade.net.Telescope.UnitTests
var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection;
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GG#")).Returns(telescopeUtcCorrection); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GG#")).Returns(telescopeUtcCorrection);
_sharedResourcesWrapperMock.Setup(x => x.SendChar($"#:SL{telescopeTime}#")).Returns("0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($"#:SL{telescopeTime}#")).Returns("0");
ConnectTelescope();
var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.UTCDate = newDate; } ); var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.UTCDate = newDate; } );
Assert.That(exception.Message, Is.EqualTo("Failed to set local time")); Assert.That(exception.Message, Is.EqualTo("Failed to set local time"));
@@ -2008,12 +2018,12 @@ namespace Meade.net.Telescope.UnitTests
var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection;
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GG#")).Returns(telescopeUtcCorrection); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GG#")).Returns(telescopeUtcCorrection);
_sharedResourcesWrapperMock.Setup(x => x.SendChar($"#:SL{telescopeTime}#")).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($"#:SL{telescopeTime}#")).Returns("1");
_sharedResourcesWrapperMock.Setup(x => x.SendChar($"#:SC{newDate:MM/dd/yy}#")).Returns("0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($"#:SC{newDate:MM/dd/yy}#")).Returns("0");
ConnectTelescope();
var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.UTCDate = newDate; }); var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.UTCDate = newDate; });
Assert.That(exception.Message, Is.EqualTo("Failed to set local date")); Assert.That(exception.Message, Is.EqualTo("Failed to set local date"));
@@ -2030,12 +2040,12 @@ namespace Meade.net.Telescope.UnitTests
var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection;
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GG#")).Returns(telescopeUtcCorrection); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GG#")).Returns(telescopeUtcCorrection);
_sharedResourcesWrapperMock.Setup(x => x.SendChar($"#:SL{telescopeTime}#")).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($"#:SL{telescopeTime}#")).Returns("1");
_sharedResourcesWrapperMock.Setup(x => x.SendChar($"#:SC{telescopeDate}#")).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($"#:SC{telescopeDate}#")).Returns("1");
ConnectTelescope();
_telescope.UTCDate = newDate; _telescope.UTCDate = newDate;
_sharedResourcesWrapperMock.Verify(x => x.ReadTerminated(), Times.Exactly(2)); _sharedResourcesWrapperMock.Verify(x => x.ReadTerminated(), Times.Exactly(2));
@@ -2050,14 +2060,14 @@ namespace Meade.net.Telescope.UnitTests
double declination = -30.5; double declination = -30.5;
string dec = "-30*30:00"; string dec = "-30*30:00";
ConnectTelescope();
_utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(hms); _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(hms);
_sharedResourcesWrapperMock.Setup(x => x.SendChar($"#:Sr{hms}#")).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($"#:Sr{hms}#")).Returns("1");
_utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(dec); _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(dec);
_sharedResourcesWrapperMock.Setup(x => x.SendChar($"#:Sd{dec}#")).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($"#:Sd{dec}#")).Returns("1");
ConnectTelescope();
_telescope.SyncToCoordinates(rightAscension, declination); _telescope.SyncToCoordinates(rightAscension, declination);
_sharedResourcesWrapperMock.Verify( x => x.SendString("#:CM#"), Times.Once); _sharedResourcesWrapperMock.Verify( x => x.SendString("#:CM#"), Times.Once);
@@ -2090,10 +2100,10 @@ namespace Meade.net.Telescope.UnitTests
[Test] [Test]
public void Slewing_WhenTelescopeIsSlewing_ThenReturnsTrue() public void Slewing_WhenTelescopeIsSlewing_ThenReturnsTrue()
{ {
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:D#")).Returns("|"); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:D#")).Returns("|");
ConnectTelescope();
var result = _telescope.Slewing; var result = _telescope.Slewing;
Assert.That(result, Is.True); Assert.That(result, Is.True);
@@ -2162,12 +2172,13 @@ namespace Meade.net.Telescope.UnitTests
[Test] [Test]
public void SlewToTargetAsync_WhenTargetSetAndSlewIsPossible_ThenAttemptsSlew() public void SlewToTargetAsync_WhenTargetSetAndSlewIsPossible_ThenAttemptsSlew()
{ {
_sharedResourcesWrapperMock.Setup(x => x.SendChar("#:MS#")).Returns("0");
ConnectTelescope(); ConnectTelescope();
_telescope.TargetRightAscension = 2; _telescope.TargetRightAscension = 2;
_telescope.TargetDeclination = 1; _telescope.TargetDeclination = 1;
_sharedResourcesWrapperMock.Setup(x => x.SendChar("#:MS#")).Returns("0");
_telescope.SlewToTargetAsync(); _telescope.SlewToTargetAsync();
@@ -2177,15 +2188,14 @@ namespace Meade.net.Telescope.UnitTests
[Test] [Test]
public void SlewToTargetAsync_WhenTargetBelowHorizon_ThenThrowsException() public void SlewToTargetAsync_WhenTargetBelowHorizon_ThenThrowsException()
{ {
_sharedResourcesWrapperMock.Setup(x => x.SendChar("#:MS#")).Returns("1");
_sharedResourcesWrapperMock.Setup(x => x.ReadTerminated()).Returns("Below horizon");
ConnectTelescope(); ConnectTelescope();
_telescope.TargetRightAscension = 2; _telescope.TargetRightAscension = 2;
_telescope.TargetDeclination = 1; _telescope.TargetDeclination = 1;
_sharedResourcesWrapperMock.Setup(x => x.SendChar("#:MS#")).Returns("1");
_sharedResourcesWrapperMock.Setup(x => x.ReadTerminated()).Returns("Below horizon");
var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.SlewToTargetAsync(); }); var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.SlewToTargetAsync(); });
Assert.That(exception.Message, Is.EqualTo("Below horizon")); Assert.That(exception.Message, Is.EqualTo("Below horizon"));
} }
@@ -2193,15 +2203,14 @@ namespace Meade.net.Telescope.UnitTests
[Test] [Test]
public void SlewToTargetAsync_WhenTargetBelowElevation_ThenThrowsException() public void SlewToTargetAsync_WhenTargetBelowElevation_ThenThrowsException()
{ {
_sharedResourcesWrapperMock.Setup(x => x.SendChar("#:MS#")).Returns("2");
_sharedResourcesWrapperMock.Setup(x => x.ReadTerminated()).Returns("Above below elevation");
ConnectTelescope(); ConnectTelescope();
_telescope.TargetRightAscension = 2; _telescope.TargetRightAscension = 2;
_telescope.TargetDeclination = 1; _telescope.TargetDeclination = 1;
_sharedResourcesWrapperMock.Setup(x => x.SendChar("#:MS#")).Returns("2");
_sharedResourcesWrapperMock.Setup(x => x.ReadTerminated()).Returns("Above below elevation");
var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.SlewToTargetAsync(); }); var exception = Assert.Throws<InvalidOperationException>(() => { _telescope.SlewToTargetAsync(); });
Assert.That(exception.Message, Is.EqualTo("Above below elevation")); Assert.That(exception.Message, Is.EqualTo("Above below elevation"));
} }
@@ -2216,11 +2225,6 @@ namespace Meade.net.Telescope.UnitTests
[Test] [Test]
public void SlewToTarget_WhenSlewing_ThenWaitsForTheSlewToComplete() public void SlewToTarget_WhenSlewing_ThenWaitsForTheSlewToComplete()
{ {
ConnectTelescope();
_telescope.TargetRightAscension = 2;
_telescope.TargetDeclination = 1;
_sharedResourcesWrapperMock.Setup(x => x.SendChar("#:MS#")).Returns("0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar("#:MS#")).Returns("0");
var slewCounter = 0; var slewCounter = 0;
@@ -2233,6 +2237,11 @@ namespace Meade.net.Telescope.UnitTests
return ""; return "";
}); });
ConnectTelescope();
_telescope.TargetRightAscension = 2;
_telescope.TargetDeclination = 1;
_telescope.SlewToTarget(); _telescope.SlewToTarget();
_utilMock.Verify( x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Exactly(iterations)); _utilMock.Verify( x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Exactly(iterations));
@@ -2251,8 +2260,6 @@ namespace Meade.net.Telescope.UnitTests
var rightAscension = 1; var rightAscension = 1;
var declination = 2; var declination = 2;
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendChar("#:MS#")).Returns("0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar("#:MS#")).Returns("0");
//var slewCounter = 0; //var slewCounter = 0;
@@ -2266,6 +2273,8 @@ namespace Meade.net.Telescope.UnitTests
// return ""; // return "";
//}); //});
ConnectTelescope();
_telescope.SlewToCoordinatesAsync(rightAscension, declination); _telescope.SlewToCoordinatesAsync(rightAscension, declination);
//_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Exactly(iterations)); //_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny<int>()), Times.Exactly(iterations));
@@ -2287,8 +2296,6 @@ namespace Meade.net.Telescope.UnitTests
var rightAscension = 1; var rightAscension = 1;
var declination = 2; var declination = 2;
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendChar("#:MS#")).Returns("0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar("#:MS#")).Returns("0");
var slewCounter = 0; var slewCounter = 0;
@@ -2301,6 +2308,8 @@ namespace Meade.net.Telescope.UnitTests
return ""; return "";
}); });
ConnectTelescope();
_telescope.SlewToCoordinates(rightAscension, declination); _telescope.SlewToCoordinates(rightAscension, declination);
Assert.That(_telescope.TargetRightAscension, Is.EqualTo(rightAscension)); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(rightAscension));
Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination));
@@ -2360,8 +2369,6 @@ namespace Meade.net.Telescope.UnitTests
var rightAscension = 20; var rightAscension = 20;
var declination = 10; var declination = 10;
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GC#")).Returns("10/15/20"); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GC#")).Returns("10/15/20");
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GL#")).Returns("20:15:10"); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GL#")).Returns("20:15:10");
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GG#")).Returns("-1.0"); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GG#")).Returns("-1.0");
@@ -2372,6 +2379,8 @@ namespace Meade.net.Telescope.UnitTests
_sharedResourcesWrapperMock.Setup(x => x.SendChar("#:MS#")).Returns("0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar("#:MS#")).Returns("0");
ConnectTelescope();
_telescope.SlewToAltAzAsync(azimuth, altitude); _telescope.SlewToAltAzAsync(azimuth, altitude);
Assert.That(_telescope.TargetRightAscension, Is.EqualTo(rightAscension)); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(rightAscension));
@@ -2394,8 +2403,6 @@ namespace Meade.net.Telescope.UnitTests
var azimuth = 30; var azimuth = 30;
var altitude = 40; var altitude = 40;
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GC#")).Returns("10/15/20"); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GC#")).Returns("10/15/20");
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GL#")).Returns("20:15:10"); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GL#")).Returns("20:15:10");
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GG#")).Returns("-1.0"); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GG#")).Returns("-1.0");
@@ -2416,6 +2423,8 @@ namespace Meade.net.Telescope.UnitTests
return ""; return "";
}); });
ConnectTelescope();
_telescope.SlewToAltAz( azimuth, altitude); _telescope.SlewToAltAz( azimuth, altitude);
Assert.That(_telescope.TargetRightAscension, Is.EqualTo(rightAscension)); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(rightAscension));
@@ -2448,8 +2457,6 @@ namespace Meade.net.Telescope.UnitTests
var mockHourAngle = 3; var mockHourAngle = 3;
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GC#")).Returns("10/15/20"); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GC#")).Returns("10/15/20");
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GL#")).Returns("20:15:10"); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GL#")).Returns("20:15:10");
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GG#")).Returns("-1.0"); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GG#")).Returns("-1.0");
@@ -2464,6 +2471,8 @@ namespace Meade.net.Telescope.UnitTests
_astroMathsMock.Setup(x => x.ConvertEqToHoz(mockHourAngle, It.IsAny<double>(), It.IsAny<EquatorialCoordinates>())).Returns(new HorizonCoordinates { Altitude = 45, Azimuth = expectedAzimuth }); _astroMathsMock.Setup(x => x.ConvertEqToHoz(mockHourAngle, It.IsAny<double>(), It.IsAny<EquatorialCoordinates>())).Returns(new HorizonCoordinates { Altitude = 45, Azimuth = expectedAzimuth });
ConnectTelescope();
var result = _telescope.Azimuth; var result = _telescope.Azimuth;
Assert.That(result,Is.EqualTo(expectedAzimuth)); Assert.That(result,Is.EqualTo(expectedAzimuth));
@@ -2493,8 +2502,6 @@ namespace Meade.net.Telescope.UnitTests
var mockHourAngle = 3; var mockHourAngle = 3;
ConnectTelescope();
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GC#")).Returns("10/15/20"); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GC#")).Returns("10/15/20");
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GL#")).Returns("20:15:10"); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GL#")).Returns("20:15:10");
_sharedResourcesWrapperMock.Setup(x => x.SendString("#:GG#")).Returns("-1.0"); _sharedResourcesWrapperMock.Setup(x => x.SendString("#:GG#")).Returns("-1.0");
@@ -2509,6 +2516,8 @@ namespace Meade.net.Telescope.UnitTests
_astroMathsMock.Setup(x => x.ConvertEqToHoz(mockHourAngle, It.IsAny<double>(), It.IsAny<EquatorialCoordinates>())).Returns(new HorizonCoordinates { Altitude = expectedAltitude, Azimuth = 200 }); _astroMathsMock.Setup(x => x.ConvertEqToHoz(mockHourAngle, It.IsAny<double>(), It.IsAny<EquatorialCoordinates>())).Returns(new HorizonCoordinates { Altitude = expectedAltitude, Azimuth = 200 });
ConnectTelescope();
var result = _telescope.Altitude; var result = _telescope.Altitude;
Assert.That(result, Is.EqualTo(expectedAltitude)); Assert.That(result, Is.EqualTo(expectedAltitude));
+9 -3
View File
@@ -389,9 +389,6 @@ namespace ASCOM.Meade.net
{ {
LogMessage("Connected Set", "Making first connection telescope adjustments"); LogMessage("Connected Set", "Making first connection telescope adjustments");
AlignmentModes alignmode = AlignmentMode;
LogMessage("Connected Set", alignmode.ToString());
//These settings are applied only when the first device connects to the telescope. //These settings are applied only when the first device connects to the telescope.
SetLongFormat(true); SetLongFormat(true);
@@ -401,6 +398,10 @@ namespace ASCOM.Meade.net
} }
SetTelescopePrecision("Connect"); SetTelescopePrecision("Connect");
var raAndDec = GetTelescopeRaAndDec();
LogMessage("Connected Set", $"Connected OK. Current RA = {_utilitiesExtra.HoursToHMS(raAndDec.RightAscension)} Dec = {_utilitiesExtra.DegreesToDMS(raAndDec.Declination)}");
} }
else else
{ {
@@ -492,7 +493,10 @@ namespace ASCOM.Meade.net
IsLongFormat = false; IsLongFormat = false;
if (!IsLongFormatSupported()) if (!IsLongFormatSupported())
{
LogMessage("SetLongFormat", "Long coordinate format not supported for this mount");
return; return;
}
_sharedResourcesWrapper.Lock(() => _sharedResourcesWrapper.Lock(() =>
{ {
@@ -513,6 +517,8 @@ namespace ASCOM.Meade.net
// Returns Nothing // Returns Nothing
} }
}); });
LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} ");
} }
private bool TogglePrecision() private bool TogglePrecision()