diff --git a/AstroMath.UnitTests/AstroMathsUnitTests.cs b/AstroMath.UnitTests/AstroMathsUnitTests.cs index 2e4e37c..c9dc655 100644 --- a/AstroMath.UnitTests/AstroMathsUnitTests.cs +++ b/AstroMath.UnitTests/AstroMathsUnitTests.cs @@ -123,7 +123,8 @@ namespace AstroMath.UnitTests var altAz = _astroMath.ConvertEqToHoz(hourAngle, latitude, equatorialCoordinates); - Assert.That(altAz.Altitude, Is.EqualTo(20.958562421092779)); + Assert.That(altAz.Altitude, Is.GreaterThan(20.958562421092770)); + Assert.That(altAz.Altitude, Is.LessThanOrEqualTo(20.958562421092779)); Assert.That(altAz.Azimuth, Is.EqualTo(281.2728706962269)); } diff --git a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs index 9f945d2..e96a219 100644 --- a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs +++ b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs @@ -109,16 +109,17 @@ namespace Meade.net.Focuser.UnitTests Assert.That(exception.Message, Is.EqualTo("Not connected to focuser when trying to execute: CommandBlind")); } - [Test] - public void CommandBlind_WhenConnected_ThenSendsExpectedMessage() + [TestCase(false)] + [TestCase(true)] + public void CommandBlind_WhenConnected_ThenSendsExpectedMessage(bool raw) { string expectedMessage = "test blind Message"; ConnectFocuser(); - _focuser.CommandBlind(expectedMessage, true); + _focuser.CommandBlind(expectedMessage, raw); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedMessage), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedMessage, raw), Times.Once); } [Test] @@ -130,16 +131,19 @@ namespace Meade.net.Focuser.UnitTests Assert.That(exception.Message, Is.EqualTo("Not connected to focuser when trying to execute: CommandBool")); } - [Test] - public void CommandBool_WhenConnected_ThenSendsExpectedMessage() + [TestCase(false)] + [TestCase(true)] + public void CommandBool_WhenConnected_ThenSendsExpectedMessage(bool raw) { string expectedMessage = "test blind Message"; + _sharedResourcesWrapperMock.Setup(x => x.SendBool(expectedMessage, raw)).Returns(true); ConnectFocuser(); - var exception = Assert.Throws(() => { _focuser.CommandBool(expectedMessage, true); }); + var result = _focuser.CommandBool(expectedMessage, raw); - Assert.That(exception.Message, Is.EqualTo("Method CommandBool is not implemented in this driver.")); + _sharedResourcesWrapperMock.Verify(x => x.SendBool(expectedMessage, raw), Times.Once); + Assert.That(result, Is.True); } [Test] @@ -319,7 +323,7 @@ namespace Meade.net.Focuser.UnitTests _focuser.Halt(); - _sharedResourcesWrapperMock.Verify( x => x.SendBlind(":FQ#"), Times.AtLeastOnce); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("FQ", false), Times.AtLeastOnce); } [Test] @@ -334,13 +338,13 @@ namespace Meade.net.Focuser.UnitTests [TestCase(false)] [TestCase(true)] - public void Link_Get_ReturnsSameValueAsConnected( bool connected) + public void Link_Get_ReturnsSameValueAsConnected(bool connected) { _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_31Ee); _focuser.Connected = connected; - Assert.That( _focuser.Link, Is.EqualTo(connected)); + Assert.That(_focuser.Link, Is.EqualTo(connected)); } [TestCase(false)] @@ -394,12 +398,12 @@ namespace Meade.net.Focuser.UnitTests _focuser.Move(0); - _utilMock.Verify( x => x.WaitForMilliseconds(It.IsAny()), Times.Never); + _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Never); } [TestCase(200)] [TestCase(-200)] - public void Move_WhenIncrementIsNot0_ThenMovesFocuserAndStopsFocuser( int position) + public void Move_WhenIncrementIsNot0_ThenMovesFocuserAndStopsFocuser(int position) { _profileProperties.BacklashCompensation = 0; @@ -409,16 +413,16 @@ namespace Meade.net.Focuser.UnitTests if (position < 0) { - _sharedResourcesWrapperMock.Verify( x => x.SendBlind(":F-#"), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F+#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F-", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Never); } else { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F-#"), Times.Never); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F+#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F-", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Once); } - _sharedResourcesWrapperMock.Verify( x => x.Lock(It.IsAny()), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.Lock(It.IsAny()), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(_profileProperties.BacklashCompensation)), Times.Never); @@ -437,16 +441,16 @@ namespace Meade.net.Focuser.UnitTests if (position < 0) { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F-#"), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F+#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F-", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Never); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(_profileProperties.BacklashCompensation)), Times.Never); _utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Exactly(1)); } else { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F-#"), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F+#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F-", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position) + _profileProperties.BacklashCompensation), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(_profileProperties.BacklashCompensation), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Exactly(2)); @@ -503,7 +507,7 @@ namespace Meade.net.Focuser.UnitTests { var exception = Assert.Throws(() => { - var result = _focuser.Temperature; + var result = _focuser.Temperature; Assert.Fail($"{result} should not have a value"); }); Assert.That(exception.Message, Is.EqualTo("Property read Temperature is not implemented in this driver.")); diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index f0a46d7..a917901 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2,7 +2,9 @@ using System.Globalization; using System.Reflection; using ASCOM; +using ASCOM.Astrometry; using ASCOM.Astrometry.AstroUtils; +using ASCOM.Astrometry.NOVAS; using ASCOM.DeviceInterface; using ASCOM.Meade.net; using ASCOM.Meade.net.AstroMaths; @@ -17,11 +19,19 @@ namespace Meade.net.Telescope.UnitTests public class TestProperties { internal string telescopeRaResult = "HH:MM:SS"; - internal double rightAscension = 1.2; //todo rename to RightAscension; + internal double rightAscension = 1.2; //todo rename to declination; + internal double declination = 45; internal string SiteLatitudeString = "testLatString"; internal double SiteLatitudeValue = 123.45; + internal string telescopeDate = "10/15/20"; + internal string telescopeTime = "20:15:10"; + internal string telescopeUtcCorrection = "-1.0"; + + internal double hourAngle; + internal int telescopeAltitude = 45; + internal int telescopeAzimuth = 200; } [TestFixture] @@ -34,15 +44,22 @@ namespace Meade.net.Telescope.UnitTests private Mock _sharedResourcesWrapperMock; private Mock _astroMathsMock; private Mock _clockMock; + private Mock _novasMock; private ProfileProperties _profileProperties; private ConnectionInfo _connectionInfo; private TestProperties _testProperties; + private bool _isParked; + private ParkedPosition _parkedPosition; + [SetUp] public void Setup() { + _isParked = false; + _parkedPosition = null; + _testProperties = new TestProperties(); _profileProperties = new ProfileProperties @@ -70,7 +87,7 @@ namespace Meade.net.Telescope.UnitTests _astroUtilsMock = new Mock(); _sharedResourcesWrapperMock = new Mock(); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM’SS"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MM’SS"); _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(() =>_profileProperties); _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny())).Callback(action => { action(); }); @@ -83,29 +100,58 @@ namespace Meade.net.Telescope.UnitTests SameDevice = 1 }; - _sharedResourcesWrapperMock.Setup(x => x.Connect("Serial", It.IsAny(), It.IsAny())).Returns( () => _connectionInfo ); - + _sharedResourcesWrapperMock.Setup(x => x.Connect("Serial", It.IsAny(), It.IsAny())).Returns( () => _connectionInfo); _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(_profileProperties); + _sharedResourcesWrapperMock + .SetupProperty(x => x.SideOfPier) + .SetupProperty(x => x.TargetRightAscension) + .SetupProperty(x => x.TargetDeclination) + .SetupProperty(x => x.SlewSettleTime) + .SetupProperty(x => x.IsLongFormat); + _astroMathsMock = new Mock(); _clockMock = new Mock(); + _novasMock = new Mock(); + _telescope = new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, - _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object); + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object); } private void ConnectTelescope(string productName = TelescopeList.Autostar497, string firmwareVersion = TelescopeList.Autostar497_31Ee) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gt#", true)).Returns(_testProperties.SiteLatitudeString); - _utilMock.Setup(x => x.DMSToDegrees(_testProperties.SiteLatitudeString)).Returns(_testProperties.SiteLatitudeValue); + _sharedResourcesWrapperMock.Setup(x => x.SendString("Gt", false)).Returns( () => _testProperties.SiteLatitudeString); + _utilMock.Setup(x => x.DMSToDegrees(_testProperties.SiteLatitudeString)).Returns( () => _testProperties.SiteLatitudeValue); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#", true)).Returns(_testProperties.telescopeRaResult); - _utilMock.Setup(x => x.HMSToHours(_testProperties.telescopeRaResult)).Returns(_testProperties.rightAscension); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GR", false)).Returns( () =>_testProperties.telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(_testProperties.telescopeRaResult)).Returns( () => _testProperties.rightAscension); + + _sharedResourcesWrapperMock.Setup(x => x.SendString("GC", false)).Returns(() => _testProperties.telescopeDate); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GL", false)).Returns(() => _testProperties.telescopeTime); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns(() => _testProperties.telescopeUtcCorrection); _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => productName); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => firmwareVersion); + + _sharedResourcesWrapperMock.Setup(x => x.SetParked(It.IsAny(), It.IsAny())).Callback((isParked, parkedPostion) => { + _isParked = isParked; + _parkedPosition = parkedPostion; + }); + + _sharedResourcesWrapperMock.SetupGet(x => x.IsParked).Returns(() => _isParked); + _sharedResourcesWrapperMock.SetupGet(x => x.ParkedPosition).Returns(() => _parkedPosition); + + _astroMathsMock + .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny())).Returns(() => new EquatorialCoordinates { Declination = _testProperties.declination, RightAscension = _testProperties.rightAscension }); + + _astroMathsMock.Setup(x => x.RightAscensionToHourAngle(It.IsAny(), It.IsAny(), It.IsAny())).Returns(() =>_testProperties.hourAngle); + + _astroMathsMock.Setup(x => x.ConvertEqToHoz(_testProperties.hourAngle, It.IsAny(), It.IsAny())).Returns(new HorizonCoordinates { Altitude = _testProperties.telescopeAltitude, Azimuth = _testProperties.telescopeAzimuth }); + _telescope.Connected = true; } @@ -146,10 +192,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void Action_WhenNotConnected_ThrowsNotConnectedException() { - var exception = Assert.Throws(() => - { - _telescope.Action(string.Empty, string.Empty); - }); + var exception = Assert.Throws(() => _telescope.Action(string.Empty, string.Empty) ); Assert.That(exception.Message,Is.EqualTo("Not connected to telescope when trying to execute: Action")); } @@ -157,43 +200,43 @@ namespace Meade.net.Telescope.UnitTests public void Action_Handbox_ReadDisplay() { string expectedResult = "test result string"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":ED#", true)).Returns(expectedResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); _telescope.Connected = true; - + var actualResult = _telescope.Action("handbox", "readdisplay"); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":ED#", true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("ED", false), Times.Once); Assert.That(actualResult, Is.EqualTo(expectedResult)); } - [TestCase("enter", ":EK13#")] - [TestCase("mode", ":EK9#")] - [TestCase("longMode", ":EK11#")] - [TestCase("goto", ":EK24#")] - [TestCase("0", ":EK48#")] - [TestCase("1", ":EK49#")] - [TestCase("2", ":EK50#")] - [TestCase("3", ":EK51#")] - [TestCase("4", ":EK52#")] - [TestCase("5", ":EK53#")] - [TestCase("6", ":EK54#")] - [TestCase("7", ":EK55#")] - [TestCase("8", ":EK56#")] - [TestCase("9", ":EK57#")] - [TestCase("up", ":EK94#")] - [TestCase("down", ":EK118#")] - [TestCase("back", ":EK87#")] - [TestCase("forward", ":EK69#")] - [TestCase("?", ":EK63#")] + [TestCase("enter", "EK13")] + [TestCase("mode", "EK9")] + [TestCase("longMode", "EK11")] + [TestCase("goto", "EK24")] + [TestCase("0", "EK48")] + [TestCase("1", "EK49")] + [TestCase("2", "EK50")] + [TestCase("3", "EK51")] + [TestCase("4", "EK52")] + [TestCase("5", "EK53")] + [TestCase("6", "EK54")] + [TestCase("7", "EK55")] + [TestCase("8", "EK56")] + [TestCase("9", "EK57")] + [TestCase("up", "EK94")] + [TestCase("down", "EK118")] + [TestCase("back", "EK87")] + [TestCase("forward", "EK69")] + [TestCase("?", "EK63")] public void Action_Handbox_WhenCalling_ThenSendsAppropriateBlindCommands(string action, string expectedString) { ConnectTelescope(); _telescope.Action("handbox", action); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedString), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedString, false), Times.Once); } [TestCase("1")] @@ -207,7 +250,7 @@ namespace Meade.net.Telescope.UnitTests string parameters = $"select {site}"; _telescope.Action("site", parameters); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":W{site}#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"W{site}", false), Times.Once); } [TestCase("0")] @@ -217,25 +260,25 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); string parameters = $"select {site}"; - var exception = Assert.Throws(() => { _telescope.Action("site", parameters); }); + var exception = Assert.Throws(() => _telescope.Action("site", parameters) ); Assert.That(exception.Message, Is.EqualTo($"Site {parameters} not allowed, must be between 1 and 4")); } - [TestCase("1", ":GM#", "Home")] - [TestCase("2", ":GN#", "Club")] - [TestCase("3", ":GO#", "GPS")] - [TestCase("4", ":GP#", "Parents")] + [TestCase("1", "GM", "Home")] + [TestCase("2", "GN", "Club")] + [TestCase("3", "GO", "GPS")] + [TestCase("4", "GP", "Parents")] public void Action_Site_GetName_WhenCallingWithValidValues_ThenSelectsCorrectSite(string site, string telescopeCommand, string siteName) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(telescopeCommand, true)).Returns(siteName); + _sharedResourcesWrapperMock.Setup(x => x.SendString(telescopeCommand, false)).Returns(siteName); ConnectTelescope(); string parameters = $"GetName {site}"; var result = _telescope.Action("site", parameters); - _sharedResourcesWrapperMock.Verify(x => x.SendString(telescopeCommand, true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(telescopeCommand, false), Times.Once); Assert.That(result, Is.EqualTo(siteName)); } @@ -246,7 +289,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); string parameters = $"GetName {site}"; - var exception = Assert.Throws(() => { _telescope.Action("site", parameters); }); + var exception = Assert.Throws(() => _telescope.Action("site", parameters) ); Assert.That(exception.Message, Is.EqualTo($"Site {parameters} not allowed, must be between 1 and 4")); } @@ -262,21 +305,21 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.EqualTo("4")); } - [TestCase("1", ":SMHome#", "Home")] - [TestCase("2", ":SNClub#", "Club")] - [TestCase("3", ":SOGPS Site#", "GPS Site")] - [TestCase("4", ":SPParents#", "Parents")] + [TestCase("1", "SMHome", "Home")] + [TestCase("2", "SNClub", "Club")] + [TestCase("3", "SOGPS Site", "GPS Site")] + [TestCase("4", "SPParents", "Parents")] public void Action_Site_SetName_WhenCallingWithValidValues_ThenSelectsCorrectSite(string site, string telescopeCommand, string siteName) { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(telescopeCommand)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(telescopeCommand, false)).Returns("1"); ConnectTelescope(); string parameters = $"SetName {site} {siteName}"; _telescope.Action("site", parameters); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(telescopeCommand), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(telescopeCommand, false), Times.Once); } [TestCase("0")] @@ -286,7 +329,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); string parameters = $"SetName {site}"; - var exception = Assert.Throws(() => { _telescope.Action("site", parameters); }); + var exception = Assert.Throws(() => _telescope.Action("site", parameters)); Assert.That(exception.Message, Is.EqualTo($"Site {parameters} not allowed, must be between 1 and 4")); } @@ -297,7 +340,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); string parameters = "unknown"; - var exception = Assert.Throws(() => { _telescope.Action("site", parameters); }); + var exception = Assert.Throws(() => _telescope.Action("site", parameters)); Assert.That(exception.Message, Is.EqualTo($"Site parameters {parameters} not known")); } @@ -309,7 +352,7 @@ namespace Meade.net.Telescope.UnitTests string actionName = "handbox"; string actionParameters = "doesnotexist"; - var exception = Assert.Throws(() => { _telescope.Action(actionName, actionParameters); }); + var exception = Assert.Throws(() => _telescope.Action(actionName, actionParameters)); Assert.That(exception.Message, Is.EqualTo($"Action {actionName}({actionParameters}) is not implemented in this driver is not implemented in this driver.")); } @@ -320,7 +363,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); string actionName = "doesnotexist"; - var exception = Assert.Throws(() => { _telescope.Action(actionName, string.Empty); }); + var exception = Assert.Throws(() => _telescope.Action(actionName, string.Empty)); Assert.That(exception.Message, Is.EqualTo($"Action {actionName} is not implemented in this driver is not implemented in this driver.")); } @@ -329,66 +372,72 @@ namespace Meade.net.Telescope.UnitTests public void CommandBlind_WhenNotConnected_ThenThrowsNotConnectedException() { string expectedMessage = "test blind Message"; - var exception = Assert.Throws(() => { _telescope.CommandBlind(expectedMessage, true); }); + var exception = Assert.Throws(() => _telescope.CommandBlind(expectedMessage, true)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: CommandBlind")); } - [Test] - public void CommandBlind_WhenConnected_ThenSendsExpectedMessage() + [TestCase(false)] + [TestCase(true)] + public void CommandBlind_WhenConnected_ThenSendsExpectedMessage(bool raw) { string expectedMessage = "test blind Message"; ConnectTelescope(); - _telescope.CommandBlind(expectedMessage, true); + _telescope.CommandBlind(expectedMessage, raw); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedMessage), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedMessage, raw), Times.Once); } [Test] public void CommandBool_WhenNotConnected_ThenThrowsNotConnectedException() { string expectedMessage = "test blind Message"; - var exception = Assert.Throws(() => { _telescope.CommandBool(expectedMessage, true); }); + var exception = Assert.Throws(() => _telescope.CommandBool(expectedMessage, true)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: CommandBool")); } - [Test] - public void CommandBool_WhenConnected_ThenSendsExpectedMessage() + + [TestCase(false)] + [TestCase(true)] + public void CommandBool_WhenConnected_ThenSendsExpectedMessage(bool raw) { string expectedMessage = "test blind Message"; + _sharedResourcesWrapperMock.Setup(x => x.SendBool(expectedMessage, raw)).Returns(true); ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.CommandBool(expectedMessage, true); }); + var result = _telescope.CommandBool(expectedMessage, raw); - Assert.That(exception.Message, Is.EqualTo("Method CommandBool is not implemented in this driver.")); + _sharedResourcesWrapperMock.Verify(x => x.SendBool(expectedMessage, raw), Times.Once); + Assert.That(result, Is.True); } [Test] public void CommandString_WhenNotConnected_ThenThrowsNotConnectedException() { string expectedMessage = "test blind Message"; - var exception = Assert.Throws(() => { _telescope.CommandString(expectedMessage, true); }); + var exception = Assert.Throws(() => _telescope.CommandString(expectedMessage, true)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: CommandString")); } - [Test] - public void CommandString_WhenConnected_ThenSendsExpectedMessage() + [TestCase(false)] + [TestCase(true)] + public void CommandString_WhenConnected_ThenSendsExpectedMessage(bool raw) { string expectedMessage = "expected result message"; string sendMessage = "test blind Message"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage, true)).Returns(() => expectedMessage); + _sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage, raw)).Returns(() => expectedMessage); ConnectTelescope(); - var actualMessage = _telescope.CommandString(sendMessage, true); + var actualMessage = _telescope.CommandString(sendMessage, raw); - _sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage, true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage, raw), Times.Once); Assert.That(actualMessage, Is.EqualTo(expectedMessage)); } @@ -401,46 +450,45 @@ namespace Meade.net.Telescope.UnitTests if (expectedConnected) ConnectTelescope(); - + Assert.That(_telescope.Connected, Is.EqualTo(expectedConnected)); if (expectedConnected) { - _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#", true), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Never); } } - + [Test] public void Connected_Set_WhenConnectingLX200GPS_Then_ConnectsToSerialDevice() { ConnectTelescope(TelescopeList.LX200GPS, string.Empty); - _sharedResourcesWrapperMock.Verify( x => x.Connect("Serial", It.IsAny(), It.IsAny()), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#", true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.Connect("Serial", It.IsAny(), It.IsAny()), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"),Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Once); } [Test] public void Connected_WhenConnectingLX200GPSAndSendDateTimeIsTrue_Then_SpecialStartupInstructionSendOnFirstConnect() { _profileProperties.SendDateTime = true; - + _testProperties.telescopeUtcCorrection = "0"; DateTime testNow = DateTime.ParseExact("2021-10-03T20:36:25", "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); - _clockMock.Setup(x => x.UtcNow).Returns(() => { return testNow; }); + _clockMock.Setup(x => x.UtcNow).Returns(() => testNow); - string setDateCommand = $":hI{testNow:yyMMddHHmmss}#"; + string setDateCommand = $"hI{testNow:yyMMddHHmmss}"; string expectedResult = "Daylight Savings Time:"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":ED#", true)).Returns(expectedResult); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("0"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(setDateCommand)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(setDateCommand, false)).Returns("1"); ConnectTelescope(TelescopeList.LX200GPS, string.Empty); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand, false), Times.Once); } [Test] @@ -450,26 +498,22 @@ namespace Meade.net.Telescope.UnitTests string telescopeTime = "20:36:25"; string telescopeDate = "10/03/21"; + _testProperties.telescopeUtcCorrection = "0"; DateTime endSlewingDatetime = DateTime.ParseExact("2021-10-03T20:36:25", "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); - _clockMock.Setup(x => x.UtcNow).Returns(() => - { - return endSlewingDatetime; - }); + _clockMock.Setup(x => x.UtcNow).Returns(() => endSlewingDatetime); - string setDateCommand = $":hI{endSlewingDatetime:yyMMddHHmmss}#"; + string setDateCommand = $"hI{endSlewingDatetime:yyMMddHHmmss}"; string expectedResult = "Align"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":ED#", true)).Returns(expectedResult); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{telescopeDate}", false)).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SC{telescopeDate}#")).Returns("1"); - ConnectTelescope(TelescopeList.LX200GPS, string.Empty); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand, false), Times.Never); _sharedResourcesWrapperMock.Verify(x => x.ReadTerminated(), Times.Exactly(2)); } @@ -480,6 +524,7 @@ namespace Meade.net.Telescope.UnitTests string telescopeTime = "20:36:25"; string telescopeDate = "10/03/21"; + _testProperties.telescopeUtcCorrection = "0"; DateTime endSlewingDatetime = DateTime.ParseExact("2021-10-03T20:36:25", "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); _clockMock.Setup(x => x.UtcNow).Returns(() => @@ -487,19 +532,18 @@ namespace Meade.net.Telescope.UnitTests return endSlewingDatetime; }); - string setDateCommand = $":hI{endSlewingDatetime:yyMMddHHmmss}#"; + string setDateCommand = $"hI{endSlewingDatetime:yyMMddHHmmss}"; string expectedResult = "Align"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":ED#", true)).Returns(expectedResult); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SC{telescopeDate}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{telescopeDate}", false)).Returns("1"); ConnectTelescope(); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand, false), Times.Never); _sharedResourcesWrapperMock.Verify(x => x.ReadTerminated(), Times.Exactly(2)); } @@ -514,8 +558,8 @@ namespace Meade.net.Telescope.UnitTests _telescope.Connected = true; _sharedResourcesWrapperMock.Verify(x => x.Connect("Serial", It.IsAny(), It.IsAny()), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#", true), Times.Never); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Never); } @@ -523,7 +567,7 @@ namespace Meade.net.Telescope.UnitTests public void Connected_Set_SettingTrueWhenTrue_ThenDoesNothing() { ConnectTelescope(); - _sharedResourcesWrapperMock.Verify( x => x.Connect(It.IsAny(), It.IsAny(), It.IsAny()),Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); //act _telescope.Connected = true; @@ -561,15 +605,15 @@ namespace Meade.net.Telescope.UnitTests } [TestCase("Auto", "Autostar", "30Ab", false)] - [TestCase("Auto","Autostar", "31Ee", true)] - [TestCase("Auto","Autostar", "43Eg", true)] - [TestCase("Auto","Autostar", "A4S4", true)] - [TestCase("Auto","Autostar II", "", false)] - [TestCase("Auto","LX2001", "", true)] - [TestCase("Auto",":GVP", "", false)] //LX200 Classic + [TestCase("Auto", "Autostar", "31Ee", true)] + [TestCase("Auto", "Autostar", "43Eg", true)] + [TestCase("Auto", "Autostar", "A4S4", true)] + [TestCase("Auto", "Autostar II", "", false)] + [TestCase("Auto", "LX2001", "", true)] + [TestCase("Auto", ":GVP", "", false)] //LX200 Classic [TestCase("Guide Rate Slew", "LX2001", "", false)] //force old style [TestCase("Pulse Guiding", ":GVP", "", true)] //force new style - + public void IsNewPulseGuidingSupported_ThenIsSupported_ThenReturnsTrue(string guidingStyle, string productName, string firmware, bool isSupported) { _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); @@ -587,43 +631,43 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SetLongFormatFalse_WhenTelescopeReturnsShortFormat_ThenDoesNothing() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MM"); _telescope.SetLongFormat(false); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"),Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("U", false), Times.Never); } [Test] public void SetLongFormatFalse_WhenTelescopeReturnsLongFormat_ThenTogglesPrecision() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM’SS"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MM’SS"); _telescope.SetLongFormat(false); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("U", false), Times.Once); } [Test] public void SetLongFormatTrue_WhenTelescopeReturnsLongFormat_ThenDoesNothing() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM’SS"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MM’SS"); _telescope.SetLongFormat(true); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("U", false), Times.Never); } [Test] public void SetLongFormatTrue_WhenTelescopeReturnsShortFormat_ThenTogglesPrecision() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MM"); _telescope.SetLongFormat(true); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("U", false), Times.Once); } [Test] public void SelectSite_Get_WhenNotConnected_ThrowsException() { - var exception = Assert.Throws(() => { _telescope.SelectSite(1); }); + var exception = Assert.Throws(() => _telescope.SelectSite(1)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SelectSite")); } @@ -633,7 +677,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); var site = 0; - var result = Assert.Throws(() => { _telescope.SelectSite(site); }); + var result = Assert.Throws(() => _telescope.SelectSite(site)); Assert.That(result.Message, Is.EqualTo($"Site cannot be lower than 1\r\nParameter name: site\r\nActual value was {site}.")); } @@ -644,7 +688,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); var site = 5; - var result = Assert.Throws(() => { _telescope.SelectSite(site); }); + var result = Assert.Throws(() => _telescope.SelectSite(site)); Assert.That(result.Message, Is.EqualTo($"Site cannot be higher than 4\r\nParameter name: site\r\nActual value was {site}.")); } @@ -659,7 +703,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.SelectSite(site); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":W{site}#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"W{site}", false), Times.Once); } [Test] @@ -733,13 +777,13 @@ namespace Meade.net.Telescope.UnitTests public void AlignmentMode_Get_WhenScopeInAltAz_ReturnsAltAz(string telescopeMode, AlignmentModes alignmentMode, string productName, string firmware) { const char ack = (char)6; - _sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString())).Returns(telescopeMode); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GW#")).Returns($"{telescopeMode}N0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString(), false)).Returns(telescopeMode); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GW", false)).Returns($"{telescopeMode}N0"); ConnectTelescope(productName, firmware); - + var actualResult = _telescope.AlignmentMode; - + Assert.That(actualResult, Is.EqualTo(alignmentMode)); } @@ -758,13 +802,13 @@ namespace Meade.net.Telescope.UnitTests [Test] public void AlignmentMode_Set_WhenNotConnected_ThrowsException() { - var exception = Assert.Throws(() => { _telescope.AlignmentMode = AlignmentModes.algAltAz; }); + var exception = Assert.Throws(() => _telescope.AlignmentMode = AlignmentModes.algAltAz); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: AlignmentMode Set")); } - [TestCase("AUTOSTAR", "43Eg", AlignmentModes.algAltAz, ":AA#")] - [TestCase("AUTOSTAR", "43Eg", AlignmentModes.algPolar, ":AP#")] - [TestCase("AUTOSTAR", "43Eg", AlignmentModes.algGermanPolar, ":AP#")] + [TestCase("AUTOSTAR", "43Eg", AlignmentModes.algAltAz, "AA")] + [TestCase("AUTOSTAR", "43Eg", AlignmentModes.algPolar, "AP")] + [TestCase("AUTOSTAR", "43Eg", AlignmentModes.algGermanPolar, "AP")] public void AlignmentMode_Set_WhenConnected_ThenSendsExpectedCommand(string productName, string firmware, AlignmentModes alignmentMode, string expectedCommand) { _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); @@ -773,17 +817,17 @@ namespace Meade.net.Telescope.UnitTests _telescope.AlignmentMode = alignmentMode; - _sharedResourcesWrapperMock.Verify( x => x.SendBlind(expectedCommand), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedCommand, false), Times.Once); } [TestCase("AUTOSTAR", "43Ef")] - public void AlignmentMode_Set_WhenAutostarFirmwareToLow_ThenThrowsException(string productName, string firmware ) + public void AlignmentMode_Set_WhenAutostarFirmwareToLow_ThenThrowsException(string productName, string firmware) { _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware); _telescope.Connected = true; - var excpetion = Assert.Throws(() => { _telescope.AlignmentMode = AlignmentModes.algAltAz; }); + var excpetion = Assert.Throws(() => _telescope.AlignmentMode = AlignmentModes.algAltAz); Assert.That(excpetion.Property, Is.EqualTo("AlignmentMode")); Assert.That(excpetion.AccessorSet, Is.True); @@ -904,7 +948,7 @@ namespace Meade.net.Telescope.UnitTests }); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: CanSetGuideRates Get")); } - + [Test] public void CanSetGuideRates_Get_WhenConnectedToAutostar_ThenReturnsFalse() { @@ -932,7 +976,7 @@ namespace Meade.net.Telescope.UnitTests { _telescope.Connected = true; - _sharedResourcesWrapperMock.Verify( x => x.SendString(":P#", true), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString("P", false), Times.Never); } [TestCase("High", false, true)] @@ -944,7 +988,7 @@ namespace Meade.net.Telescope.UnitTests _profileProperties.Precision = desiredPresision; var currentPrecision = telescopePrecision; - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":P#")).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendChar("P", false)).Returns(() => { currentPrecision = !currentPrecision; @@ -960,23 +1004,88 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); Assert.That(currentPrecision, Is.EqualTo(finalPrecision)); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(":P#"), Times.AtLeastOnce); + _sharedResourcesWrapperMock.Verify(x => x.SendChar("P", false), Times.AtLeastOnce); } - [TestCase("High", false, true)] - [TestCase("High", true, true)] - [TestCase("Low", false, false)] - [TestCase("Low", true, false)] - public void Precision_Set_WhenSecondConnectionMade_ThenTelescopePrecisionNotChanged(string desiredPresision, bool telescopePrecision, bool finalPrecision) + [TestCase("High")] + [TestCase("Low")] + public void Precision_Set_WhenSecondConnectionMade_ThenTelescopePrecisionNotChanged(string desiredPresision) { + var isLongFormat = desiredPresision == "High" + || (desiredPresision == "Low" + ? false + : throw new ArgumentOutOfRangeException(nameof(desiredPresision), desiredPresision, "Should be High or Low")); + _sharedResourcesWrapperMock.SetupProperty(x => x.IsLongFormat, isLongFormat); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GR", false)).Returns(() => _testProperties.telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(_testProperties.telescopeRaResult)).Returns(() => _testProperties.rightAscension); + _profileProperties.Precision = desiredPresision; _connectionInfo.SameDevice = 2; //_connectionInfo.Connections = 2; + _telescope.Connected = true; - _sharedResourcesWrapperMock.Verify(x => x.SendChar(":P#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendChar("P", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.IsLongFormat, Times.Once); + } + + [Test] + public void IsLongFormat_WhenHighPrecisionNotSupportedAndSecondConnectionMade_ThenDigitPrecisionValuesArePreserved() + { + var ra = 12d; + var dec = 34d; + + _utilMock.Setup(x => x.HoursToHM(ra, ":", "", 1)).Returns(ra + "HM"); + _utilMock.Setup(x => x.DegreesToDM(dec, "*", "", 0)).Returns(dec + "DM"); + + ConnectTelescope(TelescopeList.LX200CLASSIC); + + _telescope.TargetRightAscension = ra; + _telescope.TargetDeclination = dec; + + Assert.That(_connectionInfo.SameDevice, Is.EqualTo(1)); + + var secondTelescopeInstance = + new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object); + + Assert.That(secondTelescopeInstance.Connected, Is.False); + + _connectionInfo.SameDevice = 2; + secondTelescopeInstance.Connected = true; + + secondTelescopeInstance.TargetRightAscension = ra; + secondTelescopeInstance.TargetDeclination = dec; + + _utilMock.Verify(x => x.HoursToHM(ra, ":", "", 1), Times.Exactly(2)); + _utilMock.Verify(x => x.DegreesToDM(dec, "*", "", 0), Times.Exactly(2)); + _utilMock.Verify(x => x.HoursToHMS(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), 2), Times.Never); + _utilMock.Verify(x => x.DegreesToDMS(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), 2), Times.Never); + } + + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void SlewSettleTime_WhenSecondConnectionMade_ThenSlewSettleTimeIsPreserved(short slewSettleTime) + { + ConnectTelescope(); + + _telescope.SlewSettleTime = slewSettleTime; + + Assert.That(_connectionInfo.SameDevice, Is.EqualTo(1)); + + var secondTelescopeInstance = + new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object); + + Assert.That(secondTelescopeInstance.Connected, Is.False); + + _connectionInfo.SameDevice = 2; + secondTelescopeInstance.Connected = true; + + Assert.That(secondTelescopeInstance.SlewSettleTime, Is.EqualTo(slewSettleTime)); } [Test] @@ -1099,10 +1208,10 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(productVersion, firmware); if (canUnPark) - Assert.DoesNotThrow(() => { _telescope.Unpark(); }); + Assert.DoesNotThrow(() => _telescope.Unpark()); else { - var exception = Assert.Throws(() => { _telescope.Unpark(); }); + var exception = Assert.Throws(() => _telescope.Unpark()); Assert.That(exception.Message, Is.EqualTo("Unable to unpark this telescope type")); } @@ -1124,7 +1233,7 @@ namespace Meade.net.Telescope.UnitTests public void Declination_Get_WhenConnected_ThenReadsValueFromScope(string declincationString) { var expectedResult = 12.34; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(declincationString); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(declincationString); _utilMock.Setup(x => x.DMSToDegrees(declincationString)).Returns(expectedResult); ConnectTelescope(); @@ -1138,15 +1247,15 @@ namespace Meade.net.Telescope.UnitTests { var telescopeDecResult = "s12*34’56"; var dmsResult = 1.2; - - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); + + _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); ConnectTelescope(); var result = _telescope.Declination; - _sharedResourcesWrapperMock.Verify(x => x.SendString(":GD#", true), Times.Exactly(2)); + _sharedResourcesWrapperMock.Verify(x => x.SendString("GD", false), Times.Exactly(2)); _utilMock.Verify(x => x.DMSToDegrees(telescopeDecResult), Times.Exactly(2)); Assert.That(result, Is.EqualTo(dmsResult)); @@ -1156,29 +1265,108 @@ namespace Meade.net.Telescope.UnitTests public void DeclinationRate_Get_ThenReturns0() { var actualResult = _telescope.DeclinationRate; - + Assert.That(actualResult, Is.EqualTo(0)); } [Test] public void DeclinationRate_Set_ThenThrowsException() { - var excpetion = Assert.Throws(() => { _telescope.DeclinationRate = 0; }); + var excpetion = Assert.Throws(() => _telescope.DeclinationRate = 0); Assert.That(excpetion.Property, Is.EqualTo("DeclinationRate")); Assert.That(excpetion.AccessorSet, Is.True); } [Test] - public void DestinationSideOfPier_ThenThrowsException() + public void DestinationSideOfPier_WhenNotConnected_ThenThrowsException() { - var excpetion = Assert.Throws(() => + var excpetion = Assert.Throws(() => { - var result = _telescope.DestinationSideOfPier(0,0); + var result = _telescope.DestinationSideOfPier(0, 0); Assert.Fail($"{result} should not have returned"); }); - Assert.That(excpetion.Method, Is.EqualTo("DestinationSideOfPier")); + Assert.That(excpetion.Message, Is.EqualTo("Not connected to telescope when trying to execute: DestinationSideOfPier")); + } + + [TestCase(1, 1, 4, PierSide.pierEast)] + [TestCase(1, -1, 4, PierSide.pierEast)] + [TestCase(4, 1, 1, PierSide.pierWest)] + [TestCase(4, -1, 1, PierSide.pierWest)] + [TestCase(0, 0, 0, PierSide.pierUnknown)] + [TestCase(5, 0, 5, PierSide.pierUnknown)] + [TestCase(23.8, 1, 23.9, PierSide.pierEast)] + [TestCase(23.8, -1, 23.9, PierSide.pierEast)] + [TestCase(23.9, 1, 1, PierSide.pierEast)] + [TestCase(23.9, -1, 1, PierSide.pierEast)] + [TestCase(1, 1, 23.9, PierSide.pierWest)] + [TestCase(1, -1, 23.9, PierSide.pierWest)] + public void DestinationSideOfPier_WhenHASiderealTimeDiffIsNotNull_ThenSideOfPierIsCalculated(double ra, double dec, double siderealTime, PierSide expectedDSOP) + { + // given + + // deterministic start + _sharedResourcesWrapperMock.Object.SideOfPier = PierSide.pierUnknown; + + // SideralTime uses ConditionRA to normalize to [0..24h), so we use it to mock the property + _astroUtilsMock.Setup(x => x.ConditionRA(It.IsAny())).Returns(siderealTime); + + var ha = siderealTime - ra; + // normalized hour angle range is [-12h..12h] + var normalisedHA = ha > 12 ? ha - 24 : ha < -12 ? ha + 24 : ha; + _astroUtilsMock.Setup(x => x.ConditionHA(It.Is(v => v == ha))).Returns(normalisedHA); + + ConnectTelescope(); + + // when + var actualDSOP = _telescope.DestinationSideOfPier(ra, dec); + + // then + Assert.That(siderealTime, Is.InRange(0, 24)); + Assert.That(normalisedHA, Is.InRange(-12, 12 + double.Epsilon)); + Assert.That(actualDSOP, Is.EqualTo(expectedDSOP)); + + _astroUtilsMock.Verify(x => x.ConditionRA(It.IsAny()), Times.Once); + _astroUtilsMock.Verify(x => x.ConditionHA(It.Is(v => v == ha)), Times.Once); + } + + [Test] + public void SiderealTime_Get_WhenNotConnected_ThenThrowsException() + { + // when + var exception = Assert.Throws(() => + { + var result = _telescope.SiderealTime; + Assert.Fail($"{result} should not have returned"); + }); + + // then + Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SiderealTime Get")); + } + + [Test] + public void SiderealTime_Get_WhenNOVASErrors_ThenThrowsException() + { + // given + double gst = 0.0; + _novasMock + .Setup(x => x.SiderealTime(It.IsAny(), It.IsAny(), It.IsAny(), ASCOM.Astrometry.GstType.GreenwichApparentSiderealTime, ASCOM.Astrometry.Method.EquinoxBased, ASCOM.Astrometry.Accuracy.Reduced, ref gst)) + .Returns(3) + .Verifiable(); + + ConnectTelescope(); + + // when + var exception = Assert.Throws(() => + { + var result = _telescope.SiderealTime; + Assert.Fail($"{result} should not have returned"); + }); + + // then + Assert.That(exception.Message, Is.EqualTo("NOVAS 3.1 SiderealTime returned: 3 in SiderealTime")); + _novasMock.Verify(); } [Test] @@ -1197,7 +1385,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void DoesRefraction_Set_ThenThrowsException() { - var excpetion = Assert.Throws(() => { _telescope.DoesRefraction = true; }); + var excpetion = Assert.Throws(() => _telescope.DoesRefraction = true); Assert.That(excpetion.Property, Is.EqualTo("DoesRefraction")); Assert.That(excpetion.AccessorSet, Is.True); @@ -1214,7 +1402,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void FindHome_ThenThrowsException() { - var excpetion = Assert.Throws(() => { _telescope.FindHome();}); + var excpetion = Assert.Throws(() => _telescope.FindHome()); Assert.That(excpetion.Method, Is.EqualTo("FindHome")); } @@ -1245,7 +1433,7 @@ namespace Meade.net.Telescope.UnitTests { _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); - var excpetion = Assert.Throws(() => { _telescope.GuideRateDeclination = 0; }); + var excpetion = Assert.Throws(() => _telescope.GuideRateDeclination = 0); Assert.That(excpetion.Property, Is.EqualTo("GuideRateDeclination")); Assert.That(excpetion.AccessorSet, Is.True); @@ -1260,7 +1448,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.GuideRateDeclination = newGuideRate; - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Rg01.2#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Rg01.2", false), Times.Once); Assert.That(_telescope.GuideRateDeclination, Is.EqualTo(newGuideRate)); } @@ -1278,7 +1466,7 @@ namespace Meade.net.Telescope.UnitTests { _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); - var excpetion = Assert.Throws(() => { _telescope.GuideRateRightAscension = 0; }); + var excpetion = Assert.Throws(() => _telescope.GuideRateRightAscension = 0); Assert.That(excpetion.Property, Is.EqualTo("GuideRateRightAscension")); Assert.That(excpetion.AccessorSet, Is.True); @@ -1293,7 +1481,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.GuideRateRightAscension = newGuideRate; - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Rg01.2#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Rg01.2", false), Times.Once); Assert.That(_telescope.GuideRateDeclination, Is.EqualTo(newGuideRate)); } @@ -1310,28 +1498,28 @@ namespace Meade.net.Telescope.UnitTests [Test] public void MoveAxis_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.MoveAxis(TelescopeAxes.axisPrimary, 0); }); + var exception = Assert.Throws(() => _telescope.MoveAxis(TelescopeAxes.axisPrimary, 0)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: MoveAxis")); } - [TestCase( 0, "", TelescopeAxes.axisPrimary)] - [TestCase( 1, ":RG#", TelescopeAxes.axisPrimary)] - [TestCase(-1, ":RG#", TelescopeAxes.axisPrimary)] - [TestCase( 2, ":RC#", TelescopeAxes.axisPrimary)] - [TestCase(-2, ":RC#", TelescopeAxes.axisPrimary)] - [TestCase( 3, ":RM#", TelescopeAxes.axisPrimary)] - [TestCase(-3, ":RM#", TelescopeAxes.axisPrimary)] - [TestCase( 4, ":RS#", TelescopeAxes.axisPrimary)] - [TestCase(-4, ":RS#", TelescopeAxes.axisPrimary)] + [TestCase(0, "", TelescopeAxes.axisPrimary)] + [TestCase(1, "RG", TelescopeAxes.axisPrimary)] + [TestCase(-1, "RG", TelescopeAxes.axisPrimary)] + [TestCase(2, "RC", TelescopeAxes.axisPrimary)] + [TestCase(-2, "RC", TelescopeAxes.axisPrimary)] + [TestCase(3, "RM", TelescopeAxes.axisPrimary)] + [TestCase(-3, "RM", TelescopeAxes.axisPrimary)] + [TestCase(4, "RS", TelescopeAxes.axisPrimary)] + [TestCase(-4, "RS", TelescopeAxes.axisPrimary)] [TestCase(0, "", TelescopeAxes.axisSecondary)] - [TestCase(1, ":RG#", TelescopeAxes.axisSecondary)] - [TestCase(-1, ":RG#", TelescopeAxes.axisSecondary)] - [TestCase(2, ":RC#", TelescopeAxes.axisSecondary)] - [TestCase(-2, ":RC#", TelescopeAxes.axisSecondary)] - [TestCase(3, ":RM#", TelescopeAxes.axisSecondary)] - [TestCase(-3, ":RM#", TelescopeAxes.axisSecondary)] - [TestCase(4, ":RS#", TelescopeAxes.axisSecondary)] - [TestCase(-4, ":RS#", TelescopeAxes.axisSecondary)] + [TestCase(1, "RG", TelescopeAxes.axisSecondary)] + [TestCase(-1, "RG", TelescopeAxes.axisSecondary)] + [TestCase(2, "RC", TelescopeAxes.axisSecondary)] + [TestCase(-2, "RC", TelescopeAxes.axisSecondary)] + [TestCase(3, "RM", TelescopeAxes.axisSecondary)] + [TestCase(-3, "RM", TelescopeAxes.axisSecondary)] + [TestCase(4, "RS", TelescopeAxes.axisSecondary)] + [TestCase(-4, "RS", TelescopeAxes.axisSecondary)] public void MoveAxis_WhenConnected_ThenExecutesCorrectCommandSequence(double rate, string slewRateCommand, TelescopeAxes axis) { ConnectTelescope(); @@ -1339,13 +1527,13 @@ namespace Meade.net.Telescope.UnitTests _telescope.MoveAxis(axis, rate); if (slewRateCommand != string.Empty) - _sharedResourcesWrapperMock.Verify( x => x.SendBlind(slewRateCommand), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(slewRateCommand, false), Times.Once); else { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":RG#"), Times.Never); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":RC#"), Times.Never); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":RM#"), Times.Never); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":RS#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RG", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RC", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RM", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RS", false), Times.Never); } switch (axis) @@ -1354,14 +1542,14 @@ namespace Meade.net.Telescope.UnitTests switch (rate.Compare(0)) { case ComparisonResult.Equals: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Qe#"), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Qw#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Qe", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Qw", false), Times.Once); break; case ComparisonResult.Greater: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Me#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Me", false), Times.Once); break; case ComparisonResult.Lower: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Mw#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Mw", false), Times.Once); break; } break; @@ -1369,14 +1557,14 @@ namespace Meade.net.Telescope.UnitTests switch (rate.Compare(0)) { case ComparisonResult.Equals: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Qn#"), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Qs#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Qn", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Qs", false), Times.Once); break; case ComparisonResult.Greater: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Mn#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Mn", false), Times.Once); break; case ComparisonResult.Lower: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Ms#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Ms", false), Times.Once); break; } break; @@ -1393,7 +1581,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); - var exception = Assert.Throws( () => { _telescope.MoveAxis(TelescopeAxes.axisTertiary, testRate); }); + var exception = Assert.Throws(() => _telescope.MoveAxis(TelescopeAxes.axisTertiary, testRate)); Assert.That(exception.Message, Is.EqualTo($"Rate {testRate} not supported")); } @@ -1405,7 +1593,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.MoveAxis(TelescopeAxes.axisTertiary, testRate); }); + var exception = Assert.Throws(() => _telescope.MoveAxis(TelescopeAxes.axisTertiary, testRate)); Assert.That(exception.Message, Is.EqualTo("Can not move this axis.")); } @@ -1413,7 +1601,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void Park_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.Park(); }); + var exception = Assert.Throws(() => _telescope.Park()); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: Park")); } @@ -1422,11 +1610,11 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); Assert.That(_telescope.AtPark, Is.False); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":hP#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("hP", false), Times.Never); _telescope.Park(); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":hP#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("hP", false), Times.Once); Assert.That(_telescope.AtPark, Is.True); } @@ -1437,22 +1625,22 @@ namespace Meade.net.Telescope.UnitTests _telescope.Park(); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":hP#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("hP", false), Times.Once); Assert.That(_telescope.AtPark, Is.True); - //act + //act _telescope.Park(); //no change from previous state. - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":hP#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("hP", false), Times.Once); Assert.That(_telescope.AtPark, Is.True); } [Test] public void PulseGuide_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.PulseGuide(GuideDirections.guideEast,0); }); + var exception = Assert.Throws(() => _telescope.PulseGuide(GuideDirections.guideEast, 0)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: PulseGuide")); } @@ -1484,8 +1672,8 @@ namespace Meade.net.Telescope.UnitTests break; } - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Mg{d}{duration:0000}#")); - _utilMock.Verify( x => x.WaitForMilliseconds(duration), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Mg{d}{duration:0000}", false)); + _utilMock.Verify(x => x.WaitForMilliseconds(duration), Times.Once); } [TestCase(GuideDirections.guideEast)] @@ -1494,12 +1682,12 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth)] public void PulseGuide_WhenSlewingAndPulseGuideAttempted_ThenThrowsExpectedException(GuideDirections direction) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns("|"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns("|"); var duration = 0; ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.PulseGuide(direction, duration); }); + var exception = Assert.Throws(() => _telescope.PulseGuide(direction, duration)); Assert.That(exception.Message, Is.EqualTo("Unable to PulseGuide whilst slewing to target.")); } @@ -1510,16 +1698,21 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth, TelescopeAxes.axisSecondary)] public void PulseGuide_WhenMovingAxisAndPulseGuideAttempted_ThenThrowsExpectedException(GuideDirections direction, TelescopeAxes axes) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(""); + _sharedResourcesWrapperMock.SetupProperty(x => x.MovingPrimary); + _sharedResourcesWrapperMock.SetupProperty(x => x.MovingSecondary); + _sharedResourcesWrapperMock.SetupProperty(x => x.EarliestNonSlewingTime, DateTime.MinValue); + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(""); var duration = 0; ConnectTelescope(); _telescope.MoveAxis(axes, 1); - var exception = Assert.Throws(() => { _telescope.PulseGuide(direction, duration); }); + var exception = Assert.Throws(() => _telescope.PulseGuide(direction, duration)); Assert.That(exception.Message, Is.EqualTo("Unable to PulseGuide while moving same axis.")); + Assert.That(_sharedResourcesWrapperMock.Object.MovingPrimary, Is.EqualTo(axes == TelescopeAxes.axisPrimary)); + Assert.That(_sharedResourcesWrapperMock.Object.MovingSecondary, Is.EqualTo(axes == TelescopeAxes.axisSecondary)); } [TestCase(GuideDirections.guideEast)] @@ -1533,7 +1726,7 @@ namespace Meade.net.Telescope.UnitTests _testProperties.rightAscension = 1.3; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); var duration = 0; @@ -1549,7 +1742,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.PulseGuide(direction, duration); - + Assert.That(isSlewing, Is.False); } @@ -1563,7 +1756,7 @@ namespace Meade.net.Telescope.UnitTests var dmsResult = 1.2; var duration = 0; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); ConnectTelescope(TelescopeList.Autostar497, TelescopeList.Autostar497_30Ee); @@ -1587,10 +1780,10 @@ namespace Meade.net.Telescope.UnitTests break; } - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":RG#")); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":M{d}#")); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RG", false)); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"M{d}", false)); _utilMock.Verify(x => x.WaitForMilliseconds(duration), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Q{d}#")); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Q{d}", false)); } [TestCase(GuideDirections.guideEast)] @@ -1606,9 +1799,9 @@ namespace Meade.net.Telescope.UnitTests var telescopeDecResult = "s12*34’56"; var dmsResult = 1.2; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); - _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); - + _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); + ConnectTelescope(TelescopeList.Autostar497, TelescopeList.Autostar497_30Ee); _telescope.PulseGuide(direction, duration); @@ -1661,10 +1854,10 @@ namespace Meade.net.Telescope.UnitTests break; } - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":RG#")); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":M{d}#")); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RG", false)); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"M{d}", false)); _utilMock.Verify(x => x.WaitForMilliseconds(duration), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Q{d}#")); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Q{d}", false)); } [Test] @@ -1682,10 +1875,10 @@ namespace Meade.net.Telescope.UnitTests public void RightAscension_Get_WhenConnected_ThenReturnsExpectedResult() { ConnectTelescope(); - + var result = _telescope.RightAscension; - Assert.That(result,Is.EqualTo(_testProperties.rightAscension)); + Assert.That(result, Is.EqualTo(_testProperties.rightAscension)); } [Test] @@ -1699,7 +1892,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void RightAscensionRate_Set_ThenThrowsException() { - var excpetion = Assert.Throws(() => { _telescope.RightAscensionRate = 1; }); + var excpetion = Assert.Throws(() => _telescope.RightAscensionRate = 1); Assert.That(excpetion.Property, Is.EqualTo("RightAscensionRate")); Assert.That(excpetion.AccessorSet, Is.True); @@ -1708,14 +1901,17 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SetPark_ThenThrowsException() { - var excpetion = Assert.Throws(() => { _telescope.SetPark(); }); + var excpetion = Assert.Throws(() => _telescope.SetPark()); Assert.That(excpetion.Method, Is.EqualTo("SetPark")); } [Test] - public void SideOfPier_Get_ThenThrowsException() + public void SideOfPier_Get_WhenMeridianFlipNotSupported_ThenThrowsException() { + // LX200 classic is a fork mounted scope so it does not support meridian flips + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(TelescopeList.LX200CLASSIC); + var excpetion = Assert.Throws(() => { var result = _telescope.SideOfPier; @@ -1729,12 +1925,178 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SideOfPier_Set_ThenThrowsException() { - var excpetion = Assert.Throws(() => { _telescope.SideOfPier = 0; }); + var excpetion = Assert.Throws(() => _telescope.SideOfPier = 0); Assert.That(excpetion.Property, Is.EqualTo("SideOfPier")); Assert.That(excpetion.AccessorSet, Is.True); } + [TestCase(0, 34, PierSide.pierEast)] + [TestCase(12, 34, PierSide.pierEast)] + [TestCase(23.4, 34, PierSide.pierWest)] + public void SideOfPier_WhenSecondConnectionMade_ThenValueIsPreserved(double ra, double dec, PierSide expectedPierSide) + { + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); + _utilMock.Setup(x => x.HMSToHours(null)).Returns(ra); + _utilMock.Setup(x => x.DMSToDegrees(null)).Returns(dec); + _astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny())).Returns(pHA => pHA < -12 ? pHA + 12 : pHA > 12 ? pHA - 12 : pHA); + _astroUtilsMock.Setup(x => x.ConditionRA(It.IsAny())).Returns(pRA => pRA < 0 ? pRA + 24 : pRA >= 24 ? pRA - 24 : pRA); + + ConnectTelescope(); + Assert.That(_connectionInfo.SameDevice, Is.EqualTo(1)); + + _telescope.SlewToCoordinates(ra, dec); + var sideOfPierAfterSlew = _telescope.SideOfPier; + + Assert.That(sideOfPierAfterSlew, Is.EqualTo(expectedPierSide)); + + var secondTelescopeInstance = + new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object); + + Assert.That(secondTelescopeInstance.Connected, Is.False); + + _connectionInfo.SameDevice = 2; + secondTelescopeInstance.Connected = true; + + Assert.That(secondTelescopeInstance.SideOfPier, Is.EqualTo(sideOfPierAfterSlew)); + + _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); + _utilMock.Verify(x => x.HMSToHours(null), Times.Once); + _utilMock.Verify(x => x.DMSToDegrees(null), Times.AtLeast(2)); + _astroUtilsMock.Verify(x => x.ConditionHA(It.IsAny()), Times.Once); + _astroUtilsMock.Verify(x => x.ConditionRA(It.IsAny()), Times.Once); + } + + delegate void NovasSiderealTimeDelegate(double jdHigh, double jdLow, double jdDelta, GstType gstType, Method method, Accuracy accuracy, ref double sideralTime); + + /// + /// Test cases obtained via .NET telescope simulator + /// + [TestCase(9.4337648353882, -76.7178112042103, "2021-06-07T05:23:41.7610000Z", 8.13556526999591, 145.166333333333, 2d, PierSide.pierWest, PierSide.pierEast)] + [TestCase(10.1581570159006, 11.8639491368916, "2021-06-07T10:59:19.7000000Z", 9.72726050605156, 145.166333333333, 1d, PierSide.pierWest, PierSide.pierEast)] + [TestCase(9.66583199112222, 81.2310578173083, "2021-06-07T11:19:24.5540000Z", 7.73744116673785, 110.285166666667, 2d, PierSide.pierWest, PierSide.pierEast)] + [TestCase(8.32978972808615, -29.816491813155, "2021-06-07T11:29:33.7040000Z", 7.90712206850482, 110.285166666667, 1d, PierSide.pierWest, PierSide.pierEast)] + [TestCase(1.76405553984887, 60.7756226366989, "2021-06-07T11:34:07.5270000Z", 0.214893775091689, -6.24266666666667, 2d, PierSide.pierWest, PierSide.pierEast)] + [TestCase(0.523375885742411, -33.1288722052936, "2021-06-07T11:38:25.1670000Z", 0.286661722506396, -6.24266666666667, 0.5d, PierSide.pierWest, PierSide.pierEast)] + public void SideOfPier_WhenTrackingThroughMeridianAfterSubsequentGoto_ThenAMeridianFlipIsPerformed( + double ra, + double dec, + string jnowTimeStr, /* JNOW of object before transit */ + double jnowSiderealTime, + double siteLongitude, + double trackingTimeHours, + PierSide pierSideBeforeTransit, + PierSide pierSideAfterRetargeting + ) + { + // given + var jnowTime = DateTimeOffset.ParseExact(jnowTimeStr, "o", CultureInfo.InvariantCulture).UtcDateTime; + var trackingTimeDiff = TimeSpan.FromHours(trackingTimeHours); + var timeAfterTracking = jnowTime + trackingTimeDiff; + var raAsHMS = ra + "HMS"; + var decAsDMS = dec + "DMS"; + var currentTime = jnowTime; + + _clockMock.Setup(x => x.UtcNow).Returns(() => currentTime); + + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); + + // setup for RA + _utilMock.Setup(x => x.HoursToHMS(ra, ":", ":", ":", 2)).Returns(raAsHMS); + _utilMock.Setup(x => x.HMSToHours(raAsHMS)).Returns(ra); + + // setup for DEC + _utilMock.Setup(x => x.DMSToDegrees(decAsDMS)).Returns(dec); + _utilMock.Setup(x => x.DegreesToDMS(dec, "*", ":", ":", 2)).Returns(decAsDMS); + + // setup for SiteLongitude + var siteLongitudeResult = siteLongitude + "Gg"; + _sharedResourcesWrapperMock.Setup(x => x.SendString("Gg", false)).Returns(siteLongitudeResult); + // remember to invert longitude + _utilMock.Setup(x => x.DMSToDegrees(siteLongitudeResult)).Returns(-siteLongitude); + + // setup for SideralTime + var siteLongitudeAdj = siteLongitude / 360.0 * 24.0; + var jnowSiderealTimeWithoutLongAdj = jnowSiderealTime - siteLongitudeAdj; + var afterTrackingSiderealTimeWithoutLongAdj = jnowSiderealTimeWithoutLongAdj + trackingTimeHours; + + _utilMock.Setup(x => x.DateUTCToJulian(It.IsAny())).Returns(pDateTime => pDateTime.Ticks); + + _novasMock + .Setup(x => x.SiderealTime( + It.IsAny(), + 0d, + 0d, + GstType.GreenwichApparentSiderealTime, + Method.EquinoxBased, + Accuracy.Reduced, + ref It.Ref.IsAny)) + .Callback(new NovasSiderealTimeDelegate(NovasSiderealTime)) + .Returns(0); + + _astroUtilsMock.Setup(x => x.ConditionRA(It.IsAny())).Returns(pRA => pRA < 0 ? pRA + 24 : pRA >= 24 ? pRA - 24 : pRA); + + void NovasSiderealTime(double pJDHigh, double pJDLow, double pJDDelta, GstType pGSTType, Method pMethod, Accuracy pAccuracy, ref double pSideralTime) + { + if (pJDHigh == jnowTime.Ticks) + { + pSideralTime = jnowSiderealTimeWithoutLongAdj; + } + else if (pJDHigh == timeAfterTracking.Ticks) + { + pSideralTime = afterTrackingSiderealTimeWithoutLongAdj; + } + else + { + Assert.Fail($"No sideral time defined for {pJDHigh}"); + } + } + + // Setup DestinationSideOfPier + _astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny())).Returns(pHA => pHA < -12 ? pHA + 12 : pHA > 12 ? pHA - 12 : pHA); + + ConnectTelescope(); + + // when + _telescope.SlewToCoordinatesAsync(ra, dec); + var actualSideOfPierAfterSlew = _telescope.SideOfPier; + // simulate tracking time + currentTime += trackingTimeDiff; + var actualSideOfPierAfterTracking = _telescope.SideOfPier; + _telescope.SlewToTargetAsync(); + var actualSideOfPierAfterRetargeting = _telescope.SideOfPier; + + // then + Assert.That(_telescope.TargetRightAscension, Is.EqualTo(ra)); + Assert.That(_telescope.TargetDeclination, Is.EqualTo(dec)); + Assert.That(actualSideOfPierAfterSlew, Is.EqualTo(pierSideBeforeTransit)); + Assert.That(actualSideOfPierAfterTracking, Is.EqualTo(pierSideBeforeTransit)); + Assert.That(actualSideOfPierAfterRetargeting, Is.EqualTo(pierSideAfterRetargeting)); + + _clockMock.Verify(x => x.UtcNow, Times.AtLeast(2)); + + foreach (var time in new[] { jnowTime, timeAfterTracking }) + { + _utilMock.Verify(x => x.DateUTCToJulian(time)); + + _novasMock + .Verify(x => x.SiderealTime( + time.Ticks, + 0d, + 0d, + GstType.GreenwichApparentSiderealTime, + Method.EquinoxBased, + Accuracy.Reduced, + ref It.Ref.IsAny), + Times.Once); + } + + _sharedResourcesWrapperMock.Verify(x => x.SendString("Gg", false), Times.Exactly(3)); + _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Exactly(2)); + _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Exactly(3)); + } + [Test] public void SiteElevation_Get_WhenNotConnectedThrowsException() { @@ -1785,7 +2147,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.SiteElevation = newElevation; Assert.That(_telescope.SiteElevation, Is.EqualTo(newElevation)); - _sharedResourcesWrapperMock.Verify( x => x.WriteProfile(It.IsAny()), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.WriteProfile(It.IsAny()), Times.Once); Assert.That(writtenSiteElevation, Is.EqualTo(newElevation)); } @@ -1854,16 +2216,16 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); var result = _telescope.SiteLatitude; - - _sharedResourcesWrapperMock.Verify( x => x.SendString(":Gt#", true), Times.AtLeastOnce); - Assert.That(result,Is.EqualTo(_testProperties.SiteLatitudeValue)); + _sharedResourcesWrapperMock.Verify(x => x.SendString("Gt", false), Times.AtLeastOnce); + + Assert.That(result, Is.EqualTo(_testProperties.SiteLatitudeValue)); } [Test] public void SiteLatitude_Set_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SiteLatitude = 123.45; }); + var exception = Assert.Throws(() => _telescope.SiteLatitude = 123.45); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SiteLatitude Set")); } @@ -1872,7 +2234,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SiteLatitude = 90.01; }); + var exception = Assert.Throws(() => _telescope.SiteLatitude = 90.01); Assert.That(exception.Message, Is.EqualTo("Latitude cannot be greater than 90 degrees.")); } @@ -1881,7 +2243,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SiteLatitude = -90.01; }); + var exception = Assert.Throws(() => _telescope.SiteLatitude = -90.01); Assert.That(exception.Message, Is.EqualTo("Latitude cannot be less than -90 degrees.")); } @@ -1889,26 +2251,26 @@ namespace Meade.net.Telescope.UnitTests [TestCase(20.75)] public void SiteLatitude_Set_WhenValueSetAndTelescopRejects_ThenExceptionThrown(double siteLatitude) { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny())).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny(), false)).Returns("0"); ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SiteLatitude = siteLatitude; }); + var exception = Assert.Throws(() => _telescope.SiteLatitude = siteLatitude); Assert.That(exception.Message, Is.EqualTo("Failed to set site latitude.")); } - [TestCase(-10.5, ":St-10*30#")] - [TestCase(20.75, ":St+20*45#")] + [TestCase(-10.5, "St-10*30")] + [TestCase(20.75, "St+20*45")] public void SiteLatitude_Set_WhenValidValues_ThenValueSentToTelescope(double siteLatitude, string expectedCommand) { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(expectedCommand)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(expectedCommand, false)).Returns("1"); ConnectTelescope(); _telescope.SiteLatitude = siteLatitude; - _sharedResourcesWrapperMock.Verify(x => x.SendChar(expectedCommand), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(expectedCommand, false), Times.Once); } [Test] @@ -1931,7 +2293,7 @@ namespace Meade.net.Telescope.UnitTests { var telescopeLongitude = "testLongitude"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gg#", true)).Returns(telescopeLongitude); + _sharedResourcesWrapperMock.Setup(x => x.SendString("Gg", false)).Returns(telescopeLongitude); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); ConnectTelescope(); @@ -1944,7 +2306,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SiteLongitude_Set_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SiteLongitude = 123.45; }); + var exception = Assert.Throws(() => _telescope.SiteLongitude = 123.45); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SiteLongitude Set")); } @@ -1953,7 +2315,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SiteLongitude = 180.1; }); + var exception = Assert.Throws(() => _telescope.SiteLongitude = 180.1); Assert.That(exception.Message, Is.EqualTo("Longitude cannot be greater than 180 degrees.")); } @@ -1962,32 +2324,32 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SiteLongitude = -180.1; }); + var exception = Assert.Throws(() => _telescope.SiteLongitude = -180.1); Assert.That(exception.Message, Is.EqualTo("Longitude cannot be lower than -180 degrees.")); } [Test] public void SiteLongitude_Set_WhenConnectedAndTelescopeFails_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny())).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny(), false)).Returns("0"); ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SiteLongitude = 10; }); + var exception = Assert.Throws(() => _telescope.SiteLongitude = 10); Assert.That(exception.Message, Is.EqualTo("Failed to set site longitude.")); } - [TestCase(10, ":Sg350*00#")] + [TestCase(10, "Sg350*00")] public void SiteLongitude_Set_WhenConnectedAndTelescopeFails_ThenThrowsException(double longitude, string expectedCommand) { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(expectedCommand)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(expectedCommand, false)).Returns("1"); ConnectTelescope(); _telescope.SiteLongitude = longitude; - _sharedResourcesWrapperMock.Verify(x => x.SendChar(expectedCommand), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(expectedCommand, false), Times.Once); } [Test] @@ -1995,7 +2357,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SyncToAltAz(0,0); }); + var exception = Assert.Throws(() => _telescope.SyncToAltAz(0, 0)); Assert.That(exception.Message, Is.EqualTo("Method SyncToAltAz is not implemented in this driver.")); } @@ -2003,39 +2365,39 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SyncToTarget_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SyncToTarget(); }); + var exception = Assert.Throws(() => _telescope.SyncToTarget()); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SyncToTarget")); } [Test] public void SyncToTarget_WhenSyncToTargetFails_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":CM#", true)).Returns(string.Empty); + _sharedResourcesWrapperMock.Setup(x => x.SendString("CM", false)).Returns(string.Empty); ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SyncToTarget(); } ); + var exception = Assert.Throws(() => _telescope.SyncToTarget()); Assert.That(exception.Message, Is.EqualTo("Unable to perform sync")); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#", true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("CM", false), Times.Once); } [Test] public void SyncToTarget_WhenSyncToTargetWorks_ThennoExceptionThrown() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":CM#", true)).Returns(" M31 EX GAL MAG 3.5 SZ178.0'#"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("CM", false)).Returns(" M31 EX GAL MAG 3.5 SZ178.0'#"); ConnectTelescope(); - - Assert.DoesNotThrow(() => { _telescope.SyncToTarget(); }); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#", true), Times.Once); + Assert.DoesNotThrow(() => _telescope.SyncToTarget()); + + _sharedResourcesWrapperMock.Verify(x => x.SendString("CM", false), Times.Once); } [Test] public void TargetDeclination_Set_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.TargetDeclination = 0; }); + var exception = Assert.Throws(() => _telescope.TargetDeclination = 0); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: TargetDeclination Set")); } @@ -2044,7 +2406,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.TargetDeclination = 90.1; }); + var exception = Assert.Throws(() => _telescope.TargetDeclination = 90.1); Assert.That(exception.Message, Is.EqualTo("Declination cannot be greater than 90.")); } @@ -2053,36 +2415,36 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.TargetDeclination = -90.1; }); + var exception = Assert.Throws(() => _telescope.TargetDeclination = -90.1); Assert.That(exception.Message, Is.EqualTo("Declination cannot be less than -90.")); } [Test] public void TargetDeclination_Set_WhenTelescopeReportsInvalidDec_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny())).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny(), false)).Returns("0"); ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.TargetDeclination = 50; }); + var exception = Assert.Throws(() => _telescope.TargetDeclination = 50); Assert.That(exception.Message, Is.EqualTo("Target declination invalid")); } - [TestCase(-30.5, "-30*30:00", ":Sd-30*30:00#")] - [TestCase(30.5, "30*30:00", ":Sd+30*30:00#")] - [TestCase(-75.25, "-75*15:00", ":Sd-75*15:00#")] - [TestCase(50, "50*00:00", ":Sd+50*00:00#")] - public void TargetDeclination_Set_WhenValueOK_ThenSetsNewTargetDeclination( double declination,string decstring, string commandString) + [TestCase(-30.5, "-30*30:00", "Sd-30*30:00")] + [TestCase(30.5, "30*30:00", "Sd+30*30:00")] + [TestCase(-75.25, "-75*15:00", "Sd-75*15:00")] + [TestCase(50, "50*00:00", "Sd+50*00:00")] + public void TargetDeclination_Set_WhenValueOK_ThenSetsNewTargetDeclination(double declination, string decstring, string commandString) { _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(decstring); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString, false)).Returns("1"); ConnectTelescope(); _telescope.TargetDeclination = declination; - _sharedResourcesWrapperMock.Verify(x => x.SendChar(commandString),Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(commandString, false), Times.Once); } [Test] @@ -2098,7 +2460,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Target not set")); } - [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) { var digitsRA = 2; @@ -2108,7 +2470,7 @@ namespace Meade.net.Telescope.UnitTests _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(decstring); _utilMock.Setup(x => x.DMSToDegrees(decstring)).Returns(declination); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString, false)).Returns("1"); ConnectTelescope(); @@ -2119,10 +2481,50 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.EqualTo(declination)); } + [TestCase(-90d)] + [TestCase(-45d)] + [TestCase(0d)] + [TestCase(45d)] + [TestCase(90d)] + public void TargetDeclination_Set_WhenSecondConnectionMade_ThenValueIsPreserved(double targetDeclination) + { + var targetDeclinationDMS = targetDeclination + "DMS"; + var sign = targetDeclination >= 0 ? "+" : string.Empty; + var command = $"Sd{sign}{targetDeclinationDMS}"; + + _utilMock.Setup(x => x.DegreesToDMS(targetDeclination, "*", ":", ":", 2)).Returns(targetDeclinationDMS); + _utilMock.Setup(x => x.DMSToDegrees(targetDeclinationDMS)).Returns(targetDeclination); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(command, false)).Returns("1"); + + ConnectTelescope(); + Assert.That(_connectionInfo.SameDevice, Is.EqualTo(1)); + Assert.That(_sharedResourcesWrapperMock.Object.IsLongFormat, Is.True); + + _telescope.TargetDeclination = targetDeclination; + + Assert.That(_telescope.TargetDeclination, Is.EqualTo(targetDeclination)); + + var secondTelescopeInstance = + new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object); + + Assert.That(secondTelescopeInstance.Connected, Is.False); + + _connectionInfo.SameDevice = 2; + secondTelescopeInstance.Connected = true; + + Assert.That(_sharedResourcesWrapperMock.Object.IsLongFormat, Is.True); + Assert.That(secondTelescopeInstance.TargetDeclination, Is.EqualTo(targetDeclination)); + + _utilMock.Verify(x => x.DegreesToDMS(targetDeclination, "*", ":", ":", 2), Times.Once); + _utilMock.Verify(x => x.DMSToDegrees(targetDeclinationDMS), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(command, false), Times.Once); + } + [Test] public void TargetRightAscension_Set_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.TargetRightAscension = 0; }); + var exception = Assert.Throws(() => _telescope.TargetRightAscension = 0); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: TargetRightAscension Set")); } @@ -2131,7 +2533,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.TargetRightAscension = 24; }); + var exception = Assert.Throws(() => _telescope.TargetRightAscension = 24); Assert.That(exception.Message, Is.EqualTo("Right ascension value cannot be greater than 23:59:59")); } @@ -2140,33 +2542,33 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.TargetRightAscension = -0.1; }); + var exception = Assert.Throws(() => _telescope.TargetRightAscension = -0.1); Assert.That(exception.Message, Is.EqualTo("Right ascension value cannot be below 0")); } [Test] public void TargetRightAscension_Set_WhenTelescopeReportsInvalidRA_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny())).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny(), false)).Returns("0"); ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.TargetRightAscension = 1; }); + var exception = Assert.Throws(() => _telescope.TargetRightAscension = 1); Assert.That(exception.Message, Is.EqualTo("Failed to set TargetRightAscension.")); } - [TestCase(5.5, "05:30:00", ":Sr05:30:00#")] - [TestCase(10, "10:00:00", ":Sr10:00:00#")] + [TestCase(5.5, "05:30:00", "Sr05:30:00")] + [TestCase(10, "10:00:00", "Sr10:00:00")] public void TargetRightAscension_Set_WhenValueOK_ThenSetsNewTargetDeclination(double rightAscension, string hms, string commandString) { _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(hms); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString, false)).Returns("1"); ConnectTelescope(); _telescope.TargetRightAscension = rightAscension; - _sharedResourcesWrapperMock.Verify(x => x.SendChar(commandString), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(commandString, false), Times.Once); } [Test] @@ -2182,7 +2584,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Target not set")); } - [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) { var digitsRA = 2; @@ -2190,7 +2592,7 @@ namespace Meade.net.Telescope.UnitTests _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", digitsRA)).Returns(hms); _utilMock.Setup(x => x.HMSToHours(hms)).Returns(rightAscension); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString, false)).Returns("1"); ConnectTelescope(); @@ -2201,6 +2603,44 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.EqualTo(rightAscension)); } + [TestCase(0d)] + [TestCase(6d)] + [TestCase(12d)] + [TestCase(23.599d)] + public void TargetRightAscension_Set_WhenSecondConnectionMade_ThenValueIsPreserved(double targetRightAscension) + { + var targetRightAscensionHMS = targetRightAscension + "HMS"; + var command = $"Sr{targetRightAscensionHMS}"; + + _utilMock.Setup(x => x.HoursToHMS(targetRightAscension, ":", ":", ":", 2)).Returns(targetRightAscensionHMS); + _utilMock.Setup(x => x.HMSToHours(targetRightAscensionHMS)).Returns(targetRightAscension); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(command, false)).Returns("1"); + + ConnectTelescope(); + Assert.That(_connectionInfo.SameDevice, Is.EqualTo(1)); + Assert.That(_sharedResourcesWrapperMock.Object.IsLongFormat, Is.True); + + _telescope.TargetRightAscension = targetRightAscension; + + Assert.That(_telescope.TargetRightAscension, Is.EqualTo(targetRightAscension)); + + var secondTelescopeInstance = + new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object); + + Assert.That(secondTelescopeInstance.Connected, Is.False); + + _connectionInfo.SameDevice = 2; + secondTelescopeInstance.Connected = true; + + Assert.That(_sharedResourcesWrapperMock.Object.IsLongFormat, Is.True); + Assert.That(secondTelescopeInstance.TargetRightAscension, Is.EqualTo(targetRightAscension)); + + _utilMock.Verify(x => x.HoursToHMS(targetRightAscension, ":", ":", ":", 2), Times.Once); + _utilMock.Verify(x => x.HMSToHours(targetRightAscensionHMS), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(command, false), Times.Once); + } + [Test] public void Tracking_Get_WhenDefault_ThenIsTrue() { @@ -2217,19 +2657,19 @@ namespace Meade.net.Telescope.UnitTests [Test] public void TrackingRate_Set_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.TrackingRate = DriveRates.driveSidereal; }); + var exception = Assert.Throws(() => _telescope.TrackingRate = DriveRates.driveSidereal); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: TrackingRate Set")); } - [TestCase(DriveRates.driveSidereal, ":TQ#")] - [TestCase(DriveRates.driveLunar, ":TL#")] + [TestCase(DriveRates.driveSidereal, "TQ")] + [TestCase(DriveRates.driveLunar, "TL")] public void TrackingRate_Set_WhenConnected_ThenSendsCommandToTelescope(DriveRates rate, string commandString) { ConnectTelescope(); _telescope.TrackingRate = rate; - _sharedResourcesWrapperMock.Verify( x => x.SendBlind(commandString), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(commandString, false), Times.Once); } [Test] @@ -2237,7 +2677,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws( () => { _telescope.TrackingRate = DriveRates.driveKing; }); + var exception = Assert.Throws(() => _telescope.TrackingRate = DriveRates.driveKing); Assert.That(exception.Message, Is.EqualTo("Exception of type 'System.ArgumentOutOfRangeException' was thrown.\r\nParameter name: value\r\nActual value was driveKing.")); } @@ -2290,9 +2730,9 @@ namespace Meade.net.Telescope.UnitTests public void UTCDate_Get_WhenConnected_ThenReturnsUTCDateTime(string telescopeDate, string telescopeTime, string telescopeUtcCorrection, int year, int month, int day, int hour, int min, int second) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#", true)).Returns(telescopeDate); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#", true)).Returns(telescopeTime); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns(telescopeUtcCorrection); + _testProperties.telescopeDate = telescopeDate; + _testProperties.telescopeTime = telescopeTime; + _testProperties.telescopeUtcCorrection = telescopeUtcCorrection; ConnectTelescope(); @@ -2312,7 +2752,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void UTCDate_Set_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.UTCDate = new DateTime(2010,10,15,16,42,32, DateTimeKind.Utc); }); + var exception = Assert.Throws(() => _telescope.UTCDate = new DateTime(2010, 10, 15, 16, 42, 32, DateTimeKind.Utc)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: UTCDate Set")); } @@ -2325,12 +2765,12 @@ namespace Meade.net.Telescope.UnitTests var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns(telescopeUtcCorrection); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns(telescopeUtcCorrection); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("0"); ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.UTCDate = newDate; } ); + var exception = Assert.Throws(() => _telescope.UTCDate = newDate); Assert.That(exception.Message, Is.EqualTo("Failed to set local time")); } @@ -2339,18 +2779,18 @@ namespace Meade.net.Telescope.UnitTests [TestCase("12/03/15", "21:30:45", "+0.0", 2015, 12, 3, 21, 30, 45)] public void UTCDate_Set_WhenFailsToSetTelescopeDate_ThenThrowsException(string telescopeDate, string telescopeTime, string telescopeUtcCorrection, int year, int month, int day, int hour, int min, int second) { + _testProperties.telescopeUtcCorrection = telescopeUtcCorrection; double utcOffsetHours = double.Parse(telescopeUtcCorrection); TimeSpan utcCorrection = TimeSpan.FromHours(utcOffsetHours); var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns(telescopeUtcCorrection); - _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($"SL{telescopeTime}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{newDate:MM/dd/yy}", false)).Returns("0"); ConnectTelescope(); - - var exception = Assert.Throws(() => { _telescope.UTCDate = newDate; }); + + var exception = Assert.Throws(() => _telescope.UTCDate = newDate); Assert.That(exception.Message, Is.EqualTo("Failed to set local date")); } @@ -2364,11 +2804,12 @@ namespace Meade.net.Telescope.UnitTests double utcOffsetHours = double.Parse(telescopeUtcCorrection); TimeSpan utcCorrection = TimeSpan.FromHours(utcOffsetHours); + _testProperties.telescopeUtcCorrection = telescopeUtcCorrection; + var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns(telescopeUtcCorrection); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SC{telescopeDate}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{telescopeDate}", false)).Returns("1"); ConnectTelescope(); @@ -2382,12 +2823,12 @@ namespace Meade.net.Telescope.UnitTests { double rightAscension = 5.5; double declination = -30.5; - + var exception = Assert.Throws(() => { _telescope.SyncToCoordinates(rightAscension, declination); }); - + Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SyncToCoordinates")); } @@ -2404,7 +2845,7 @@ namespace Meade.net.Telescope.UnitTests var digitsRA = 2; - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{_testProperties.telescopeRaResult}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sr{_testProperties.telescopeRaResult}", false)).Returns("1"); _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.HMSToHours(hms)).Returns(_testProperties.rightAscension); @@ -2415,18 +2856,18 @@ namespace Meade.net.Telescope.UnitTests _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", 2)).Returns(hms); _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(dec); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{hms}#")).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sd{dec}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sr{hms}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sd{dec}", false)).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendString($":CM#", true)).Returns("M31 EX GAL MAG 3.5 SZ178.0'#"); + _sharedResourcesWrapperMock.Setup(x => x.SendString($"CM", false)).Returns("M31 EX GAL MAG 3.5 SZ178.0'#"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); ConnectTelescope(); _telescope.SyncToCoordinates(_testProperties.rightAscension, declination); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#", true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("CM", false), Times.Once); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); } @@ -2438,7 +2879,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.False); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Never); } [Test] @@ -2450,13 +2891,13 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.False); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Once); } [Test] public void Slewing_WhenTelescopeIsSlewing_ThenReturnsTrue() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns("|"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns("|"); ConnectTelescope(); @@ -2464,9 +2905,9 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.True); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true),Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Once); } - + [TestCase(0, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:01", false)] [TestCase(5, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:01", true)] [TestCase(5, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:06", false)] @@ -2480,8 +2921,9 @@ namespace Meade.net.Telescope.UnitTests [TestCase(15, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:10", true)] [TestCase(15, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:24", true)] [TestCase(15, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:25", false)] - public void Slewing_WhenTelescopeIsSlewing_ThenReturnsExpectedValueForSettleTime( short settleTime, short profileSettleTime, string startSlewing, string endSlewing, bool isSlewing) + public void Slewing_WhenTelescopeIsSlewing_ThenReturnsExpectedValueForSettleTime(short settleTime, short profileSettleTime, string startSlewing, string endSlewing, bool isSlewing) { + _sharedResourcesWrapperMock.SetupProperty(x => x.EarliestNonSlewingTime, DateTime.MinValue); _profileProperties.SettleTime = profileSettleTime; var timescalled = 0; @@ -2495,22 +2937,22 @@ namespace Meade.net.Telescope.UnitTests timescalled++; return startSlewingDateTime; } - + return endSlewingDatetime; }); var slewingText = "|"; var notSlewingText = String.Empty; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns( () => - { - if (timescalled == 0) - { - return slewingText; - } + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => + { + if (timescalled == 0) + { + return slewingText; + } - return notSlewingText; - }); + return notSlewingText; + }); ConnectTelescope(); @@ -2525,17 +2967,17 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.EqualTo(isSlewing)); } - [TestCase(TelescopeList.LX200CLASSIC,"","|", true)] + [TestCase(TelescopeList.LX200CLASSIC, "", "|", true)] [TestCase(TelescopeList.LX200CLASSIC, "", "||||||||", true)] [TestCase(TelescopeList.LX200CLASSIC, "", "", false)] [TestCase(TelescopeList.LX200CLASSIC, "", "[FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF] [FF][FF][FF][FF][FF][FF]", false)] //The test case below is this same string encoded to return exactly what the telescope will return. [TestCase(TelescopeList.LX200CLASSIC, "", "\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff \x00ff\x00ff\x00ff\x00ff\x00ff\x00ff", false)] [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "|", true)] - [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "\u007f", true)] + [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "\x007f", true)] [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "", false)] public void Slewing_WhenTelescopeNotSlewing_ThenReturnsFalse(string productName, string firmwareVersion, string response, bool isSlewing) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(response); + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(response); ConnectTelescope(productName, firmwareVersion); @@ -2543,7 +2985,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.EqualTo(isSlewing)); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Once); } [TestCase(1, TelescopeAxes.axisPrimary)] @@ -2552,6 +2994,10 @@ namespace Meade.net.Telescope.UnitTests [TestCase(-1, TelescopeAxes.axisSecondary)] public void Slewing_WhenTelescopeIsMoving_ThenDoesNotSendCommandAndReturnsTrue(int rate, TelescopeAxes axis) { + _sharedResourcesWrapperMock.SetupProperty(x => x.MovingPrimary); + _sharedResourcesWrapperMock.SetupProperty(x => x.MovingSecondary); + _sharedResourcesWrapperMock.SetupProperty(x => x.EarliestNonSlewingTime, DateTime.MinValue); + ConnectTelescope(); _telescope.MoveAxis(axis, rate); @@ -2559,7 +3005,10 @@ namespace Meade.net.Telescope.UnitTests var result = _telescope.Slewing; Assert.That(result, Is.True); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true), Times.Never); + Assert.That(_sharedResourcesWrapperMock.Object.MovingPrimary, Is.EqualTo(axis == TelescopeAxes.axisPrimary)); + Assert.That(_sharedResourcesWrapperMock.Object.MovingSecondary, Is.EqualTo(axis == TelescopeAxes.axisSecondary)); + + _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Never); } [TestCase(1, TelescopeAxes.axisPrimary, 0, 0, false, false)] @@ -2578,11 +3027,16 @@ namespace Meade.net.Telescope.UnitTests [TestCase(-1, TelescopeAxes.axisSecondary, 10, 20, true, true)] public void Slewing_WhenTelescopeStops_ThenWaitsForSettleTime(int rate, TelescopeAxes axis, short profileSettleTime, short driverSettleTime, bool expectedResultInWaitingPeriod, bool afterProfileSettleTimeUp) { + _sharedResourcesWrapperMock.SetupProperty(x => x.MovingPrimary); + _sharedResourcesWrapperMock.SetupProperty(x => x.MovingSecondary); + _sharedResourcesWrapperMock.SetupProperty(x => x.SlewSettleTime); + _sharedResourcesWrapperMock.SetupProperty(x => x.EarliestNonSlewingTime, DateTime.MinValue); + _profileProperties.SettleTime = profileSettleTime; DateTime currentTime = MakeTime("2021-01-23T22:02:10"); - _clockMock.Setup(x => x.UtcNow).Returns(() => currentTime ); + _clockMock.Setup(x => x.UtcNow).Returns(() => currentTime); ConnectTelescope(); @@ -2595,23 +3049,23 @@ namespace Meade.net.Telescope.UnitTests _telescope.MoveAxis(axis, 0); - currentTime = currentTime + TimeSpan.FromSeconds(profileSettleTime / 2); + currentTime += TimeSpan.FromSeconds(profileSettleTime / 2); result = _telescope.Slewing; Assert.That(result, Is.EqualTo(expectedResultInWaitingPeriod)); - currentTime = currentTime + TimeSpan.FromSeconds(profileSettleTime / 2); + currentTime += TimeSpan.FromSeconds(profileSettleTime / 2); result = _telescope.Slewing; Assert.That(result, Is.EqualTo(afterProfileSettleTimeUp)); - currentTime = currentTime + TimeSpan.FromSeconds(driverSettleTime); + currentTime += TimeSpan.FromSeconds(driverSettleTime); result = _telescope.Slewing; Assert.That(result, Is.False); } - private DateTime MakeTime( string dateTimeString ) + private DateTime MakeTime(string dateTimeString) { return DateTime.ParseExact(dateTimeString, "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); } @@ -2620,7 +3074,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToTargetAsync_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + var exception = Assert.Throws(() => _telescope.SlewToTargetAsync()); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewToTargetAsync")); } @@ -2631,7 +3085,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.TargetRightAscension = 1; - var exception = Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + var exception = Assert.Throws(() => _telescope.SlewToTargetAsync()); Assert.That(exception.Message, Is.EqualTo("Target not set")); } @@ -2642,7 +3096,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.TargetDeclination = 1; - var exception = Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + var exception = Assert.Throws(() => _telescope.SlewToTargetAsync()); Assert.That(exception.Message, Is.EqualTo("Target not set")); } @@ -2654,14 +3108,14 @@ namespace Meade.net.Telescope.UnitTests _telescope.TargetRightAscension = 2; _telescope.TargetDeclination = 1; - var exception = Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + var exception = Assert.Throws(() => _telescope.SlewToTargetAsync()); Assert.That(exception.Message, Is.EqualTo("This error should not happen")); } [Test] public void SlewToTargetAsync_WhenTargetSetAndSlewIsPossible_ThenAttemptsSlew() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); ConnectTelescope(); @@ -2671,13 +3125,13 @@ namespace Meade.net.Telescope.UnitTests _telescope.SlewToTargetAsync(); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(":MS#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); } [Test] public void SlewToTargetAsync_WhenTargetBelowHorizon_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.ReadTerminated()).Returns("Below horizon"); ConnectTelescope(); @@ -2685,14 +3139,14 @@ namespace Meade.net.Telescope.UnitTests _telescope.TargetRightAscension = 2; _telescope.TargetDeclination = 1; - var exception = Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + var exception = Assert.Throws(() => _telescope.SlewToTargetAsync()); Assert.That(exception.Message, Is.EqualTo("Below horizon")); } [Test] public void SlewToTargetAsync_WhenTargetBelowElevation_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("2"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("2"); _sharedResourcesWrapperMock.Setup(x => x.ReadTerminated()).Returns("Above below elevation"); ConnectTelescope(); @@ -2700,14 +3154,14 @@ namespace Meade.net.Telescope.UnitTests _telescope.TargetRightAscension = 2; _telescope.TargetDeclination = 1; - var exception = Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + var exception = Assert.Throws(() => _telescope.SlewToTargetAsync()); Assert.That(exception.Message, Is.EqualTo("Above below elevation")); } [Test] public void SlewToTargetAsync_WhenTelescopeCanHitTripod_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("3"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("3"); _sharedResourcesWrapperMock.Setup(x => x.ReadTerminated()).Returns("the telescope can hit the tripod"); ConnectTelescope(); @@ -2715,25 +3169,25 @@ namespace Meade.net.Telescope.UnitTests _telescope.TargetRightAscension = 2; _telescope.TargetDeclination = 1; - var exception = Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + var exception = Assert.Throws(() => _telescope.SlewToTargetAsync()); Assert.That(exception.Message, Is.EqualTo("the telescope can hit the tripod")); } [Test] public void SlewToTarget_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SlewToTarget(); }); + 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.SendChar(":MS#")).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); var slewCounter = 0; var iterations = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => { slewCounter++; if (slewCounter <= iterations) @@ -2748,13 +3202,14 @@ namespace Meade.net.Telescope.UnitTests _telescope.SlewToTarget(); - _utilMock.Verify( x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); + _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); + _astroUtilsMock.Verify(x => x.ConditionHA(It.IsAny()), Times.Once); } [Test] public void SlewToCoordinatesAsync_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SlewToCoordinatesAsync(0,0); }); + var exception = Assert.Throws(() => _telescope.SlewToCoordinatesAsync(0, 0)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewToCoordinatesAsync")); } @@ -2769,10 +3224,10 @@ namespace Meade.net.Telescope.UnitTests var telescopeDecResult = "s12*34’56"; - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{_testProperties.telescopeRaResult}#")).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sr{_testProperties.telescopeRaResult}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(declination); @@ -2780,7 +3235,7 @@ namespace Meade.net.Telescope.UnitTests //var slewCounter = 0; //var iterations = 10; - //_sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns(() => + //_sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => //{ // slewCounter++; // if (slewCounter <= iterations) @@ -2796,13 +3251,13 @@ namespace Meade.net.Telescope.UnitTests //_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); - _sharedResourcesWrapperMock.Verify( x => x.SendChar(":MS#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); } [Test] public void SlewToCoordinates_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SlewToCoordinates(0, 0); }); + var exception = Assert.Throws(() => _telescope.SlewToCoordinates(0, 0)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewToCoordinates")); } @@ -2816,18 +3271,18 @@ namespace Meade.net.Telescope.UnitTests var dmsResult = 1.2; var digitsRA = 2; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{_testProperties.telescopeRaResult}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sr{_testProperties.telescopeRaResult}", false)).Returns("1"); _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(telescopeDecResult); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); var slewCounter = 0; var iterations = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => { slewCounter++; if (slewCounter <= iterations) @@ -2840,15 +3295,16 @@ namespace Meade.net.Telescope.UnitTests _telescope.SlewToCoordinates(_testProperties.rightAscension, declination); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(dmsResult)); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(":MS#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); + _astroUtilsMock.Verify(x => x.ConditionHA(It.IsAny()), Times.Once); } [Test] public void SlewToAltAzAsync_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SlewToAltAzAsync(0, 0); }); + var exception = Assert.Throws(() => _telescope.SlewToAltAzAsync(0, 0)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewToAltAzAsync")); } @@ -2857,7 +3313,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SlewToAltAzAsync(0, 90.1); }); + var exception = Assert.Throws(() => _telescope.SlewToAltAzAsync(0, 90.1)); Assert.That(exception.Message, Is.EqualTo("Altitude cannot be greater than 90.")); } @@ -2866,7 +3322,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SlewToAltAzAsync(0, -0.1); }); + var exception = Assert.Throws(() => _telescope.SlewToAltAzAsync(0, -0.1)); Assert.That(exception.Message, Is.EqualTo("Altitide cannot be less than 0.")); } @@ -2875,7 +3331,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SlewToAltAzAsync(360, 0); }); + var exception = Assert.Throws(() => _telescope.SlewToAltAzAsync(360, 0)); Assert.That(exception.Message, Is.EqualTo("Azimuth cannot be 360 or higher.")); } @@ -2884,7 +3340,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SlewToAltAzAsync(-0.1, 0); }); + var exception = Assert.Throws(() => _telescope.SlewToAltAzAsync(-0.1, 0)); Assert.That(exception.Message, Is.EqualTo("Azimuth cannot be less than 0.")); } @@ -2892,45 +3348,39 @@ namespace Meade.net.Telescope.UnitTests public void SlewToAltAzAsync_WhenAltAndAzValid_ThenConvertsToRADec() { _testProperties.rightAscension = 20; + _testProperties.declination = 10; var altitude = 30; var azimuth = 45; - var declination = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#", true)).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#", true)).Returns("20:15:10"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); - _astroMathsMock - .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), - It.IsAny())).Returns(new EquatorialCoordinates { Declination = declination, RightAscension = _testProperties.rightAscension }); - - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); var telescopeRaResult = "HH:MM:SS"; var telescopeDecResult = "s12*34’56"; var digitsRA = 2; - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{telescopeRaResult}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sr{telescopeRaResult}", false)).Returns("1"); _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(telescopeRaResult); _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(_testProperties.rightAscension); - _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(telescopeDecResult); - _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(declination); + _utilMock.Setup(x => x.DegreesToDMS(_testProperties.declination, "*", ":", ":", digitsRA)).Returns(telescopeDecResult); + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(_testProperties.declination); ConnectTelescope(); _telescope.SlewToAltAzAsync(azimuth, altitude); - + Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); - Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(":MS#"), Times.Once); + Assert.That(_telescope.TargetDeclination, Is.EqualTo(_testProperties.declination)); + _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); } [Test] public void SlewToAltAz_WhenAzimuthLowerThan0_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SlewToAltAz(0, 0); }); + var exception = Assert.Throws(() => _telescope.SlewToAltAz(0, 0)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewToAltAz")); } @@ -2938,28 +3388,22 @@ namespace Meade.net.Telescope.UnitTests public void SlewToAltAz_WhenCalled_ThenSetsTargetAndSlews() { _testProperties.rightAscension = 10.0; - var declination = 20; + _testProperties.declination = 20; var azimuth = 30; var altitude = 40; _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", 2)).Returns(_testProperties.telescopeRaResult); - _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(_testProperties.telescopeRaResult); - _utilMock.Setup(x => x.DMSToDegrees(_testProperties.telescopeRaResult)).Returns(declination); - - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#", true)).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#", true)).Returns("20:15:10"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("-1.0"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":Sd+HH:MM:SS#")).Returns("1"); + _utilMock.Setup(x => x.DegreesToDMS(_testProperties.declination, "*", ":", ":", 2)).Returns(_testProperties.telescopeRaResult); + _utilMock.Setup(x => x.DMSToDegrees(_testProperties.telescopeRaResult)).Returns(_testProperties.declination); - _astroMathsMock - .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), - It.IsAny())).Returns(new EquatorialCoordinates { Declination = declination, RightAscension = _testProperties.rightAscension }); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("Sd+HH:MM:SS", false)).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); var slewCounter = 0; var iterations = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => { slewCounter++; if (slewCounter <= iterations) @@ -2968,13 +3412,14 @@ namespace Meade.net.Telescope.UnitTests }); ConnectTelescope(); - - _telescope.SlewToAltAz( azimuth, altitude); + + _telescope.SlewToAltAz(azimuth, altitude); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); - Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(":MS#"), Times.Once); + Assert.That(_telescope.TargetDeclination, Is.EqualTo(_testProperties.declination)); + _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); + _astroUtilsMock.Verify(x => x.ConditionHA(It.IsAny()), Times.Once); } [Test] @@ -2991,29 +3436,24 @@ namespace Meade.net.Telescope.UnitTests [Test] public void Azimuth_WhenConnected_ThenReturnsTelescopeAzumith() { - var expectedAzimuth = 200; - var telescopeLongitude = "350"; var telescopeLongitudeValue = 350; - - var mockHourAngle = 3; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#", true)).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#", true)).Returns("20:15:10"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("-1.0"); + _testProperties.telescopeAltitude = 45; + _testProperties.telescopeAzimuth = 200; + _testProperties.hourAngle = 3; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gg#", true)).Returns(telescopeLongitude); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); + + _sharedResourcesWrapperMock.Setup(x => x.SendString("Gg", false)).Returns(telescopeLongitude); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); - - _astroMathsMock.Setup(x => x.RightAscensionToHourAngle(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockHourAngle); - _astroMathsMock.Setup(x => x.ConvertEqToHoz(mockHourAngle, It.IsAny(), It.IsAny())).Returns(new HorizonCoordinates { Altitude = 45, Azimuth = expectedAzimuth }); ConnectTelescope(); var result = _telescope.Azimuth; - Assert.That(result,Is.EqualTo(expectedAzimuth)); + Assert.That(result, Is.EqualTo(_testProperties.telescopeAzimuth)); } [Test] @@ -3035,18 +3475,13 @@ namespace Meade.net.Telescope.UnitTests var telescopeLongitude = "350"; var telescopeLongitudeValue = 350; - var mockHourAngle = 3; + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#", true)).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#", true)).Returns("20:15:10"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("-1.0"); - - _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gg#", true)).Returns(telescopeLongitude); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); - _astroMathsMock.Setup(x => x.RightAscensionToHourAngle(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockHourAngle); + _astroMathsMock.Setup(x => x.RightAscensionToHourAngle(It.IsAny(), It.IsAny(), It.IsAny())).Returns(_testProperties.hourAngle); - _astroMathsMock.Setup(x => x.ConvertEqToHoz(mockHourAngle, It.IsAny(), It.IsAny())).Returns(new HorizonCoordinates { Altitude = expectedAltitude, Azimuth = 200 }); + _astroMathsMock.Setup(x => x.ConvertEqToHoz(_testProperties.hourAngle, It.IsAny(), It.IsAny())).Returns(new HorizonCoordinates { Altitude = expectedAltitude, Azimuth = 200 }); ConnectTelescope(); @@ -3058,7 +3493,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void AbortSlew_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.AbortSlew(); }); + var exception = Assert.Throws(() => _telescope.AbortSlew()); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: AbortSlew")); } @@ -3069,12 +3504,12 @@ namespace Meade.net.Telescope.UnitTests _telescope.AbortSlew(); - _sharedResourcesWrapperMock.Verify( x => x.SendBlind(":Q#"),Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Q", false), Times.Once); var isSloSlewing = _telescope.Slewing; Assert.That(isSloSlewing, Is.False); - _sharedResourcesWrapperMock.Verify( x => x.SendString(":D#", true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Once); } [Test] @@ -3083,7 +3518,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.AbortSlew(); }); + Assert.Throws(() => _telescope.AbortSlew()); } [Test] @@ -3092,7 +3527,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.MoveAxis(TelescopeAxes.axisPrimary, 0); }); + Assert.Throws(() => _telescope.MoveAxis(TelescopeAxes.axisPrimary, 0)); } [Test] @@ -3101,7 +3536,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.PulseGuide(GuideDirections.guideEast, 0); }); + Assert.Throws(() => _telescope.PulseGuide(GuideDirections.guideEast, 0)); } [Test] @@ -3110,7 +3545,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToAltAz(0, 0); }); + Assert.Throws(() => _telescope.SlewToAltAz(0, 0)); } [Test] @@ -3119,7 +3554,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToAltAzAsync(0, 0); }); + Assert.Throws(() => _telescope.SlewToAltAzAsync(0, 0)); } [Test] @@ -3128,7 +3563,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToCoordinates(0, 0); }); + Assert.Throws(() => _telescope.SlewToCoordinates(0, 0)); } [Test] @@ -3137,7 +3572,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToCoordinatesAsync(0, 0); }); + Assert.Throws(() => _telescope.SlewToCoordinatesAsync(0, 0)); } [Test] @@ -3146,7 +3581,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToTarget(); }); + Assert.Throws(() => _telescope.SlewToTarget()); } [Test] @@ -3155,7 +3590,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + Assert.Throws(() => _telescope.SlewToTargetAsync()); } [Test] @@ -3164,7 +3599,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SyncToCoordinates(0,0); }); + Assert.Throws(() => _telescope.SyncToCoordinates(0, 0)); } [Test] @@ -3173,7 +3608,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SyncToTarget(); }); + Assert.Throws(() => _telescope.SyncToTarget()); } [Test] @@ -3182,7 +3617,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.TargetDeclination = 1; }); + Assert.Throws(() => _telescope.TargetDeclination = 1); } [Test] @@ -3191,7 +3626,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.TargetRightAscension = 1; }); + Assert.Throws(() => _telescope.TargetRightAscension = 1); } [Test] @@ -3200,7 +3635,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.TrackingRate = DriveRates.driveLunar; }); + Assert.Throws(() => _telescope.TrackingRate = DriveRates.driveLunar); } @@ -3211,7 +3646,7 @@ namespace Meade.net.Telescope.UnitTests { _profileProperties.ParkedBehaviour = behaviour; DateTime testNow = DateTime.ParseExact("2021-10-03T20:36:25", "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); - _clockMock.Setup(x => x.UtcNow).Returns(() => { return testNow; }); + _clockMock.Setup(x => x.UtcNow).Returns(() => testNow); ConnectTelescope(); _telescope.Park(); @@ -3265,7 +3700,7 @@ namespace Meade.net.Telescope.UnitTests var l = _telescope.SiteLongitude; Assert.That(l, Is.EqualTo(siteLongitude)); } - + } [TestCase(ParkedBehaviour.NoCoordinates)] @@ -3278,13 +3713,9 @@ namespace Meade.net.Telescope.UnitTests _profileProperties.ParkedAz = 180; DateTime testNow = DateTime.ParseExact("2021-10-03T20:36:25", "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); - var declination = 45; + _testProperties.declination = 45; - _clockMock.Setup(x => x.UtcNow).Returns(() => { return testNow; }); - - _astroMathsMock - .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), - It.IsAny())).Returns(new EquatorialCoordinates { Declination = declination, RightAscension = _testProperties.rightAscension }); + _clockMock.Setup(x => x.UtcNow).Returns(() => testNow); ConnectTelescope(); _telescope.Park(); @@ -3297,7 +3728,7 @@ namespace Meade.net.Telescope.UnitTests break; case ParkedBehaviour.ReportCoordinates: var dec = _telescope.Declination; - Assert.That(dec, Is.EqualTo(declination)); + Assert.That(dec, Is.EqualTo(_testProperties.declination)); break; default: Assert.Throws(() => { var d = _telescope.Declination; }); @@ -3317,7 +3748,7 @@ namespace Meade.net.Telescope.UnitTests var declination = 45; - _clockMock.Setup(x => x.UtcNow).Returns(() => { return testNow; }); + _clockMock.Setup(x => x.UtcNow).Returns(() => testNow); _astroMathsMock .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), diff --git a/Meade.net.Telescope/Meade.net.Telescope.csproj b/Meade.net.Telescope/Meade.net.Telescope.csproj index f60b4d1..a884ce0 100644 --- a/Meade.net.Telescope/Meade.net.Telescope.csproj +++ b/Meade.net.Telescope/Meade.net.Telescope.csproj @@ -62,7 +62,7 @@ ..\bin\Release\ - false + true ..\bin\Debug\ @@ -192,7 +192,7 @@ -