From c2ecb1891c19aa6497ed0b029bb9b6993e8e1d7d Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 2 May 2019 12:50:22 +0100 Subject: [PATCH] Added SiteLatitude unit tests --- .../TelescopeControllerUnitTests.cs | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/MeadeAutostar497.UnitTests/TelescopeControllerUnitTests.cs b/MeadeAutostar497.UnitTests/TelescopeControllerUnitTests.cs index 600b538..3f48324 100644 --- a/MeadeAutostar497.UnitTests/TelescopeControllerUnitTests.cs +++ b/MeadeAutostar497.UnitTests/TelescopeControllerUnitTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO.Ports; +using ASCOM; using ASCOM.MeadeAutostar497.Controller; using Moq; using NUnit.Framework; @@ -265,5 +266,69 @@ 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)] + public void SiteLatitude_Get_ReturnsExpectedDouble( string latitude, double expectedResult) + { + serialMock.Setup(x => x.CommandTerminated(":Gt#", "#")).Returns(latitude); + + _isConnected = true; + + _telescopeController.Connected = true; + + var result = _telescopeController.SiteLatitude; + + Assert.That(result, Is.EqualTo(expectedResult)); + } + + [Test] + public void SiteLatitude_Set_ThrowsExeptionWhenValueTooSmall() + { + _isConnected = true; + + _telescopeController.Connected = true; + + var exception = Assert.Throws( () => { _telescopeController.SiteLatitude = -91;}); + + Assert.That(exception.Message, Is.EqualTo("Latitude cannot be less than -90 degrees.")); + } + + [Test] + public void SiteLatitude_Set_ThrowsExeptionWhenValueTooLarge() + { + _isConnected = true; + + _telescopeController.Connected = true; + + var exception = Assert.Throws(() => { _telescopeController.SiteLatitude = 91; }); + + Assert.That(exception.Message, Is.EqualTo("Latitude cannot be greater than 90 degrees.")); + } + + [Test] + public void SiteLatitude_Set_ThrowsExeptionWhenTelescopeReportsFail() + { + _isConnected = true; + + _telescopeController.Connected = true; + + var exception = Assert.Throws(() => { _telescopeController.SiteLatitude = 10; }); + + Assert.That(exception.Message, Is.EqualTo("Failed to set site latitude.")); + } + + [Test] + public void SiteLatitude_Set_NoErrorWhenValidValueSentSuccessfully() + { + serialMock.Setup(x => x.CommandChar(":Sts10*00#")).Returns('1'); + + _isConnected = true; + + _telescopeController.Connected = true; + + _telescopeController.SiteLatitude = 10; + } } }