diff --git a/AstroMath.UnitTests/AstroMathsUnitTests.cs b/AstroMath.UnitTests/AstroMathsUnitTests.cs index cdbe4ad..a890647 100644 --- a/AstroMath.UnitTests/AstroMathsUnitTests.cs +++ b/AstroMath.UnitTests/AstroMathsUnitTests.cs @@ -1,5 +1,6 @@ using System; using ASCOM.Meade.net; +using ASCOM.Meade.net.AstroMaths; using NUnit.Framework; namespace AstroMath.UnitTests diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index a427f0c..d174cec 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1,5 +1,8 @@ -using ASCOM.Astrometry.AstroUtils; +using System.Xml.Serialization; +using ASCOM; +using ASCOM.Astrometry.AstroUtils; using ASCOM.Meade.net; +using ASCOM.Meade.net.AstroMaths; using ASCOM.Meade.net.Wrapper; using ASCOM.Utilities.Interfaces; using Moq; @@ -34,7 +37,8 @@ namespace Meade.net.Telescope.UnitTests _astroMathsMock = new Mock(); - _telescope = new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, _sharedResourcesWrapperMock.Object, _astroMathsMock.Object); + _telescope = new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object); } [Test] @@ -56,8 +60,75 @@ namespace Meade.net.Telescope.UnitTests _telescope.SetupDialog(); - _sharedResourcesWrapperMock.Verify( x => x.SetupDialog(), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SetupDialog(), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.ReadProfile(), Times.Exactly(2)); } + + [Test] + public void SupportedActions() + { + var supportedActions = _telescope.SupportedActions; + + Assert.That(supportedActions, Is.Not.Null); + Assert.That(supportedActions.Count, Is.EqualTo(1)); + Assert.That(supportedActions.Contains("handbox"), Is.True); + } + + [Test] + public void Action_Handbox_ReadDisplay() + { + string expectedResult = "test result string"; + _sharedResourcesWrapperMock.Setup(x => x.SendString(It.IsAny())).Returns(expectedResult); + + var actualResult = _telescope.Action("handbox", "readdisplay"); + + _sharedResourcesWrapperMock.Verify(x => x.SendString(":ED#"), 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#")] + public void Action_Handbox_blindCommands(string action, string expectedString) + { + _telescope.Action("handbox", action); + + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedString), Times.Once); + } + + [Test] + public void Action_Handbox_nonExistantAction() + { + string actionName = "handbox"; + string actionParameters = "doesnotexist"; + 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.")); + } + + [Test] + public void Action_nonExistantAction() + { + string actionName = "doesnotexist"; + 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.")); + } } } diff --git a/Meade.net.Telescope/AstroMaths/AltitudeData.cs b/Meade.net.Telescope/AstroMaths/AltitudeData.cs new file mode 100644 index 0000000..a00f7db --- /dev/null +++ b/Meade.net.Telescope/AstroMaths/AltitudeData.cs @@ -0,0 +1,12 @@ +using System; + +namespace ASCOM.Meade.net.AstroMaths +{ + public class AltitudeData + { + public DateTime UtcDateTime { get; set; } + public double SiteLatitude { get; set; } + public double SiteLongitude { get; set; } + public EquatorialCoordinates equatorialCoordinates { get; set; } + } +} \ No newline at end of file diff --git a/Meade.net.Telescope/AstroMaths.cs b/Meade.net.Telescope/AstroMaths/AstroMaths.cs similarity index 90% rename from Meade.net.Telescope/AstroMaths.cs rename to Meade.net.Telescope/AstroMaths/AstroMaths.cs index f197b5f..45fea5f 100644 --- a/Meade.net.Telescope/AstroMaths.cs +++ b/Meade.net.Telescope/AstroMaths/AstroMaths.cs @@ -1,29 +1,8 @@ using System; using ASCOM.Utilities; -namespace ASCOM.Meade.net +namespace ASCOM.Meade.net.AstroMaths { - public class EquatorialCoordinates - { - public double RightAscension { get; set; } - public double Declination { get; set; } - } - - public class HorizonCoordinates - { - public double Altitude { get; set; } - public double Azimuth { get; set; } - } - - - public class AltitudeData - { - public DateTime UtcDateTime { get; set; } - public double SiteLatitude { get; set; } - public double SiteLongitude { get; set; } - public EquatorialCoordinates equatorialCoordinates { get; set; } - } - public class AstroMaths : IAstroMaths { diff --git a/Meade.net.Telescope/AstroMaths/EquatorialCoordinates.cs b/Meade.net.Telescope/AstroMaths/EquatorialCoordinates.cs new file mode 100644 index 0000000..e181e79 --- /dev/null +++ b/Meade.net.Telescope/AstroMaths/EquatorialCoordinates.cs @@ -0,0 +1,8 @@ +namespace ASCOM.Meade.net.AstroMaths +{ + public class EquatorialCoordinates + { + public double RightAscension { get; set; } + public double Declination { get; set; } + } +} \ No newline at end of file diff --git a/Meade.net.Telescope/AstroMaths/HorizonCoordinates.cs b/Meade.net.Telescope/AstroMaths/HorizonCoordinates.cs new file mode 100644 index 0000000..de7eeae --- /dev/null +++ b/Meade.net.Telescope/AstroMaths/HorizonCoordinates.cs @@ -0,0 +1,8 @@ +namespace ASCOM.Meade.net.AstroMaths +{ + public class HorizonCoordinates + { + public double Altitude { get; set; } + public double Azimuth { get; set; } + } +} \ No newline at end of file diff --git a/Meade.net.Telescope/IAstroMaths.cs b/Meade.net.Telescope/AstroMaths/IAstroMaths.cs similarity index 95% rename from Meade.net.Telescope/IAstroMaths.cs rename to Meade.net.Telescope/AstroMaths/IAstroMaths.cs index 970942c..ff4ef4e 100644 --- a/Meade.net.Telescope/IAstroMaths.cs +++ b/Meade.net.Telescope/AstroMaths/IAstroMaths.cs @@ -1,6 +1,6 @@ using System; -namespace ASCOM.Meade.net +namespace ASCOM.Meade.net.AstroMaths { public interface IAstroMaths { diff --git a/Meade.net.Telescope/Meade.net.Telescope.csproj b/Meade.net.Telescope/Meade.net.Telescope.csproj index 6f0fdde..cf50efa 100644 --- a/Meade.net.Telescope/Meade.net.Telescope.csproj +++ b/Meade.net.Telescope/Meade.net.Telescope.csproj @@ -113,8 +113,11 @@ - - + + + + + diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index b0987af..d80f52f 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -8,6 +8,7 @@ using ASCOM.DeviceInterface; using System.Globalization; using System.Collections; using System.Reflection; +using ASCOM.Meade.net.AstroMaths; using ASCOM.Meade.net.Wrapper; using ASCOM.Utilities.Interfaces; @@ -80,7 +81,7 @@ namespace ASCOM.Meade.net _utilitiesExtra = util; //Initialise util object _astroUtilities = new AstroUtils(); // Initialise astro utilities object _sharedResourcesWrapper = new SharedResourcesWrapper(); - _astroMaths = new AstroMaths(); + _astroMaths = new AstroMaths.AstroMaths(); Initialise(); } @@ -173,7 +174,7 @@ namespace ASCOM.Meade.net case "mode": _sharedResourcesWrapper.SendBlind(":EK9#"); break; - case "longMode": + case "longmode": _sharedResourcesWrapper.SendBlind(":EK11#"); break; case "goto": @@ -228,12 +229,12 @@ namespace ASCOM.Meade.net break; default: LogMessage("", "Action {0}, parameters {1} not implemented", actionName, actionParameters); - throw new ASCOM.ActionNotImplementedException($"Action {actionName}({actionParameters}) is not implemented by this driver"); + throw new ASCOM.ActionNotImplementedException($"{actionName}({actionParameters})"); } break; default: LogMessage("", "Action {0}, parameters {1} not implemented", actionName, actionParameters); - throw new ASCOM.ActionNotImplementedException($"Action {actionName} is not implemented by this driver"); + throw new ASCOM.ActionNotImplementedException($"{actionName}"); } return string.Empty; diff --git a/Meade.net.v3.ncrunchsolution.user b/Meade.net.v3.ncrunchsolution.user index b162f35..24ce899 100644 --- a/Meade.net.v3.ncrunchsolution.user +++ b/Meade.net.v3.ncrunchsolution.user @@ -2,6 +2,7 @@ True Run all tests automatically [Global] + False 25 false