From 58992c29478ec9101d4706ade80077aeb8c07280 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 17 Jan 2021 18:04:24 +0000 Subject: [PATCH] More unit tests fixed --- .../TelescopeUnitTests.cs | 50 +++++++++++++++++-- Meade.net.Telescope/Telescope.cs | 2 +- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 2a0403c..2310575 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -422,6 +422,12 @@ namespace Meade.net.Telescope.UnitTests [Test] public void Connected_Set_SettingFalseWhenTrue_ThenDisconnects() { + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.2; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + ConnectTelescope(); _sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); @@ -978,18 +984,22 @@ namespace Meade.net.Telescope.UnitTests [Test] public void Declination_Get_WhenConnected_ThenReturnsExpectedResult() { - var telescopeRaResult = "s12*34’56"; + var telescopeDecResult = "s12*34’56"; var dmsResult = 1.2; + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.3; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeRaResult); - _utilMock.Setup(x => x.DMSToDegrees(telescopeRaResult)).Returns(dmsResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); ConnectTelescope(); var result = _telescope.Declination; _sharedResourcesWrapperMock.Verify(x => x.SendString(":GD#"), Times.Exactly(2)); - _utilMock.Verify(x => x.DMSToDegrees(telescopeRaResult), Times.Exactly(2)); + _utilMock.Verify(x => x.DMSToDegrees(telescopeDecResult), Times.Exactly(2)); Assert.That(result, Is.EqualTo(dmsResult)); } @@ -1304,6 +1314,12 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth)] public void PulseGuide_WhenConnectedAndNewerPulseGuidingAvailable_ThenSendsNewCommandsAndWaits(GuideDirections direction) { + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.2; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + var duration = 0; ConnectTelescope(); @@ -1370,6 +1386,16 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth)] public void PulseGuide_WhenConnectedAndNewerPulseGuidingNotAvailable_ThenIsSlewingRespondsFalse(GuideDirections direction) { + var telescopeDecResult = "s12*34’56"; + var dmsResult = 1.2; + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.3; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + var duration = 0; _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_30Ee); @@ -1393,6 +1419,16 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth)] public void PulseGuide_WhenConnectedAndNewerPulseGuidingNotAvailable_ThenSendsOldCommandsAndWaits(GuideDirections direction) { + var telescopeDecResult = "s12*34’56"; + var dmsResult = 1.2; + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.3; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + var duration = 0; _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_30Ee); @@ -1429,6 +1465,12 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth)] public void PulseGuide_WhenConnectedAndNewerPulseGuidingAvailableButDurationTooLong_ThenSendsOldCommandsAndWaits(GuideDirections direction) { + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.2; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + var duration = 10000; _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_30Ee); diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 7677c15..b91325c 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1550,7 +1550,7 @@ namespace ASCOM.Meade.net /// /// convert a HH:MM.T (classic LX200 RA Notation) string to a double hours. T is the decimal part of minutes which is converted into seconds /// - public double HMToHours(String hm) + public double HMToHours(string hm) { String[] token = hm.Split('.'); if (token.Length == 2)