Added more error checks for connected, and found a couple of logic holds in the code that sets the IsConnected property.

This commit is contained in:
2022-05-07 12:22:46 +01:00
parent d9093635de
commit 9866578cab
2 changed files with 7 additions and 13 deletions
@@ -221,9 +221,7 @@ namespace Meade.net.Telescope.UnitTests
{ {
string expectedResult = "test result string"; string expectedResult = "test result string";
_sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult);
_telescope.Connected = true; ConnectTelescope();
var actualResult = _telescope.Action("handbox", "readdisplay"); var actualResult = _telescope.Action("handbox", "readdisplay");
@@ -830,21 +828,17 @@ namespace Meade.net.Telescope.UnitTests
[TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, AlignmentModes.algGermanPolar, "AP")] [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, AlignmentModes.algGermanPolar, "AP")]
public void AlignmentMode_Set_WhenConnected_ThenSendsExpectedCommand(string productName, string firmware, AlignmentModes alignmentMode, string expectedCommand) public void AlignmentMode_Set_WhenConnected_ThenSendsExpectedCommand(string productName, string firmware, AlignmentModes alignmentMode, string expectedCommand)
{ {
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); ConnectTelescope(productName, firmware);
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware);
_telescope.Connected = true;
_telescope.AlignmentMode = alignmentMode; _telescope.AlignmentMode = alignmentMode;
_sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedCommand, false), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedCommand, false), Times.Once);
} }
[TestCase("AUTOSTAR", "43Ef")] [TestCase(TelescopeList.Autostar497, "43Ef")]
public void AlignmentMode_Set_WhenAutostarFirmwareToLow_ThenThrowsException(string productName, string firmware) public void AlignmentMode_Set_WhenAutostarFirmwareToLow_ThenThrowsException(string productName, string firmware)
{ {
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); ConnectTelescope(productName, firmware);
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware);
_telescope.Connected = true;
var excpetion = Assert.Throws<PropertyNotImplementedException>(() => _telescope.AlignmentMode = AlignmentModes.algAltAz); var excpetion = Assert.Throws<PropertyNotImplementedException>(() => _telescope.AlignmentMode = AlignmentModes.algAltAz);
@@ -983,9 +977,7 @@ namespace Meade.net.Telescope.UnitTests
[Test] [Test]
public void CanSetGuideRates_Get_WhenConnectedToLX200GPS_ThenReturnsTrue() public void CanSetGuideRates_Get_WhenConnectedToLX200GPS_ThenReturnsTrue()
{ {
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.LX200GPS); ConnectTelescope(TelescopeList.LX200GPS, TelescopeList.LX200GPS_42G);
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.LX200GPS_42G);
_telescope.Connected = true;
var result = _telescope.CanSetGuideRates; var result = _telescope.CanSetGuideRates;
+2
View File
@@ -508,12 +508,14 @@ namespace ASCOM.Meade.net
} }
catch (Exception) catch (Exception)
{ {
IsConnected = false;
SharedResourcesWrapper.Disconnect("Serial", DriverId); SharedResourcesWrapper.Disconnect("Serial", DriverId);
throw; throw;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
IsConnected = false;
LogMessage("Connected Set", "Error connecting to port {0} - {1}", _profileProperties.ComPort, ex.Message); LogMessage("Connected Set", "Error connecting to port {0} - {1}", _profileProperties.ComPort, ex.Message);
} }
} }