More unit testing. Added check for to be able to support setting the alignment mode

This commit is contained in:
2019-07-13 20:02:06 +01:00
parent bfde58c6af
commit 8980c3c6b5
3 changed files with 99 additions and 10 deletions
@@ -9,6 +9,7 @@ using ASCOM.Meade.net.Wrapper;
using ASCOM.Utilities.Interfaces;
using Moq;
using NUnit.Framework;
using NotImplementedException = ASCOM.NotImplementedException;
namespace Meade.net.Telescope.UnitTests
{
@@ -39,6 +40,7 @@ namespace Meade.net.Telescope.UnitTests
_sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#")).Returns("DDD*MMSS");
_sharedResourcesWrapperMock.Setup(x => x.AUTOSTAR497).Returns(() => "AUTOSTAR");
_sharedResourcesWrapperMock.Setup(x => x.AUTOSTAR497_31EE).Returns(() => "31Ee");
_sharedResourcesWrapperMock.Setup(x => x.AUTOSTAR497_43EG) .Returns(() => "43Eg");
_sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny<Action>())).Callback<Action>(action => { action(); });
@@ -300,7 +302,7 @@ namespace Meade.net.Telescope.UnitTests
[TestCase("AUTOSTAR", "30Ab", false)]
[TestCase("AUTOSTAR","31Ee", true)]
[TestCase("AUTOSTAR", "41Aa", true)]
[TestCase("AUTOSTAR", "43Eg", true)]
[TestCase("AUTOSTAR II", "", false)]
public void IsNewPulseGuidingSupported_ThenIsSupported_ThenReturnsTrue(string productName, string firmware, bool isSupported)
{
@@ -429,5 +431,80 @@ namespace Meade.net.Telescope.UnitTests
Assert.That(name, Is.EqualTo(expectedName));
}
[Test]
public void AlignmentMode_Get_WhenNotConnected_ThrowsException()
{
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497);
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE);
var exception = Assert.Throws<NotConnectedException>(() => { var actualResult = _telescope.AlignmentMode; });
Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: AlignmentMode Get"));
}
[TestCase("A", AlignmentModes.algAltAz)]
[TestCase("P", AlignmentModes.algPolar)]
[TestCase("G", AlignmentModes.algGermanPolar)]
public void AlignmentMode_Get_WhenScopeInAltAz_ReturnsAltAz(string telescopeMode, AlignmentModes alignmentMode)
{
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497);
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE);
_telescope.Connected = true;
const char ack = (char)6;
_sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString())).Returns(telescopeMode);
var actualResult = _telescope.AlignmentMode;
Assert.That(actualResult, Is.EqualTo(alignmentMode));
}
[Test]
public void AlignmentMode_Get_WhenUnknownAlignmentMode_ThrowsException()
{
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497);
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE);
_telescope.Connected = true;
Assert.Throws<InvalidValueException>(() => { var actualResult = _telescope.AlignmentMode; });
}
[Test]
public void AlignmentMode_Set_WhenNotConnected_ThrowsException()
{
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497);
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE);
var exception = Assert.Throws<NotConnectedException>(() => { _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#")]
public void AlignmentMode_Set_WhenConnected_ThenSendsExpectedCommand(string productName, string firmware, AlignmentModes alignmentMode, string expectedCommand)
{
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName);
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware);
_telescope.Connected = true;
_telescope.AlignmentMode = alignmentMode;
_sharedResourcesWrapperMock.Verify( x => x.SendBlind(expectedCommand), Times.Once);
}
[TestCase("AUTOSTAR", "43Ef")]
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<PropertyNotImplementedException>(() => { _telescope.AlignmentMode = AlignmentModes.algAltAz; });
Assert.That(excpetion.Property, Is.EqualTo("AlignmentMode"));
Assert.That(excpetion.AccessorSet, Is.True);
}
}
}
+18 -9
View File
@@ -482,14 +482,17 @@ namespace ASCOM.Meade.net
//L If scope in Land Mode
//P If scope in Polar Mode
//todo implement GW Command
//var alignmentString = SerialPort.CommandTerminated(":GW#", "#");
//:GW# Get Scope Alignment Status
//Returns: <mount><tracking><alignment>#
// where:
//mount: A - AzEl mounted, P - Equatorially mounted, G - german mounted equatorial
//tracking: T - tracking, N - not tracking
//alignment: 0 - needs alignment, 1 - one star aligned, 2 - two star aligned, 3 - three star aligned.
//todo implement GW Command - Supported in Autostar 43Eg and above
//if FirmwareIsGreaterThan(_sharedResourcesWrapper.AUTOSTAR497_43EG)
//{
//var alignmentString = SerialPort.CommandTerminated(":GW#", "#");
//:GW# Get Scope Alignment Status
//Returns: <mount><tracking><alignment>#
// where:
//mount: A - AzEl mounted, P - Equatorially mounted, G - german mounted equatorial
//tracking: T - tracking, N - not tracking
//alignment: 0 - needs alignment, 1 - one star aligned, 2 - two star aligned, 3 - three star aligned.
//}
AlignmentModes alignmentMode;
switch (alignmentString)
@@ -515,7 +518,13 @@ namespace ASCOM.Meade.net
{
CheckConnected("AlignmentMode Set");
switch (value)
//todo tidy this up into a better solution that means can :GW#, :AL#, :AA#, & :AP# and checked for Autostar properly
if (!FirmwareIsGreaterThan(_sharedResourcesWrapper.AUTOSTAR497_43EG))
throw new PropertyNotImplementedException("AlignmentMode",true );
//todo make this only try with Autostar 43Eg and above.
switch (value)
{
case AlignmentModes.algAltAz:
_sharedResourcesWrapper.SendBlind(":AA#");
@@ -10,6 +10,8 @@ namespace ASCOM.Meade.net.Wrapper
string AUTOSTAR497 { get; }
string AUTOSTAR497_31EE { get; }
string AUTOSTAR497_43EG { get;}
void Connect(string deviceId);
void Disconnect(string deviceId);
@@ -38,6 +40,7 @@ namespace ASCOM.Meade.net.Wrapper
public string AUTOSTAR497 => "Autostar";
public string AUTOSTAR497_31EE => "31Ee";
public string AUTOSTAR497_43EG => "43Eg";
#endregion