Implemented the select site custom action.
This commit is contained in:
@@ -87,8 +87,9 @@ namespace Meade.net.Telescope.UnitTests
|
||||
var supportedActions = _telescope.SupportedActions;
|
||||
|
||||
Assert.That(supportedActions, Is.Not.Null);
|
||||
Assert.That(supportedActions.Count, Is.EqualTo(1));
|
||||
Assert.That(supportedActions.Count, Is.EqualTo(2));
|
||||
Assert.That(supportedActions.Contains("handbox"), Is.True);
|
||||
Assert.That(supportedActions.Contains("site"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -132,7 +133,7 @@ namespace Meade.net.Telescope.UnitTests
|
||||
[TestCase("back", ":EK87#")]
|
||||
[TestCase("forward", ":EK69#")]
|
||||
[TestCase("?", ":EK63#")]
|
||||
public void Action_Handbox_blindCommands(string action, string expectedString)
|
||||
public void Action_Handbox_WhenCalling_ThenSendsAppropriateBlindCommands(string action, string expectedString)
|
||||
{
|
||||
ConnectTelescope();
|
||||
|
||||
@@ -141,6 +142,30 @@ namespace Meade.net.Telescope.UnitTests
|
||||
_sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedString), Times.Once);
|
||||
}
|
||||
|
||||
[TestCase("1")]
|
||||
[TestCase("2")]
|
||||
[TestCase("3")]
|
||||
[TestCase("4")]
|
||||
public void Action_Site_WhenCallingWithValidValues_ThenSelectsCorrectSite(string site)
|
||||
{
|
||||
ConnectTelescope();
|
||||
|
||||
_telescope.Action("site", site);
|
||||
|
||||
_sharedResourcesWrapperMock.Verify(x => x.SendBlind($":W{site}#"), Times.Once);
|
||||
}
|
||||
|
||||
[TestCase("0")]
|
||||
[TestCase("5")]
|
||||
public void Action_Site_WhenCallingWithInCorrectValues_ThenThrowsException(string site)
|
||||
{
|
||||
ConnectTelescope();
|
||||
|
||||
var exception = Assert.Throws<InvalidValueException>(() => { _telescope.Action("site", site); });
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo($"Site {site} not allowed must be between 1 and 4"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Action_Handbox_nonExistantAction()
|
||||
{
|
||||
@@ -335,9 +360,18 @@ namespace Meade.net.Telescope.UnitTests
|
||||
_sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SelectSite_Get_WhenNotConnected_ThrowsException()
|
||||
{
|
||||
var exception = Assert.Throws<NotConnectedException>(() => { _telescope.SelectSite(1); });
|
||||
Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SelectSite"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SelectSite_WhenNewSiteToLow_ThenThrowsException()
|
||||
{
|
||||
ConnectTelescope();
|
||||
|
||||
var site = 0;
|
||||
var result = Assert.Throws<ArgumentOutOfRangeException>(() => { _telescope.SelectSite(site); });
|
||||
|
||||
@@ -347,6 +381,8 @@ namespace Meade.net.Telescope.UnitTests
|
||||
[Test]
|
||||
public void SelectSite_WhenNewSiteToHigh_ThenThrowsException()
|
||||
{
|
||||
ConnectTelescope();
|
||||
|
||||
var site = 5;
|
||||
var result = Assert.Throws<ArgumentOutOfRangeException>(() => { _telescope.SelectSite(site); });
|
||||
|
||||
@@ -359,6 +395,8 @@ namespace Meade.net.Telescope.UnitTests
|
||||
[TestCase(4)]
|
||||
public void SelectSite_WhenNewSiteToHigh_ThenThrowsException(int site)
|
||||
{
|
||||
ConnectTelescope();
|
||||
|
||||
_telescope.SelectSite(site);
|
||||
|
||||
_sharedResourcesWrapperMock.Verify(x => x.SendBlind($":W{site}#"), Times.Once);
|
||||
|
||||
@@ -157,6 +157,7 @@ namespace ASCOM.Meade.net
|
||||
LogMessage("SupportedActions Get", "Returning empty arraylist");
|
||||
var supportedActions = new ArrayList();
|
||||
supportedActions.Add("handbox");
|
||||
supportedActions.Add("site");
|
||||
return supportedActions;
|
||||
}
|
||||
}
|
||||
@@ -239,6 +240,23 @@ namespace ASCOM.Meade.net
|
||||
LogMessage("", "Action {0}, parameters {1} not implemented", actionName, actionParameters);
|
||||
throw new ActionNotImplementedException($"{actionName}({actionParameters})");
|
||||
}
|
||||
|
||||
break;
|
||||
case "site":
|
||||
switch (actionParameters.ToLower())
|
||||
{
|
||||
case "1":
|
||||
case "2":
|
||||
case "3":
|
||||
case "4":
|
||||
SelectSite(actionParameters.ToInteger());
|
||||
break;
|
||||
default:
|
||||
LogMessage("", "Action {0}, parameters {1} not implemented", actionName, actionParameters);
|
||||
throw new InvalidValueException($"Site {actionParameters} not allowed must be between 1 and 4");
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
LogMessage("", "Action {0}, parameters {1} not implemented", actionName, actionParameters);
|
||||
@@ -396,9 +414,10 @@ namespace ASCOM.Meade.net
|
||||
});
|
||||
}
|
||||
|
||||
//todo hook this up to a custom action
|
||||
public void SelectSite(int site)
|
||||
{
|
||||
CheckConnected("SelectSite");
|
||||
|
||||
if (site < 1)
|
||||
throw new ArgumentOutOfRangeException("site",site,"Site cannot be lower than 1");
|
||||
else if (site > 4)
|
||||
|
||||
Reference in New Issue
Block a user