Added more unit testing to the telescope driver.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using System.Xml.Serialization;
|
||||
using ASCOM;
|
||||
using ASCOM;
|
||||
using ASCOM.Astrometry;
|
||||
using ASCOM.Astrometry.AstroUtils;
|
||||
using ASCOM.Meade.net;
|
||||
using ASCOM.Meade.net.AstroMaths;
|
||||
@@ -32,7 +32,11 @@ namespace Meade.net.Telescope.UnitTests
|
||||
_utilMock = new Mock<IUtil>();
|
||||
_utilExtraMock = new Mock<IUtilExtra>();
|
||||
_astroUtilsMock = new Mock<IAstroUtils>();
|
||||
|
||||
_sharedResourcesWrapperMock = new Mock<ISharedResourcesWrapper>();
|
||||
_sharedResourcesWrapperMock.Setup(x => x.AUTOSTAR497).Returns(() => "AUTOSTAR497");
|
||||
_sharedResourcesWrapperMock.Setup(x => x.AUTOSTAR497_31EE).Returns(() => "31EE");
|
||||
|
||||
_sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(_profileProperties);
|
||||
|
||||
_astroMathsMock = new Mock<IAstroMaths>();
|
||||
@@ -74,9 +78,23 @@ namespace Meade.net.Telescope.UnitTests
|
||||
Assert.That(supportedActions.Contains("handbox"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Action_WhenNotConnected_ThrowsNotConnectedException()
|
||||
{
|
||||
_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.Action(string.Empty, string.Empty); });
|
||||
Assert.That(exception.Message,Is.EqualTo("Not connected to telescope when trying to execute: Action"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Action_Handbox_ReadDisplay()
|
||||
{
|
||||
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497);
|
||||
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE);
|
||||
_telescope.Connected = true;
|
||||
|
||||
string expectedResult = "test result string";
|
||||
_sharedResourcesWrapperMock.Setup(x => x.SendString(It.IsAny<string>())).Returns(expectedResult);
|
||||
|
||||
@@ -107,6 +125,9 @@ namespace Meade.net.Telescope.UnitTests
|
||||
[TestCase("?", ":EK63#")]
|
||||
public void Action_Handbox_blindCommands(string action, string expectedString)
|
||||
{
|
||||
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497);
|
||||
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE);
|
||||
_telescope.Connected = true;
|
||||
_telescope.Action("handbox", action);
|
||||
|
||||
_sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedString), Times.Once);
|
||||
@@ -115,6 +136,10 @@ namespace Meade.net.Telescope.UnitTests
|
||||
[Test]
|
||||
public void Action_Handbox_nonExistantAction()
|
||||
{
|
||||
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497);
|
||||
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE);
|
||||
_telescope.Connected = true;
|
||||
|
||||
string actionName = "handbox";
|
||||
string actionParameters = "doesnotexist";
|
||||
var exception = Assert.Throws<ActionNotImplementedException>(() => { _telescope.Action(actionName, actionParameters); });
|
||||
@@ -125,10 +150,87 @@ namespace Meade.net.Telescope.UnitTests
|
||||
[Test]
|
||||
public void Action_nonExistantAction()
|
||||
{
|
||||
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497);
|
||||
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE);
|
||||
_telescope.Connected = true;
|
||||
|
||||
string actionName = "doesnotexist";
|
||||
var exception = Assert.Throws<ActionNotImplementedException>(() => { _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."));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CommandBlind_WhenNotConnected_ThenThrowsNotConnectedException()
|
||||
{
|
||||
string expectedMessage = "test blind Message";
|
||||
var exception = Assert.Throws<NotConnectedException>(() => { _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()
|
||||
{
|
||||
string expectedMessage = "test blind Message";
|
||||
|
||||
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns( () => _sharedResourcesWrapperMock.Object.AUTOSTAR497);
|
||||
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE);
|
||||
_telescope.Connected = true;
|
||||
|
||||
_telescope.CommandBlind(expectedMessage, true);
|
||||
|
||||
_sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedMessage), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CommandBool_WhenNotConnected_ThenThrowsNotConnectedException()
|
||||
{
|
||||
string expectedMessage = "test blind Message";
|
||||
var exception = Assert.Throws<NotConnectedException>(() => { _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()
|
||||
{
|
||||
string expectedMessage = "test blind Message";
|
||||
|
||||
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497);
|
||||
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE);
|
||||
_telescope.Connected = true;
|
||||
|
||||
var exception = Assert.Throws<MethodNotImplementedException>(() => { _telescope.CommandBool(expectedMessage, true); });
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo("Method CommandBool is not implemented in this driver."));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CommandString_WhenNotConnected_ThenThrowsNotConnectedException()
|
||||
{
|
||||
string expectedMessage = "test blind Message";
|
||||
var exception = Assert.Throws<NotConnectedException>(() => { _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()
|
||||
{
|
||||
string expectedMessage = "expected result message";
|
||||
string sendMessage = "test blind Message";
|
||||
|
||||
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497);
|
||||
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE);
|
||||
_telescope.Connected = true;
|
||||
|
||||
_sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage)).Returns(() => expectedMessage);
|
||||
|
||||
var actualMessage = _telescope.CommandString(sendMessage, true);
|
||||
|
||||
_sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage), Times.Once);
|
||||
Assert.That(actualMessage, Is.EqualTo(expectedMessage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user