Added unit testing for bypass feature, and setting the date on first connection

This commit is contained in:
2021-04-25 18:27:44 +01:00
parent 7eec6c0008
commit c6b54e273d
3 changed files with 111 additions and 19 deletions
@@ -52,8 +52,13 @@ namespace Meade.net.Telescope.UnitTests
DataBits = 8, DataBits = 8,
GuideRateArcSecondsPerSecond = 1.23, GuideRateArcSecondsPerSecond = 1.23,
Precision = "Unchanged", Precision = "Unchanged",
GuidingStyle = "Auto" GuidingStyle = "Auto",
SendDateTime = false,
ParkedBehaviour = ParkedBehaviour.NoCoordinates,
ParkedAlt = 0,
ParkedAz = 180
}; };
_utilMock = new Mock<IUtil>(); _utilMock = new Mock<IUtil>();
@@ -400,12 +405,7 @@ namespace Meade.net.Telescope.UnitTests
[Test] [Test]
public void Connected_Set_WhenConnectingLX200GPS_Then_ConnectsToSerialDevice() public void Connected_Set_WhenConnectingLX200GPS_Then_ConnectsToSerialDevice()
{ {
var productName = TelescopeList.LX200GPS; ConnectTelescope(TelescopeList.LX200GPS, string.Empty);
var firmware = string.Empty;
_sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName);
_sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware);
_telescope.Connected = true;
_sharedResourcesWrapperMock.Verify( x => x.Connect("Serial", It.IsAny<string>(), It.IsAny<ITraceLogger>()), Times.Once); _sharedResourcesWrapperMock.Verify( x => x.Connect("Serial", It.IsAny<string>(), It.IsAny<ITraceLogger>()), Times.Once);
_sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#", true), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#", true), Times.Once);
@@ -413,6 +413,90 @@ namespace Meade.net.Telescope.UnitTests
_sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"),Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"),Times.Once);
} }
[Test]
public void Connected_WhenConnectingLX200GPSAndSendDateTimeIsTrue_Then_SpecialStartupInstructionSendOnFirstConnect()
{
_profileProperties.SendDateTime = true;
DateTime endSlewingDatetime = DateTime.ParseExact("2021-10-03T20:36:25", "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture);
_clockMock.Setup(x => x.UtcNow).Returns(() =>
{
return endSlewingDatetime;
});
string setDateCommand = $":hI{endSlewingDatetime:yyMMddHHmmss}#";
string expectedResult = "Daylight Savings Time:";
_sharedResourcesWrapperMock.Setup(x => x.SendString(":ED#", true)).Returns(expectedResult);
_sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("0");
_sharedResourcesWrapperMock.Setup(x => x.SendChar(setDateCommand)).Returns("1");
ConnectTelescope(TelescopeList.LX200GPS, string.Empty);
_sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand), Times.Once);
}
[Test]
public void Connected_WhenConnectingLX200GPSAndSendDateTimeIsTrue_Then_ByPassDisplaysWhenNotOnDaylightScreen()
{
_profileProperties.SendDateTime = true;
string telescopeTime = "20:36:25";
string telescopeDate = "10/03/21";
DateTime endSlewingDatetime = DateTime.ParseExact("2021-10-03T20:36:25", "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture);
_clockMock.Setup(x => x.UtcNow).Returns(() =>
{
return endSlewingDatetime;
});
string setDateCommand = $":hI{endSlewingDatetime:yyMMddHHmmss}#";
string expectedResult = "Align";
_sharedResourcesWrapperMock.Setup(x => x.SendString(":ED#", true)).Returns(expectedResult);
_sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("0");
_sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("1");
_sharedResourcesWrapperMock.Setup(x => x.SendChar($":SC{telescopeDate}#")).Returns("1");
ConnectTelescope(TelescopeList.LX200GPS, string.Empty);
_sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand), Times.Never);
_sharedResourcesWrapperMock.Verify(x => x.ReadTerminated(), Times.Exactly(2));
}
[Test]
public void Connected_WhenConnectingAutostarAndSendDateTimeIsTrue_Then_ByPassDisplaysWhenNotOnDaylightScreen()
{
_profileProperties.SendDateTime = true;
string telescopeTime = "20:36:25";
string telescopeDate = "10/03/21";
DateTime endSlewingDatetime = DateTime.ParseExact("2021-10-03T20:36:25", "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture);
_clockMock.Setup(x => x.UtcNow).Returns(() =>
{
return endSlewingDatetime;
});
string setDateCommand = $":hI{endSlewingDatetime:yyMMddHHmmss}#";
string expectedResult = "Align";
_sharedResourcesWrapperMock.Setup(x => x.SendString(":ED#", true)).Returns(expectedResult);
_sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("0");
_sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("1");
_sharedResourcesWrapperMock.Setup(x => x.SendChar($":SC{telescopeDate}#")).Returns("1");
ConnectTelescope();
_sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand), Times.Never);
_sharedResourcesWrapperMock.Verify(x => x.ReadTerminated(), Times.Exactly(2));
}
[Test] [Test]
public void Connected_Set_WhenConnectingToLX200EMC_Then_ConnectsToSerialDevice() public void Connected_Set_WhenConnectingToLX200EMC_Then_ConnectsToSerialDevice()
{ {
@@ -473,6 +557,7 @@ namespace Meade.net.Telescope.UnitTests
[TestCase("Auto", "Autostar", "30Ab", false)] [TestCase("Auto", "Autostar", "30Ab", false)]
[TestCase("Auto","Autostar", "31Ee", true)] [TestCase("Auto","Autostar", "31Ee", true)]
[TestCase("Auto","Autostar", "43Eg", true)] [TestCase("Auto","Autostar", "43Eg", true)]
[TestCase("Auto","Autostar", "A4S4", true)]
[TestCase("Auto","Autostar II", "", false)] [TestCase("Auto","Autostar II", "", false)]
[TestCase("Auto","LX2001", "", true)] [TestCase("Auto","LX2001", "", true)]
[TestCase("Auto",":GVP", "", false)] //LX200 Classic [TestCase("Auto",":GVP", "", false)] //LX200 Classic
+17 -11
View File
@@ -484,7 +484,7 @@ namespace ASCOM.Meade.net
{ {
if (SendDateTime) if (SendDateTime)
{ {
UTCDate = DateTime.UtcNow; UTCDate = _clock.UtcNow;
} }
} }
@@ -505,14 +505,19 @@ namespace ASCOM.Meade.net
} }
else if (SharedResourcesWrapper.ProductName == TelescopeList.Autostar497) else if (SharedResourcesWrapper.ProductName == TelescopeList.Autostar497)
{ {
var displayText = Action("Handbox", "readdisplay"); var i = 10;
if (displayText.Contains("Press 0 to Alignor MODE for Menu")) while (i > 0)
{ {
for (var i = 0; i < 4; i++) var displayText = Action("Handbox", "readdisplay");
if (displayText.Contains("Align:"))
{ {
Action("Handbox", "mode"); i = 0;
_utilities.WaitForMilliseconds(500); continue;
} }
Action("Handbox", "mode");
_utilities.WaitForMilliseconds(500);
i--;
} }
} }
} }
@@ -1764,7 +1769,7 @@ namespace ASCOM.Meade.net
double siderealTime = 0.0; double siderealTime = 0.0;
using (var novas = new NOVAS31()) using (var novas = new NOVAS31())
{ {
var jd = _utilities.DateUTCToJulian(DateTime.UtcNow); var jd = _utilities.DateUTCToJulian(_clock.UtcNow);
novas.SiderealTime(jd, 0, novas.DeltaT(jd), novas.SiderealTime(jd, 0, novas.DeltaT(jd),
GstType.GreenwichApparentSiderealTime, GstType.GreenwichApparentSiderealTime,
Method.EquinoxBased, Method.EquinoxBased,
@@ -2573,7 +2578,7 @@ namespace ASCOM.Meade.net
} }
catch (ParkedException e) catch (ParkedException e)
{ {
return DateTime.UtcNow; return _clock.UtcNow;
} }
} }
set set
@@ -2639,18 +2644,19 @@ namespace ASCOM.Meade.net
AtPark = false; AtPark = false;
} }
private void BypassHandboxEntryForAutostarII() private bool BypassHandboxEntryForAutostarII()
{ {
var utcCorrection = GetUtcCorrection(); var utcCorrection = GetUtcCorrection();
var localDateTime = DateTime.UtcNow - utcCorrection; var localDateTime = _clock.UtcNow - utcCorrection;
//localDateTime: HH: mm: ss //localDateTime: HH: mm: ss
SharedResourcesWrapper.SendBlind($":hI{localDateTime:yyMMddHHmmss}#"); var result = SharedResourcesWrapper.SendChar($":hI{localDateTime:yyMMddHHmmss}#");
//:hIYYMMDDHHMMSS# //:hIYYMMDDHHMMSS#
//Bypass handbox entry of daylight savings, date and time.Use the values supplied in this command.This feature is //Bypass handbox entry of daylight savings, date and time.Use the values supplied in this command.This feature is
//intended to allow use of the Autostar II from permanent installations where GPS reception is not possible, such as within //intended to allow use of the Autostar II from permanent installations where GPS reception is not possible, such as within
//metal domes. This command must be issued while the telescope is waiting at the initial daylight savings prompt. //metal domes. This command must be issued while the telescope is waiting at the initial daylight savings prompt.
//Returns: 1 if command was accepted. //Returns: 1 if command was accepted.
return result == "1";
} }
#endregion #endregion
+1
View File
@@ -14,6 +14,7 @@
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
public const string Autostar497_43Eg = "43Eg"; public const string Autostar497_43Eg = "43Eg";
public const string AudioStar_A4S4 = "A4S4";
#endregion #endregion
#region LX200GPS #region LX200GPS