From aeaaf9df954c7c136252283228df17f8665aff1a Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 18 Jul 2019 12:31:09 +0100 Subject: [PATCH] More unit testing --- .../TelescopeUnitTests.cs | 38 +++++++++++++++++++ Meade.net.Telescope/Telescope.cs | 1 - 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index c1a08c7..db8c115 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2009,5 +2009,43 @@ namespace Meade.net.Telescope.UnitTests var exception = Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); Assert.That(exception.Message, Is.EqualTo("Above below elevation")); } + + [Test] + public void SlewToTarget_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.SlewToTarget(); }); + Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewToTarget")); + } + + [Test] + public void SlewToTarget_WhenSlewing_ThenWaitsForTheSlewToComplete() + { + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE); + _telescope.Connected = true; + + _telescope.TargetRightAscension = 2; + _telescope.TargetDeclination = 1; + + _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); + + var slewCounter = 0; + var iterations = 10; + _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns(() => + { + slewCounter++; + if (slewCounter <= iterations) + return "|"; + else + return ""; + }); + + _telescope.SlewToTarget(); + + _utilMock.Verify( x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); + } } } diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index c97b264..9d82148 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -5,7 +5,6 @@ using System.Runtime.InteropServices; using ASCOM.Astrometry.AstroUtils; using ASCOM.Utilities; using ASCOM.DeviceInterface; -using System.Globalization; using System.Collections; using System.Reflection; using ASCOM.Meade.net.AstroMaths;