Added check to ensure that telescope is in Polar Mode when attempting to PulseGuide. CanPulseGuide also fails when scope is in AltAz mode.

This commit is contained in:
2022-05-05 20:40:51 +01:00
parent f788320927
commit 503eec38a3
2 changed files with 43 additions and 6 deletions
@@ -18,6 +18,7 @@ namespace Meade.net.Telescope.UnitTests
{ {
public class TestProperties public class TestProperties
{ {
public string AlignmentMode { get; internal set; } = "P";
internal string telescopeRaResult { get; set; } = "HH:MM:SS"; internal string telescopeRaResult { get; set; } = "HH:MM:SS";
internal double rightAscension { get; set; } = 1.2; //todo rename to declination; internal double rightAscension { get; set; } = 1.2; //todo rename to declination;
internal double declination { get; set; } = 45; internal double declination { get; set; } = 45;
@@ -155,6 +156,9 @@ namespace Meade.net.Telescope.UnitTests
_parkedPosition = parkedPostion; _parkedPosition = parkedPostion;
}); });
const char ack = (char)6;
_sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString(), false)).Returns( () => _testProperties.AlignmentMode);
_sharedResourcesWrapperMock.SetupGet(x => x.IsParked).Returns(() => _isParked); _sharedResourcesWrapperMock.SetupGet(x => x.IsParked).Returns(() => _isParked);
_sharedResourcesWrapperMock.SetupGet(x => x.ParkedPosition).Returns(() => _parkedPosition); _sharedResourcesWrapperMock.SetupGet(x => x.ParkedPosition).Returns(() => _parkedPosition);
@@ -793,9 +797,7 @@ namespace Meade.net.Telescope.UnitTests
[TestCase("G", AlignmentModes.algGermanPolar, TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg)] [TestCase("G", AlignmentModes.algGermanPolar, TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg)]
public void AlignmentMode_Get_WhenScopeInAltAz_ReturnsAltAz(string telescopeMode, AlignmentModes alignmentMode, string productName, string firmware) public void AlignmentMode_Get_WhenScopeInAltAz_ReturnsAltAz(string telescopeMode, AlignmentModes alignmentMode, string productName, string firmware)
{ {
const char ack = (char)6; _testProperties.AlignmentMode = telescopeMode;
_sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString(), false)).Returns(telescopeMode);
ConnectTelescope(productName, firmware, $"{telescopeMode}N0"); ConnectTelescope(productName, firmware, $"{telescopeMode}N0");
var actualResult = _telescope.AlignmentMode; var actualResult = _telescope.AlignmentMode;
@@ -806,6 +808,7 @@ namespace Meade.net.Telescope.UnitTests
[Test] [Test]
public void AlignmentMode_Get_WhenUnknownAlignmentMode_ThrowsException() public void AlignmentMode_Get_WhenUnknownAlignmentMode_ThrowsException()
{ {
_testProperties.AlignmentMode = "";
ConnectTelescope(); ConnectTelescope();
Assert.Throws<InvalidValueException>(() => Assert.Throws<InvalidValueException>(() =>
@@ -929,13 +932,25 @@ namespace Meade.net.Telescope.UnitTests
} }
[Test] [Test]
public void CanPulseGuide_Get_ReturnsTrue() public void CanPulseGuide_GetInPolarMode_ReturnsTrue()
{ {
_testProperties.AlignmentMode = "P";
ConnectTelescope();
var result = _telescope.CanPulseGuide; var result = _telescope.CanPulseGuide;
Assert.That(result, Is.True); Assert.That(result, Is.True);
} }
[Test]
public void CanPulseGuide_GetInAltAzMode_ReturnsFalse()
{
_testProperties.AlignmentMode = "A";
ConnectTelescope();
var result = _telescope.CanPulseGuide;
Assert.That(result, Is.False);
}
[Test] [Test]
public void CanSetDeclinationRate_Get_ReturnsFalse() public void CanSetDeclinationRate_Get_ReturnsFalse()
{ {
@@ -1696,6 +1711,23 @@ namespace Meade.net.Telescope.UnitTests
Assert.That(exception.Message, Is.EqualTo("Unable to PulseGuide whilst slewing to target.")); Assert.That(exception.Message, Is.EqualTo("Unable to PulseGuide whilst slewing to target."));
} }
[TestCase(GuideDirections.guideEast)]
[TestCase(GuideDirections.guideWest)]
[TestCase(GuideDirections.guideNorth)]
[TestCase(GuideDirections.guideSouth)]
public void PulseGuide_WhenAltAzPulseGuideAttempted_ThenThrowsExpectedException(GuideDirections direction)
{
_testProperties.AlignmentMode = "A";
_sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns("");
var duration = 1;
ConnectTelescope();
var exception = Assert.Throws<InvalidOperationException>(() => _telescope.PulseGuide(direction, duration));
Assert.That(exception.Message, Is.EqualTo("Unable to PulseGuide whilst in AltAz mode."));
}
[TestCase(GuideDirections.guideEast, TelescopeAxes.axisPrimary)] [TestCase(GuideDirections.guideEast, TelescopeAxes.axisPrimary)]
[TestCase(GuideDirections.guideWest, TelescopeAxes.axisPrimary)] [TestCase(GuideDirections.guideWest, TelescopeAxes.axisPrimary)]
[TestCase(GuideDirections.guideNorth, TelescopeAxes.axisSecondary)] [TestCase(GuideDirections.guideNorth, TelescopeAxes.axisSecondary)]
+7 -2
View File
@@ -1274,8 +1274,10 @@ namespace ASCOM.Meade.net
{ {
get get
{ {
LogMessage("CanPulseGuide", "Get - " + true); CheckConnected("CanPulseGuide");
return true; var canPulseGuide = AlignmentMode != AlignmentModes.algAltAz;
LogMessage("CanPulseGuide", $"Get - {canPulseGuide}");
return canPulseGuide;
} }
} }
@@ -1759,6 +1761,9 @@ namespace ASCOM.Meade.net
if (IsSlewingToTarget()) if (IsSlewingToTarget())
throw new InvalidOperationException("Unable to PulseGuide whilst slewing to target."); throw new InvalidOperationException("Unable to PulseGuide whilst slewing to target.");
if (AlignmentMode == AlignmentModes.algAltAz)
throw new InvalidOperationException("Unable to PulseGuide whilst in AltAz mode.");
SharedResourcesWrapper.IsGuiding = true; SharedResourcesWrapper.IsGuiding = true;
try try
{ {