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 960f578ea2
3 changed files with 99 additions and 10 deletions
@@ -9,6 +9,7 @@ using ASCOM.Meade.net.Wrapper;
using ASCOM.Utilities.Interfaces; using ASCOM.Utilities.Interfaces;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NotImplementedException = ASCOM.NotImplementedException;
namespace Meade.net.Telescope.UnitTests 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.SendString(":GZ#")).Returns("DDD*MMSS");
_sharedResourcesWrapperMock.Setup(x => x.AUTOSTAR497).Returns(() => "AUTOSTAR"); _sharedResourcesWrapperMock.Setup(x => x.AUTOSTAR497).Returns(() => "AUTOSTAR");
_sharedResourcesWrapperMock.Setup(x => x.AUTOSTAR497_31EE).Returns(() => "31Ee"); _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(); }); _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", "30Ab", false)]
[TestCase("AUTOSTAR","31Ee", true)] [TestCase("AUTOSTAR","31Ee", true)]
[TestCase("AUTOSTAR", "41Aa", true)] [TestCase("AUTOSTAR", "43Eg", true)]
[TestCase("AUTOSTAR II", "", false)] [TestCase("AUTOSTAR II", "", false)]
public void IsNewPulseGuidingSupported_ThenIsSupported_ThenReturnsTrue(string productName, string firmware, bool isSupported) 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)); 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 //L If scope in Land Mode
//P If scope in Polar Mode //P If scope in Polar Mode
//todo implement GW Command //todo implement GW Command - Supported in Autostar 43Eg and above
//var alignmentString = SerialPort.CommandTerminated(":GW#", "#"); //if FirmwareIsGreaterThan(_sharedResourcesWrapper.AUTOSTAR497_43EG)
//:GW# Get Scope Alignment Status //{
//Returns: <mount><tracking><alignment># //var alignmentString = SerialPort.CommandTerminated(":GW#", "#");
// where: //:GW# Get Scope Alignment Status
//mount: A - AzEl mounted, P - Equatorially mounted, G - german mounted equatorial //Returns: <mount><tracking><alignment>#
//tracking: T - tracking, N - not tracking // where:
//alignment: 0 - needs alignment, 1 - one star aligned, 2 - two star aligned, 3 - three star aligned. //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; AlignmentModes alignmentMode;
switch (alignmentString) switch (alignmentString)
@@ -515,7 +518,13 @@ namespace ASCOM.Meade.net
{ {
CheckConnected("AlignmentMode Set"); 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: case AlignmentModes.algAltAz:
_sharedResourcesWrapper.SendBlind(":AA#"); _sharedResourcesWrapper.SendBlind(":AA#");
@@ -10,6 +10,8 @@ namespace ASCOM.Meade.net.Wrapper
string AUTOSTAR497 { get; } string AUTOSTAR497 { get; }
string AUTOSTAR497_31EE { get; } string AUTOSTAR497_31EE { get; }
string AUTOSTAR497_43EG { get;}
void Connect(string deviceId); void Connect(string deviceId);
void Disconnect(string deviceId); void Disconnect(string deviceId);
@@ -38,6 +40,7 @@ namespace ASCOM.Meade.net.Wrapper
public string AUTOSTAR497 => "Autostar"; public string AUTOSTAR497 => "Autostar";
public string AUTOSTAR497_31EE => "31Ee"; public string AUTOSTAR497_31EE => "31Ee";
public string AUTOSTAR497_43EG => "43Eg";
#endregion #endregion