From d1b3f5718f1024df4e2a4b2d18ad1c037f4e7098 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 2 May 2019 13:00:52 +0100 Subject: [PATCH] Added unit tests for SiteLongitude --- .../TelescopeControllerUnitTests.cs | 73 ++++++++++++++++++- .../Controller/TelescopeController.cs | 2 +- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/MeadeAutostar497.UnitTests/TelescopeControllerUnitTests.cs b/MeadeAutostar497.UnitTests/TelescopeControllerUnitTests.cs index 3f48324..c47b9ef 100644 --- a/MeadeAutostar497.UnitTests/TelescopeControllerUnitTests.cs +++ b/MeadeAutostar497.UnitTests/TelescopeControllerUnitTests.cs @@ -267,9 +267,9 @@ namespace MeadeAutostar497.UnitTests Assert.That(exception.Message, Is.EqualTo("Failed to set local date")); } - [TestCase("+12:34", 12.566666666666666)] - [TestCase("+12:34.56", 12.582222222222223)] - [TestCase("-67:34.56", -67.582222222222214)] + [TestCase("+12*34", 12.566666666666666)] + [TestCase("+12*34.56", 12.582222222222223)] + [TestCase("-67*34.56", -67.582222222222214)] public void SiteLatitude_Get_ReturnsExpectedDouble( string latitude, double expectedResult) { serialMock.Setup(x => x.CommandTerminated(":Gt#", "#")).Returns(latitude); @@ -330,5 +330,72 @@ namespace MeadeAutostar497.UnitTests _telescopeController.SiteLatitude = 10; } + + + [TestCase("012*34", 12.566666666666666)] + [TestCase("012:34.56", 12.582222222222223)] + [TestCase("350:34.56", -9.4177777777777578)] + public void SiteLongitude_Get_ReturnsExpectedDouble(string longitude, double expectedResult) + { + serialMock.Setup(x => x.CommandTerminated(":Gg#", "#")).Returns(longitude); + + _isConnected = true; + + _telescopeController.Connected = true; + + var result = _telescopeController.SiteLongitude; + + Assert.That(result, Is.EqualTo(expectedResult)); + } + + [Test] + public void SiteLongitude_Set_ThrowsExeptionWhenValueTooSmall() + { + _isConnected = true; + + _telescopeController.Connected = true; + + var exception = Assert.Throws(() => { _telescopeController.SiteLongitude = -181; }); + + Assert.That(exception.Message, Is.EqualTo("Longitude cannot be lower than -180 degrees.")); + } + + [Test] + public void SiteLongitude_Set_ThrowsExeptionWhenValueTooLarge() + { + _isConnected = true; + + _telescopeController.Connected = true; + + var exception = Assert.Throws(() => { _telescopeController.SiteLongitude = 181; }); + + Assert.That(exception.Message, Is.EqualTo("Longitude cannot be greater than 180 degrees.")); + } + + [Test] + public void SiteLongitude_Set_ThrowsExeptionWhenTelescopeReportsFail() + { + _isConnected = true; + + _telescopeController.Connected = true; + + var exception = Assert.Throws(() => { _telescopeController.SiteLongitude = 10; }); + + Assert.That(exception.Message, Is.EqualTo("Failed to set site longitude.")); + } + + + + [Test] + public void SiteLongitude_Set_NoErrorWhenValidValueSentSuccessfully() + { + serialMock.Setup(x => x.CommandChar(":Sg010*00#")).Returns('1'); + + _isConnected = true; + + _telescopeController.Connected = true; + + _telescopeController.SiteLongitude = 10; + } } } diff --git a/MeadeAutostar497/Controller/TelescopeController.cs b/MeadeAutostar497/Controller/TelescopeController.cs index 0568b42..76569ae 100644 --- a/MeadeAutostar497/Controller/TelescopeController.cs +++ b/MeadeAutostar497/Controller/TelescopeController.cs @@ -243,7 +243,7 @@ namespace ASCOM.MeadeAutostar497.Controller var result = SerialPort.CommandChar($":Sg{d:000}*{m:00}#"); if (result != '1') - throw new InvalidOperationException("Failed to set site Longitude."); + throw new InvalidOperationException("Failed to set site longitude."); } }