diff --git a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs index a898637..e5699dc 100644 --- a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs +++ b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs @@ -15,6 +15,7 @@ namespace Meade.net.Focuser.UnitTests { private Mock _utilMock; private Mock _sharedResourcesWrapperMock; + private Mock _traceLoggerMock; private ProfileProperties _profileProperties; @@ -40,11 +41,13 @@ namespace Meade.net.Focuser.UnitTests _utilMock = new Mock(); + _traceLoggerMock = new Mock(); + _sharedResourcesWrapperMock = new Mock(); _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(() => _profileProperties); - _focuser = new ASCOM.Meade.net.Focuser(_utilMock.Object, _sharedResourcesWrapperMock.Object); + _focuser = new ASCOM.Meade.net.Focuser(_utilMock.Object, _sharedResourcesWrapperMock.Object, _traceLoggerMock.Object); } private void ConnectFocuser() @@ -117,7 +120,7 @@ namespace Meade.net.Focuser.UnitTests _focuser.CommandBlind(expectedMessage, raw); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedMessage, raw), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, expectedMessage, raw), Times.Once); } [Test] @@ -134,13 +137,13 @@ namespace Meade.net.Focuser.UnitTests public void CommandBool_WhenConnected_ThenSendsExpectedMessage(bool raw) { string expectedMessage = "test blind Message"; - _sharedResourcesWrapperMock.Setup(x => x.SendBool(expectedMessage, raw)).Returns(true); + _sharedResourcesWrapperMock.Setup(x => x.SendBool(_traceLoggerMock.Object, expectedMessage, raw)).Returns(true); ConnectFocuser(); var result = _focuser.CommandBool(expectedMessage, raw); - _sharedResourcesWrapperMock.Verify(x => x.SendBool(expectedMessage, raw), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBool(_traceLoggerMock.Object, expectedMessage, raw), Times.Once); Assert.That(result, Is.True); } @@ -161,11 +164,11 @@ namespace Meade.net.Focuser.UnitTests ConnectFocuser(); - _sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage, true)).Returns(() => expectedMessage); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, sendMessage, true)).Returns(() => expectedMessage); var actualMessage = _focuser.CommandString(sendMessage, true); - _sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage, true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, sendMessage, true), Times.Once); Assert.That(actualMessage, Is.EqualTo(expectedMessage)); } @@ -321,7 +324,7 @@ namespace Meade.net.Focuser.UnitTests _focuser.Halt(); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("FQ", false), Times.AtLeastOnce); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "FQ", false), Times.AtLeastOnce); } [Test] @@ -411,13 +414,13 @@ namespace Meade.net.Focuser.UnitTests if (position < 0) { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F-", false), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "F-", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "F+", false), Times.Never); } else { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F-", false), Times.Never); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "F-", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "F+", false), Times.Once); } _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once); @@ -437,16 +440,16 @@ namespace Meade.net.Focuser.UnitTests if (position < 0) { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F-", false), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "F-", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "F+", false), Times.Never); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(_profileProperties.BacklashCompensation)), Times.Never); _utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Exactly(1)); } else { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F-", false), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "F-", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "F+", false), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position) + _profileProperties.BacklashCompensation), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(_profileProperties.BacklashCompensation), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Exactly(2)); diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index f1fabbe..6c7565f 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -48,6 +48,7 @@ namespace Meade.net.Telescope.UnitTests private Mock _astroMathsMock; private Mock _clockMock; private Mock _novasMock; + private Mock _traceLoggerMock; private ProfileProperties _profileProperties; private ConnectionInfo _connectionInfo; @@ -92,9 +93,10 @@ namespace Meade.net.Telescope.UnitTests _utilMock = new Mock(); _utilExtraMock = new Mock(); _astroUtilsMock = new Mock(); + _traceLoggerMock = new Mock(); _sharedResourcesWrapperMock = new Mock(); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MM’SS"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GZ", false)).Returns("DDD*MM’SS"); _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(() =>_profileProperties); @@ -121,32 +123,32 @@ namespace Meade.net.Telescope.UnitTests _novasMock = new Mock(); _telescope = new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, - _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object); + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object, _traceLoggerMock.Object); } private void ConnectTelescope(string productName = TelescopeList.Autostar497, string firmwareVersion = TelescopeList.Autostar497_31Ee, string alignmentStatus = "GT0") { _testProperties.AlignmentStatus = alignmentStatus.ToCharArray(); - _sharedResourcesWrapperMock.Setup(x => x.SendChars("GW", false, 3)).Returns(() => new string(_testProperties.AlignmentStatus)); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GW", false)).Returns(() => new string(_testProperties.AlignmentStatus)); - _sharedResourcesWrapperMock.Setup(x => x.SendBlind("AP", false)).Callback(() => _testProperties.AlignmentStatus[1] = 'T'); - _sharedResourcesWrapperMock.Setup(x => x.SendBlind("AL", false)).Callback(() => _testProperties.AlignmentStatus[1] = 'N'); + _sharedResourcesWrapperMock.Setup(x => x.SendChars(_traceLoggerMock.Object, "GW", false, 3)).Returns(() => new string(_testProperties.AlignmentStatus)); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GW", false)).Returns(() => new string(_testProperties.AlignmentStatus)); + _sharedResourcesWrapperMock.Setup(x => x.SendBlind(_traceLoggerMock.Object, "AP", false)).Callback(() => _testProperties.AlignmentStatus[1] = 'T'); + _sharedResourcesWrapperMock.Setup(x => x.SendBlind(_traceLoggerMock.Object, "AL", false)).Callback(() => _testProperties.AlignmentStatus[1] = 'N'); - _sharedResourcesWrapperMock.Setup(x => x.SendString("Gt", false)).Returns( () => _testProperties.SiteLatitudeString); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "Gt", false)).Returns( () => _testProperties.SiteLatitudeString); _utilMock.Setup(x => x.DMSToDegrees(_testProperties.SiteLatitudeString)).Returns( () => _testProperties.SiteLatitudeValue); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GR", false)).Returns( () =>_testProperties.telescopeRaResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GR", false)).Returns( () =>_testProperties.telescopeRaResult); _utilMock.Setup(x => x.HMSToHours(_testProperties.telescopeRaResult)).Returns( () => _testProperties.rightAscension); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GC", false)).Returns(() => _testProperties.telescopeDate); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GL", false)).Returns(() => _testProperties.telescopeTime); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns(() => _testProperties.telescopeUtcCorrection); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GC", false)).Returns(() => _testProperties.telescopeDate); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GL", false)).Returns(() => _testProperties.telescopeTime); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GG", false)).Returns(() => _testProperties.telescopeUtcCorrection); _testProperties.TrackingRate = _siderealTrackingRate; - _sharedResourcesWrapperMock.Setup(x => x.SendString("GT", false)).Returns(() => _testProperties.TrackingRate); - _sharedResourcesWrapperMock.Setup(x => x.SendBlind("TL", false)).Callback(() => _testProperties.TrackingRate = "57.9"); - _sharedResourcesWrapperMock.Setup(x => x.SendBlind("TQ", false)).Callback(() => _testProperties.TrackingRate = _siderealTrackingRate); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GT", false)).Returns(() => _testProperties.TrackingRate); + _sharedResourcesWrapperMock.Setup(x => x.SendBlind(_traceLoggerMock.Object, "TL", false)).Callback(() => _testProperties.TrackingRate = "57.9"); + _sharedResourcesWrapperMock.Setup(x => x.SendBlind(_traceLoggerMock.Object, "TQ", false)).Callback(() => _testProperties.TrackingRate = _siderealTrackingRate); _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => productName); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => firmwareVersion); @@ -158,7 +160,7 @@ namespace Meade.net.Telescope.UnitTests }); const char ack = (char)6; - _sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString(), false)).Returns( () => _testProperties.AlignmentMode); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, ack.ToString(), false)).Returns( () => _testProperties.AlignmentMode); _sharedResourcesWrapperMock.SetupGet(x => x.IsParked).Returns(() => _isParked); _sharedResourcesWrapperMock.SetupGet(x => x.ParkedPosition).Returns(() => _parkedPosition); @@ -221,12 +223,12 @@ namespace Meade.net.Telescope.UnitTests public void Action_Handbox_ReadDisplay() { string expectedResult = "test result string"; - _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "ED", false)).Returns(expectedResult); ConnectTelescope(); var actualResult = _telescope.Action("handbox", "readdisplay"); - _sharedResourcesWrapperMock.Verify(x => x.SendString("ED", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "ED", false), Times.Once); Assert.That(actualResult, Is.EqualTo(expectedResult)); } @@ -261,7 +263,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.Action("handbox", action); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedString, false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, expectedString, false), Times.Once); } [TestCase("1")] @@ -275,7 +277,7 @@ namespace Meade.net.Telescope.UnitTests string parameters = $"select {site}"; _telescope.Action("site", parameters); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"W{site}", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, $"W{site}", false), Times.Once); } [TestCase("0")] @@ -296,14 +298,14 @@ namespace Meade.net.Telescope.UnitTests [TestCase("4", "GP", "Parents")] public void Action_Site_GetName_WhenCallingWithValidValues_ThenSelectsCorrectSite(string site, string telescopeCommand, string siteName) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(telescopeCommand, false)).Returns(siteName); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, telescopeCommand, false)).Returns(siteName); ConnectTelescope(); string parameters = $"GetName {site}"; var result = _telescope.Action("site", parameters); - _sharedResourcesWrapperMock.Verify(x => x.SendString(telescopeCommand, false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, telescopeCommand, false), Times.Once); Assert.That(result, Is.EqualTo(siteName)); } @@ -337,14 +339,14 @@ namespace Meade.net.Telescope.UnitTests public void Action_Site_SetName_WhenCallingWithValidValues_ThenSelectsCorrectSite(string site, string telescopeCommand, string siteName) { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(telescopeCommand, false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, telescopeCommand, false)).Returns("1"); ConnectTelescope(); string parameters = $"SetName {site} {siteName}"; _telescope.Action("site", parameters); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(telescopeCommand, false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, telescopeCommand, false), Times.Once); } [TestCase("0")] @@ -412,7 +414,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.CommandBlind(expectedMessage, raw); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedMessage, raw), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, expectedMessage, raw), Times.Once); } [Test] @@ -430,13 +432,13 @@ namespace Meade.net.Telescope.UnitTests public void CommandBool_WhenConnected_ThenSendsExpectedMessage(bool raw) { string expectedMessage = "test blind Message"; - _sharedResourcesWrapperMock.Setup(x => x.SendBool(expectedMessage, raw)).Returns(true); + _sharedResourcesWrapperMock.Setup(x => x.SendBool(_traceLoggerMock.Object, expectedMessage, raw)).Returns(true); ConnectTelescope(); var result = _telescope.CommandBool(expectedMessage, raw); - _sharedResourcesWrapperMock.Verify(x => x.SendBool(expectedMessage, raw), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBool(_traceLoggerMock.Object, expectedMessage, raw), Times.Once); Assert.That(result, Is.True); } @@ -456,13 +458,13 @@ namespace Meade.net.Telescope.UnitTests string expectedMessage = "expected result message"; string sendMessage = "test blind Message"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage, raw)).Returns(() => expectedMessage); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, sendMessage, raw)).Returns(() => expectedMessage); ConnectTelescope(); var actualMessage = _telescope.CommandString(sendMessage, raw); - _sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage, raw), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, sendMessage, raw), Times.Once); Assert.That(actualMessage, Is.EqualTo(expectedMessage)); } @@ -480,8 +482,8 @@ namespace Meade.net.Telescope.UnitTests if (expectedConnected) { - _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.AtLeastOnce); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "GZ", false), Times.AtLeastOnce); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, $"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Never); } } @@ -491,9 +493,9 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(TelescopeList.LX200GPS, string.Empty); _sharedResourcesWrapperMock.Verify(x => x.Connect("Serial", It.IsAny(), It.IsAny()), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.AtLeastOnce); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "GZ", false), Times.AtLeastOnce); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, $"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Once); } [Test] @@ -508,12 +510,12 @@ namespace Meade.net.Telescope.UnitTests string setDateCommand = $"hI{testNow:yyMMddHHmmss}"; string expectedResult = "Daylight Savings Time:"; - _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(setDateCommand, false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "ED", false)).Returns(expectedResult); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, setDateCommand, false)).Returns("1"); ConnectTelescope(TelescopeList.LX200GPS, string.Empty); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand, false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, setDateCommand, false), Times.Once); } [Test] @@ -531,14 +533,14 @@ namespace Meade.net.Telescope.UnitTests string setDateCommand = $"hI{endSlewingDatetime:yyMMddHHmmss}"; string expectedResult = "Align"; - _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "ED", false)).Returns(expectedResult); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{telescopeDate}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, $"SL{telescopeTime}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, $"SC{telescopeDate}", false)).Returns("1"); ConnectTelescope(TelescopeList.LX200GPS, string.Empty); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand, false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, setDateCommand, false), Times.Never); _sharedResourcesWrapperMock.Verify(x => x.ReadTerminated(), Times.Exactly(2)); } @@ -560,15 +562,15 @@ namespace Meade.net.Telescope.UnitTests string setDateCommand = $"hI{endSlewingDatetime:yyMMddHHmmss}"; string expectedResult = "Align"; - _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "ED", false)).Returns(expectedResult); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{telescopeDate}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, $"SL{telescopeTime}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, $"SC{telescopeDate}", false)).Returns("1"); ConnectTelescope(); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand, false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, setDateCommand, false), Times.Never); _sharedResourcesWrapperMock.Verify(x => x.ReadTerminated(), Times.Exactly(2)); } @@ -583,8 +585,8 @@ namespace Meade.net.Telescope.UnitTests _telescope.Connected = true; _sharedResourcesWrapperMock.Verify(x => x.Connect("Serial", It.IsAny(), It.IsAny()), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.Never); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "GZ", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, $"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Never); } @@ -620,7 +622,7 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_31Ee); - _sharedResourcesWrapperMock.Setup(x => x.SendString(It.IsAny(), It.IsAny())).Throws(new Exception("TestFailed")); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, It.IsAny(), It.IsAny())).Throws(new Exception("TestFailed")); //act _telescope.Connected = true; @@ -654,37 +656,37 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SetLongFormatFalse_WhenTelescopeReturnsShortFormat_ThenDoesNothing() { - _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MM"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GZ", false)).Returns("DDD*MM"); _telescope.SetLongFormat(false); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("U", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "U", false), Times.Never); } [Test] public void SetLongFormatFalse_WhenTelescopeReturnsLongFormat_ThenTogglesPrecision() { - _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MM’SS"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GZ", false)).Returns("DDD*MM’SS"); _telescope.SetLongFormat(false); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("U", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "U", false), Times.Once); } [Test] public void SetLongFormatTrue_WhenTelescopeReturnsLongFormat_ThenDoesNothing() { - _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MM’SS"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GZ", false)).Returns("DDD*MM’SS"); _telescope.SetLongFormat(true); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("U", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "U", false), Times.Never); } [Test] public void SetLongFormatTrue_WhenTelescopeReturnsShortFormat_ThenTogglesPrecision() { - _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MM"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GZ", false)).Returns("DDD*MM"); _telescope.SetLongFormat(true); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("U", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "U", false), Times.Once); } [Test] @@ -726,7 +728,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.SelectSite(site); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"W{site}", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, $"W{site}", false), Times.Once); } [Test] @@ -837,7 +839,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.AlignmentMode = alignmentMode; - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedCommand, false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, expectedCommand, false), Times.Once); } [Test] @@ -982,7 +984,7 @@ namespace Meade.net.Telescope.UnitTests { _telescope.Connected = true; - _sharedResourcesWrapperMock.Verify(x => x.SendString("P", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "P", false), Times.Never); } [TestCase("High", false, true)] @@ -994,7 +996,7 @@ namespace Meade.net.Telescope.UnitTests _profileProperties.Precision = desiredPresision; var currentPrecision = telescopePrecision; - _sharedResourcesWrapperMock.Setup(x => x.SendChar("P", false)).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, "P", false)).Returns(() => { currentPrecision = !currentPrecision; @@ -1010,7 +1012,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); Assert.That(currentPrecision, Is.EqualTo(finalPrecision)); - _sharedResourcesWrapperMock.Verify(x => x.SendChar("P", false), Times.AtLeastOnce); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, "P", false), Times.AtLeastOnce); } [TestCase("High")] @@ -1022,7 +1024,7 @@ namespace Meade.net.Telescope.UnitTests ? false : throw new ArgumentOutOfRangeException(nameof(desiredPresision), desiredPresision, "Should be High or Low")); _sharedResourcesWrapperMock.SetupProperty(x => x.IsLongFormat, isLongFormat); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GR", false)).Returns(() => _testProperties.telescopeRaResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GR", false)).Returns(() => _testProperties.telescopeRaResult); _utilMock.Setup(x => x.HMSToHours(_testProperties.telescopeRaResult)).Returns(() => _testProperties.rightAscension); _profileProperties.Precision = desiredPresision; @@ -1031,7 +1033,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); - _sharedResourcesWrapperMock.Verify(x => x.SendChar("P", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, "P", false), Times.Never); _sharedResourcesWrapperMock.Verify(x => x.IsLongFormat, Times.Once); } @@ -1053,7 +1055,7 @@ namespace Meade.net.Telescope.UnitTests var secondTelescopeInstance = new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, - _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object); + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object, _traceLoggerMock.Object); Assert.That(secondTelescopeInstance.Connected, Is.False); @@ -1082,7 +1084,7 @@ namespace Meade.net.Telescope.UnitTests var secondTelescopeInstance = new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, - _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object); + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object, _traceLoggerMock.Object); Assert.That(secondTelescopeInstance.Connected, Is.False); @@ -1241,7 +1243,7 @@ namespace Meade.net.Telescope.UnitTests public void Declination_Get_WhenConnected_ThenReadsValueFromScope(string declincationString) { var expectedResult = 12.34; - _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(declincationString); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GD", false)).Returns(declincationString); _utilMock.Setup(x => x.DMSToDegrees(declincationString)).Returns(expectedResult); ConnectTelescope(); @@ -1256,14 +1258,14 @@ namespace Meade.net.Telescope.UnitTests var telescopeDecResult = "s12*34’56"; var dmsResult = 1.2; - _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GD", false)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); ConnectTelescope(); var result = _telescope.Declination; - _sharedResourcesWrapperMock.Verify(x => x.SendString("GD", false), Times.Exactly(2)); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "GD", false), Times.Exactly(2)); _utilMock.Verify(x => x.DMSToDegrees(telescopeDecResult), Times.Exactly(2)); Assert.That(result, Is.EqualTo(dmsResult)); @@ -1448,7 +1450,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.GuideRateDeclination = newGuideRate; - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Rg01.2", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "Rg01.2", false), Times.Once); Assert.That(_telescope.GuideRateDeclination, Is.EqualTo(newGuideRate)); } @@ -1481,7 +1483,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.GuideRateRightAscension = newGuideRate; - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Rg01.2", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "Rg01.2", false), Times.Once); Assert.That(_telescope.GuideRateDeclination, Is.EqualTo(newGuideRate)); } @@ -1527,13 +1529,13 @@ namespace Meade.net.Telescope.UnitTests _telescope.MoveAxis(axis, rate); if (slewRateCommand != string.Empty) - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(slewRateCommand, false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, slewRateCommand, false), Times.Once); else { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RG", false), Times.Never); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RC", false), Times.Never); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RM", false), Times.Never); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RS", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "RG", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "RC", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "RM", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "RS", false), Times.Never); } switch (axis) @@ -1542,14 +1544,14 @@ namespace Meade.net.Telescope.UnitTests switch (rate.Compare(0)) { case ComparisonResult.Equals: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Qe", false), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Qw", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "Qe", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "Qw", false), Times.Once); break; case ComparisonResult.Greater: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Me", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "Me", false), Times.Once); break; case ComparisonResult.Lower: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Mw", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "Mw", false), Times.Once); break; } break; @@ -1557,14 +1559,14 @@ namespace Meade.net.Telescope.UnitTests switch (rate.Compare(0)) { case ComparisonResult.Equals: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Qn", false), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Qs", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "Qn", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "Qs", false), Times.Once); break; case ComparisonResult.Greater: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Mn", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "Mn", false), Times.Once); break; case ComparisonResult.Lower: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Ms", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "Ms", false), Times.Once); break; } break; @@ -1610,11 +1612,11 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); Assert.That(_telescope.AtPark, Is.False); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("hP", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "hP", false), Times.Never); _telescope.Park(); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("hP", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "hP", false), Times.Once); Assert.That(_telescope.AtPark, Is.True); } @@ -1629,8 +1631,8 @@ namespace Meade.net.Telescope.UnitTests var azAsDM = "180*00"; _utilMock.Setup(x => x.DegreesToDM(az, "*", "", 2)).Returns(azAsDM); - _sharedResourcesWrapperMock.Setup(x => x.SendBool("Sa+77*30", false)).Returns(true); - _sharedResourcesWrapperMock.Setup(x => x.SendBool("Sz180*00", false)).Returns(true); + _sharedResourcesWrapperMock.Setup(x => x.SendBool(_traceLoggerMock.Object, "Sa+77*30", false)).Returns(true); + _sharedResourcesWrapperMock.Setup(x => x.SendBool(_traceLoggerMock.Object, "Sz180*00", false)).Returns(true); ConnectTelescope(TelescopeList.LX200CLASSIC); Assert.That(_telescope.AtPark, Is.False); @@ -1647,7 +1649,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.Park(); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("hP", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "hP", false), Times.Once); Assert.That(_telescope.AtPark, Is.True); @@ -1655,7 +1657,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.Park(); //no change from previous state. - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("hP", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "hP", false), Times.Once); Assert.That(_telescope.AtPark, Is.True); } @@ -1697,7 +1699,7 @@ namespace Meade.net.Telescope.UnitTests break; } - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Mg{d}{duration:0000}", false)); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, $"Mg{d}{duration:0000}", false)); _utilMock.Verify(x => x.WaitForMilliseconds(duration), Times.Once); } @@ -1748,7 +1750,7 @@ namespace Meade.net.Telescope.UnitTests break; } - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Mg{d}{duration:0000}", false)); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, $"Mg{d}{duration:0000}", false)); _utilMock.Verify(x => x.WaitForMilliseconds(duration), Times.Once); } @@ -1758,7 +1760,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth)] public void PulseGuide_WhenSlewingAndPulseGuideAttempted_ThenThrowsExpectedException(GuideDirections direction) { - _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns("|"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "D", false)).Returns("|"); var duration = 0; ConnectTelescope(); @@ -1775,7 +1777,7 @@ namespace Meade.net.Telescope.UnitTests public void PulseGuide_WhenAltAzPulseGuideAttempted_ThenThrowsExpectedException(GuideDirections direction) { _testProperties.AlignmentMode = "A"; - _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(""); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "D", false)).Returns(""); var duration = 1; ConnectTelescope(); @@ -1794,7 +1796,7 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.SetupProperty(x => x.MovingPrimary); _sharedResourcesWrapperMock.SetupProperty(x => x.MovingSecondary); _sharedResourcesWrapperMock.SetupProperty(x => x.EarliestNonSlewingTime, DateTime.MinValue); - _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(""); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "D", false)).Returns(""); var duration = 0; ConnectTelescope(); @@ -1819,7 +1821,7 @@ namespace Meade.net.Telescope.UnitTests _testProperties.rightAscension = 1.3; - _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GD", false)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); var duration = 0; @@ -1849,7 +1851,7 @@ namespace Meade.net.Telescope.UnitTests var dmsResult = 1.2; var duration = 0; - _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GD", false)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); ConnectTelescope(TelescopeList.Autostar497, TelescopeList.Autostar497_30Ee); @@ -1873,10 +1875,10 @@ namespace Meade.net.Telescope.UnitTests break; } - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RG", false)); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"M{d}", false)); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "RG", false)); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, $"M{d}", false)); _utilMock.Verify(x => x.WaitForMilliseconds(duration), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Q{d}", false)); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, $"Q{d}", false)); } [TestCase(GuideDirections.guideEast)] @@ -1892,7 +1894,7 @@ namespace Meade.net.Telescope.UnitTests var telescopeDecResult = "s12*34’56"; var dmsResult = 1.2; - _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GD", false)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); ConnectTelescope(TelescopeList.Autostar497, TelescopeList.Autostar497_30Ee); @@ -1947,10 +1949,10 @@ namespace Meade.net.Telescope.UnitTests break; } - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RG", false)); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"M{d}", false)); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "RG", false)); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, $"M{d}", false)); _utilMock.Verify(x => x.WaitForMilliseconds(duration), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Q{d}", false)); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, $"Q{d}", false)); } [Test] @@ -2180,7 +2182,7 @@ namespace Meade.net.Telescope.UnitTests var result = _telescope.SiteLatitude; - _sharedResourcesWrapperMock.Verify(x => x.SendString("Gt", false), Times.AtLeastOnce); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "Gt", false), Times.AtLeastOnce); Assert.That(result, Is.EqualTo(_testProperties.SiteLatitudeValue)); } @@ -2214,7 +2216,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase(20.75)] public void SiteLatitude_Set_WhenValueSetAndTelescopRejects_ThenExceptionThrown(double siteLatitude) { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny(), false)).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, It.IsAny(), false)).Returns("0"); ConnectTelescope(); @@ -2227,13 +2229,13 @@ namespace Meade.net.Telescope.UnitTests [TestCase(20.75, "St+20*45")] public void SiteLatitude_Set_WhenValidValues_ThenValueSentToTelescope(double siteLatitude, string expectedCommand) { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(expectedCommand, false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, expectedCommand, false)).Returns("1"); ConnectTelescope(); _telescope.SiteLatitude = siteLatitude; - _sharedResourcesWrapperMock.Verify(x => x.SendChar(expectedCommand, false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, expectedCommand, false), Times.Once); } [Test] @@ -2256,7 +2258,7 @@ namespace Meade.net.Telescope.UnitTests { var telescopeLongitude = "testLongitude"; - _sharedResourcesWrapperMock.Setup(x => x.SendString("Gg", false)).Returns(telescopeLongitude); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "Gg", false)).Returns(telescopeLongitude); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); ConnectTelescope(); @@ -2294,7 +2296,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SiteLongitude_Set_WhenConnectedAndTelescopeFails_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny(), false)).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, It.IsAny(), false)).Returns("0"); ConnectTelescope(); @@ -2306,13 +2308,13 @@ namespace Meade.net.Telescope.UnitTests [TestCase(10, "Sg350*00")] public void SiteLongitude_Set_WhenConnectedAndTelescopeFails_ThenThrowsException(double longitude, string expectedCommand) { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(expectedCommand, false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, expectedCommand, false)).Returns("1"); ConnectTelescope(); _telescope.SiteLongitude = longitude; - _sharedResourcesWrapperMock.Verify(x => x.SendChar(expectedCommand, false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, expectedCommand, false), Times.Once); } [Test] @@ -2335,26 +2337,26 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SyncToTarget_WhenSyncToTargetFails_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendString("CM", false)).Returns(string.Empty); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "CM", false)).Returns(string.Empty); ConnectTelescope(); var exception = Assert.Throws(() => _telescope.SyncToTarget()); Assert.That(exception.Message, Is.EqualTo("Unable to perform sync")); - _sharedResourcesWrapperMock.Verify(x => x.SendString("CM", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "CM", false), Times.Once); } [Test] public void SyncToTarget_WhenSyncToTargetWorks_ThennoExceptionThrown() { - _sharedResourcesWrapperMock.Setup(x => x.SendString("CM", false)).Returns(" M31 EX GAL MAG 3.5 SZ178.0'#"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "CM", false)).Returns(" M31 EX GAL MAG 3.5 SZ178.0'#"); ConnectTelescope(); Assert.DoesNotThrow(() => _telescope.SyncToTarget()); - _sharedResourcesWrapperMock.Verify(x => x.SendString("CM", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "CM", false), Times.Once); } [Test] @@ -2385,7 +2387,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void TargetDeclination_Set_WhenTelescopeReportsInvalidDec_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny(), false)).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, It.IsAny(), false)).Returns("0"); ConnectTelescope(); @@ -2401,13 +2403,13 @@ namespace Meade.net.Telescope.UnitTests { _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(decstring); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString, false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, commandString, false)).Returns("1"); ConnectTelescope(); _telescope.TargetDeclination = declination; - _sharedResourcesWrapperMock.Verify(x => x.SendChar(commandString, false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, commandString, false), Times.Once); } [Test] @@ -2433,7 +2435,7 @@ namespace Meade.net.Telescope.UnitTests _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(decstring); _utilMock.Setup(x => x.DMSToDegrees(decstring)).Returns(declination); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString, false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, commandString, false)).Returns("1"); ConnectTelescope(); @@ -2457,7 +2459,7 @@ namespace Meade.net.Telescope.UnitTests _utilMock.Setup(x => x.DegreesToDMS(targetDeclination, "*", ":", ":", 2)).Returns(targetDeclinationDMS); _utilMock.Setup(x => x.DMSToDegrees(targetDeclinationDMS)).Returns(targetDeclination); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(command, false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, command, false)).Returns("1"); ConnectTelescope(); Assert.That(_connectionInfo.SameDevice, Is.EqualTo(1)); @@ -2469,7 +2471,7 @@ namespace Meade.net.Telescope.UnitTests var secondTelescopeInstance = new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, - _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object); + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object, _traceLoggerMock.Object); Assert.That(secondTelescopeInstance.Connected, Is.False); @@ -2481,7 +2483,7 @@ namespace Meade.net.Telescope.UnitTests _utilMock.Verify(x => x.DegreesToDMS(targetDeclination, "*", ":", ":", 2), Times.Once); _utilMock.Verify(x => x.DMSToDegrees(targetDeclinationDMS), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(command, false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, command, false), Times.Once); } [Test] @@ -2512,7 +2514,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void TargetRightAscension_Set_WhenTelescopeReportsInvalidRA_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny(), false)).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, It.IsAny(), false)).Returns("0"); ConnectTelescope(); @@ -2525,13 +2527,13 @@ namespace Meade.net.Telescope.UnitTests public void TargetRightAscension_Set_WhenValueOK_ThenSetsNewTargetDeclination(double rightAscension, string hms, string commandString) { _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(hms); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString, false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, commandString, false)).Returns("1"); ConnectTelescope(); _telescope.TargetRightAscension = rightAscension; - _sharedResourcesWrapperMock.Verify(x => x.SendChar(commandString, false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, commandString, false), Times.Once); } [Test] @@ -2555,7 +2557,7 @@ namespace Meade.net.Telescope.UnitTests _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", digitsRA)).Returns(hms); _utilMock.Setup(x => x.HMSToHours(hms)).Returns(rightAscension); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString, false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, commandString, false)).Returns("1"); ConnectTelescope(); @@ -2577,7 +2579,7 @@ namespace Meade.net.Telescope.UnitTests _utilMock.Setup(x => x.HoursToHMS(targetRightAscension, ":", ":", ":", 2)).Returns(targetRightAscensionHMS); _utilMock.Setup(x => x.HMSToHours(targetRightAscensionHMS)).Returns(targetRightAscension); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(command, false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, command, false)).Returns("1"); ConnectTelescope(); Assert.That(_connectionInfo.SameDevice, Is.EqualTo(1)); @@ -2589,7 +2591,7 @@ namespace Meade.net.Telescope.UnitTests var secondTelescopeInstance = new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, - _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object); + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object, _traceLoggerMock.Object); Assert.That(secondTelescopeInstance.Connected, Is.False); @@ -2601,7 +2603,7 @@ namespace Meade.net.Telescope.UnitTests _utilMock.Verify(x => x.HoursToHMS(targetRightAscension, ":", ":", ":", 2), Times.Once); _utilMock.Verify(x => x.HMSToHours(targetRightAscensionHMS), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(command, false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, command, false), Times.Once); } [TestCase("A", true)] @@ -2625,7 +2627,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(_telescope.Tracking, Is.EqualTo(tracking)); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(alignmentCommand, false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, alignmentCommand, false), Times.Once); } [Test] @@ -2648,8 +2650,8 @@ namespace Meade.net.Telescope.UnitTests Assert.That(_telescope.TrackingRate, Is.EqualTo(rate)); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(commandString, false), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendString("GT", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, commandString, false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "GT", false), Times.Once); } [Test] @@ -2788,8 +2790,8 @@ namespace Meade.net.Telescope.UnitTests var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns(telescopeUtcCorrection); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GG", false)).Returns(telescopeUtcCorrection); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, $"SL{telescopeTime}", false)).Returns("0"); ConnectTelescope(); @@ -2808,8 +2810,8 @@ namespace Meade.net.Telescope.UnitTests var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{newDate:MM/dd/yy}", false)).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, $"SL{telescopeTime}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, $"SC{newDate:MM/dd/yy}", false)).Returns("0"); ConnectTelescope(); @@ -2831,8 +2833,8 @@ namespace Meade.net.Telescope.UnitTests var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{telescopeDate}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, $"SL{telescopeTime}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, $"SC{telescopeDate}", false)).Returns("1"); ConnectTelescope(); @@ -2868,7 +2870,7 @@ namespace Meade.net.Telescope.UnitTests var digitsRA = 2; - _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sr{_testProperties.telescopeRaResult}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, $"Sr{_testProperties.telescopeRaResult}", false)).Returns("1"); _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.HMSToHours(hms)).Returns(_testProperties.rightAscension); @@ -2879,18 +2881,18 @@ namespace Meade.net.Telescope.UnitTests _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", 2)).Returns(hms); _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(dec); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sr{hms}", false)).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sd{dec}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, $"Sr{hms}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, $"Sd{dec}", false)).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendString($"CM", false)).Returns("M31 EX GAL MAG 3.5 SZ178.0'#"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, $"CM", false)).Returns("M31 EX GAL MAG 3.5 SZ178.0'#"); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GD", false)).Returns(telescopeDecResult); ConnectTelescope(); _telescope.SyncToCoordinates(_testProperties.rightAscension, declination); - _sharedResourcesWrapperMock.Verify(x => x.SendString("CM", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "CM", false), Times.Once); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); } @@ -2902,7 +2904,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.False); - _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "D", false), Times.Never); } [Test] @@ -2914,13 +2916,13 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.False); - _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "D", false), Times.Once); } [Test] public void Slewing_WhenTelescopeIsSlewing_ThenReturnsTrue() { - _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns("|"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "D", false)).Returns("|"); ConnectTelescope(); @@ -2928,7 +2930,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.True); - _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "D", false), Times.Once); } [TestCase(0, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:01", false)] @@ -2967,7 +2969,7 @@ namespace Meade.net.Telescope.UnitTests var slewingText = "|"; var notSlewingText = String.Empty; - _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "D", false)).Returns(() => { if (timescalled == 0) { @@ -3000,7 +3002,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "", false)] public void Slewing_WhenTelescopeNotSlewing_ThenReturnsFalse(string productName, string firmwareVersion, string response, bool isSlewing) { - _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(response); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "D", false)).Returns(response); ConnectTelescope(productName, firmwareVersion); @@ -3008,7 +3010,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.EqualTo(isSlewing)); - _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "D", false), Times.Once); } [TestCase(1, TelescopeAxes.axisPrimary)] @@ -3031,7 +3033,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(_sharedResourcesWrapperMock.Object.MovingPrimary, Is.EqualTo(axis == TelescopeAxes.axisPrimary)); Assert.That(_sharedResourcesWrapperMock.Object.MovingSecondary, Is.EqualTo(axis == TelescopeAxes.axisSecondary)); - _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "D", false), Times.Never); } [TestCase(1, TelescopeAxes.axisPrimary, 0, 0, false, false)] @@ -3138,7 +3140,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToTargetAsync_WhenTargetSetAndSlewIsPossible_ThenAttemptsSlew() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, "MS", false)).Returns("0"); ConnectTelescope(); @@ -3148,13 +3150,13 @@ namespace Meade.net.Telescope.UnitTests _telescope.SlewToTargetAsync(); - _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, "MS", false), Times.Once); } [Test] public void SlewToTargetAsync_WhenTargetBelowHorizon_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, "MS", false)).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.ReadTerminated()).Returns("Below horizon"); ConnectTelescope(); @@ -3169,7 +3171,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToTargetAsync_WhenTargetBelowElevation_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("2"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, "MS", false)).Returns("2"); _sharedResourcesWrapperMock.Setup(x => x.ReadTerminated()).Returns("Above below elevation"); ConnectTelescope(); @@ -3184,7 +3186,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToTargetAsync_WhenTelescopeCanHitTripod_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("3"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, "MS", false)).Returns("3"); _sharedResourcesWrapperMock.Setup(x => x.ReadTerminated()).Returns("the telescope can hit the tripod"); ConnectTelescope(); @@ -3206,12 +3208,12 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToTarget_WhenSlewing_ThenWaitsForTheSlewToComplete() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, "MS", false)).Returns("0"); var preTestItterations = 1; var slewCounter = 0; var iterations = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "D", false)).Returns(() => { slewCounter++; if (slewCounter <= preTestItterations) @@ -3249,10 +3251,10 @@ namespace Meade.net.Telescope.UnitTests var telescopeDecResult = "s12*34’56"; - _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, "MS", false)).Returns("0"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sr{_testProperties.telescopeRaResult}", false)).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, $"Sr{_testProperties.telescopeRaResult}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GD", false)).Returns(telescopeDecResult); _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(declination); @@ -3264,7 +3266,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); - _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, "MS", false), Times.Once); } [Test] @@ -3284,19 +3286,19 @@ namespace Meade.net.Telescope.UnitTests var dmsResult = 1.2; var digitsRA = 2; - _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sr{_testProperties.telescopeRaResult}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GD", false)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, $"Sr{_testProperties.telescopeRaResult}", false)).Returns("1"); _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(telescopeDecResult); - _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, "MS", false)).Returns("0"); var preTestItterations = 1; var slewCounter = 0; var iterations = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "D", false)).Returns(() => { slewCounter++; if (slewCounter <= preTestItterations) @@ -3311,7 +3313,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.SlewToCoordinates(_testProperties.rightAscension, declination); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(dmsResult)); - _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, "MS", false), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations - preTestItterations)); } @@ -3368,15 +3370,15 @@ namespace Meade.net.Telescope.UnitTests var altitude = 30; var azimuth = 45; - _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GG", false)).Returns("-1.0"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, "MS", false)).Returns("0"); var telescopeRaResult = "HH:MM:SS"; var telescopeDecResult = "s12*34’56"; var digitsRA = 2; - _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sr{telescopeRaResult}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, $"Sr{telescopeRaResult}", false)).Returns("1"); _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(telescopeRaResult); _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(_testProperties.rightAscension); @@ -3389,7 +3391,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(_testProperties.declination)); - _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, "MS", false), Times.Once); } [Test] @@ -3411,15 +3413,15 @@ namespace Meade.net.Telescope.UnitTests _utilMock.Setup(x => x.DegreesToDMS(_testProperties.declination, "*", ":", ":", 2)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.DMSToDegrees(_testProperties.telescopeRaResult)).Returns(_testProperties.declination); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar("Sd+HH:MM:SS", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GG", false)).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, "Sd+HH:MM:SS", false)).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(_traceLoggerMock.Object, "MS", false)).Returns("0"); var preTestItterations = 1; var slewCounter = 0; var iterations = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "D", false)).Returns(() => { slewCounter++; if (slewCounter <= preTestItterations) @@ -3435,7 +3437,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(_testProperties.declination)); - _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(_traceLoggerMock.Object, "MS", false), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations - preTestItterations)); } @@ -3460,9 +3462,9 @@ namespace Meade.net.Telescope.UnitTests _testProperties.telescopeAzimuth = 200; _testProperties.hourAngle = 3; - _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GG", false)).Returns("-1.0"); - _sharedResourcesWrapperMock.Setup(x => x.SendString("Gg", false)).Returns(telescopeLongitude); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "Gg", false)).Returns(telescopeLongitude); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); @@ -3492,7 +3494,7 @@ namespace Meade.net.Telescope.UnitTests var telescopeLongitude = "350"; var telescopeLongitudeValue = 350; - _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(_traceLoggerMock.Object, "GG", false)).Returns("-1.0"); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); @@ -3521,12 +3523,12 @@ namespace Meade.net.Telescope.UnitTests _telescope.AbortSlew(); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Q", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(_traceLoggerMock.Object, "Q", false), Times.Once); var isSloSlewing = _telescope.Slewing; Assert.That(isSloSlewing, Is.False); - _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(_traceLoggerMock.Object, "D", false), Times.Once); } [Test] diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index a8a3c58..967beea 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -128,7 +128,7 @@ namespace ASCOM.Meade.net } public Telescope(IUtil util, IUtilExtra utilExtra, IAstroUtils astroUtilities, - ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths, IClock clock, INOVAS31 novas) : base( + ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths, IClock clock, INOVAS31 novas, ITraceLogger traceLogger) : base( sharedResourcesWrapper) { _clock = clock; @@ -138,7 +138,7 @@ namespace ASCOM.Meade.net _astroMaths = astroMaths; _novas = novas; - Initialise(nameof(Telescope)); + Initialise(nameof(Telescope), traceLogger); } // @@ -213,81 +213,81 @@ namespace ASCOM.Meade.net { //Read the screen case "readdisplay": - var output = SharedResourcesWrapper.SendString("ED"); + var output = SharedResourcesWrapper.SendString(Tl, "ED"); return output; //top row of buttons case "enter": - SharedResourcesWrapper.SendBlind("EK13"); + SharedResourcesWrapper.SendBlind(Tl,"EK13"); break; case "longenter": - SharedResourcesWrapper.SendBlind("EK10"); + SharedResourcesWrapper.SendBlind(Tl, "EK10"); break; case "mode": - SharedResourcesWrapper.SendBlind("EK9"); + SharedResourcesWrapper.SendBlind(Tl, "EK9"); break; case "longmode": - SharedResourcesWrapper.SendBlind("EK11"); + SharedResourcesWrapper.SendBlind(Tl, "EK11"); break; case "goto": - SharedResourcesWrapper.SendBlind("EK24"); + SharedResourcesWrapper.SendBlind(Tl, "EK24"); break; case "longgoto": - SharedResourcesWrapper.SendBlind("EK25"); + SharedResourcesWrapper.SendBlind(Tl, "EK25"); break; case "0": //light and 0 - SharedResourcesWrapper.SendBlind("EK48"); + SharedResourcesWrapper.SendBlind(Tl, "EK48"); break; case "1": - SharedResourcesWrapper.SendBlind("EK49"); + SharedResourcesWrapper.SendBlind(Tl, "EK49"); break; case "2": - SharedResourcesWrapper.SendBlind("EK50"); + SharedResourcesWrapper.SendBlind(Tl, "EK50"); break; case "3": - SharedResourcesWrapper.SendBlind("EK51"); + SharedResourcesWrapper.SendBlind(Tl, "EK51"); break; case "4": - SharedResourcesWrapper.SendBlind("EK52"); + SharedResourcesWrapper.SendBlind(Tl, "EK52"); break; case "5": - SharedResourcesWrapper.SendBlind("EK53"); + SharedResourcesWrapper.SendBlind(Tl, "EK53"); break; case "6": - SharedResourcesWrapper.SendBlind("EK54"); + SharedResourcesWrapper.SendBlind(Tl, "EK54"); break; case "7": - SharedResourcesWrapper.SendBlind("EK55"); + SharedResourcesWrapper.SendBlind(Tl, "EK55"); break; case "8": - SharedResourcesWrapper.SendBlind("EK56"); + SharedResourcesWrapper.SendBlind(Tl, "EK56"); break; case "9": - SharedResourcesWrapper.SendBlind("EK57"); + SharedResourcesWrapper.SendBlind(Tl, "EK57"); break; case "up": - SharedResourcesWrapper.SendBlind("EK94"); + SharedResourcesWrapper.SendBlind(Tl, "EK94"); break; case "down": - SharedResourcesWrapper.SendBlind("EK118"); + SharedResourcesWrapper.SendBlind(Tl, "EK118"); break; case "back": case "left": - SharedResourcesWrapper.SendBlind("EK87"); + SharedResourcesWrapper.SendBlind(Tl, "EK87"); break; case "forward": case "right": - SharedResourcesWrapper.SendBlind("EK69"); + SharedResourcesWrapper.SendBlind(Tl, "EK69"); break; case "scrollup": - SharedResourcesWrapper.SendBlind("EK85"); + SharedResourcesWrapper.SendBlind(Tl, "EK85"); break; case "scrolldown": - SharedResourcesWrapper.SendBlind("EK68"); + SharedResourcesWrapper.SendBlind(Tl, "EK68"); break; case "?": - SharedResourcesWrapper.SendBlind("EK63"); + SharedResourcesWrapper.SendBlind(Tl, "EK63"); break; default: LogMessage("", "Action {0}, parameters {1} not implemented", actionName, @@ -385,7 +385,7 @@ namespace ASCOM.Meade.net CheckConnected("CommandBlind"); // Call CommandString and return as soon as it finishes //this.CommandString(command, raw); - SharedResourcesWrapper.SendBlind(command, raw); + SharedResourcesWrapper.SendBlind(Tl, command, raw); // or //throw new ASCOM.MethodNotImplementedException("CommandBlind"); // DO NOT have both these sections! One or the other @@ -404,7 +404,7 @@ namespace ASCOM.Meade.net { LogMessage("CommandBool", $"raw: {raw} command {command}"); CheckConnected("CommandBool"); - var result = SharedResourcesWrapper.SendBool(command, raw); + var result = SharedResourcesWrapper.SendBool(Tl, command, raw); LogMessage("CommandBool", $"Completed: {result}"); return result; } @@ -429,11 +429,11 @@ namespace ASCOM.Meade.net // https://bitbucket.org/cjdskunkworks/meadeautostar497/issues/24/get-set-tracking#comment-60586901 if (command == (raw ? ":GW#" : "GW")) { - result = SharedResourcesWrapper.SendChars(command, raw, count: 3); + result = SharedResourcesWrapper.SendChars(Tl, command, raw, count: 3); } else { - result = SharedResourcesWrapper.SendString(command, raw); + result = SharedResourcesWrapper.SendString(Tl, command, raw); } LogMessage("CommandString", $"Completed: {result}"); @@ -453,8 +453,8 @@ namespace ASCOM.Meade.net // Clean up the tracelogger and util objects Tl.Enabled = false; - Tl.Dispose(); - Tl = null; + //Tl.Dispose(); + //Tl = null; } public bool Connected @@ -805,7 +805,7 @@ namespace ASCOM.Meade.net return; } - var result = SharedResourcesWrapper.SendString("GZ"); + var result = SharedResourcesWrapper.SendString(Tl, "GZ"); LogMessage("SetLongFormat", $"Get - Azimuth {result}"); //:GZ# Get telescope azimuth //Returns: DDD*MM.T or DDD*MM'SS# @@ -816,12 +816,12 @@ namespace ASCOM.Meade.net if (SharedResourcesWrapper.IsLongFormat != setLongFormat) { _utilities.WaitForMilliseconds(500); - SharedResourcesWrapper.SendBlind("U"); + SharedResourcesWrapper.SendBlind(Tl, "U"); //:U# Toggle between low/hi precision positions //Low - RA displays and messages HH:MM.T sDD*MM //High - Dec / Az / El displays and messages HH:MM: SS sDD*MM:SS // Returns Nothing - result = SharedResourcesWrapper.SendString("GZ"); + result = SharedResourcesWrapper.SendString(Tl, "GZ"); SharedResourcesWrapper.IsLongFormat = result.Length > 6; LogMessage("SetLongFormat", $"Get - Azimuth {result}"); if (SharedResourcesWrapper.IsLongFormat == setLongFormat) @@ -844,7 +844,7 @@ namespace ASCOM.Meade.net private bool TogglePrecision() { LogMessage("TogglePrecision", "Toggling slewing precision"); - var result = SharedResourcesWrapper.SendChar("P"); + var result = SharedResourcesWrapper.SendChar(Tl,"P"); //:P# Toggles High Precsion Pointing. When High precision pointing is enabled scope will first allow the operator to center a nearby bright star before moving to the actual target. //Returns: //"HIGH PRECISION" Current setting after this command. @@ -883,7 +883,7 @@ namespace ASCOM.Meade.net { CheckConnectedAndValidateSite(site, "SelectSite"); - SharedResourcesWrapper.SendBlind($"W{site}"); + SharedResourcesWrapper.SendBlind(Tl, $"W{site}"); //:W# //Set current site to, an ASCII digit in the range 1..4 //Returns: Nothing @@ -951,7 +951,7 @@ namespace ASCOM.Meade.net Resources.Telescope_GetSiteName_Site_out_of_range); } - var result = SharedResourcesWrapper.SendChar(command); + var result = SharedResourcesWrapper.SendChar(Tl, command); if (result != "1") { throw new InvalidOperationException("Failed to set site name."); @@ -965,22 +965,22 @@ namespace ASCOM.Meade.net switch (site) { case 1: - return SharedResourcesWrapper.SendString("GM"); + return SharedResourcesWrapper.SendString(Tl, "GM"); //:GM# Get Site 1 Name //Returns: # //A '#' terminated string with the name of the requested site. case 2: - return SharedResourcesWrapper.SendString("GN"); + return SharedResourcesWrapper.SendString(Tl, "GN"); //:GN# Get Site 2 Name //Returns: # //A '#' terminated string with the name of the requested site. case 3: - return SharedResourcesWrapper.SendString("GO"); + return SharedResourcesWrapper.SendString(Tl, "GO"); //:GO# Get Site 3 Name //Returns: # //A '#' terminated string with the name of the requested site. case 4: - return SharedResourcesWrapper.SendString("GP"); + return SharedResourcesWrapper.SendString(Tl, "GP"); //:GP# Get Site 4 Name //Returns: # //A '#' terminated string with the name of the requested site. @@ -1016,11 +1016,11 @@ namespace ASCOM.Meade.net { //string name = "Short driver name - please customise"; - //var telescopeProduceName = _sharedResourcesWrapper.SendString("GVP"); + //var telescopeProduceName = _sharedResourcesWrapper.SendString(Tl, "GVP"); ////:GVP# Get Telescope Product Name ////Returns: # - //var firmwareVersion = _sharedResourcesWrapper.SendString("GVN"); + //var firmwareVersion = _sharedResourcesWrapper.SendString(Tl, "GVN"); ////:GVN# Get Telescope Firmware Number ////Returns: dd.d# @@ -1049,7 +1049,7 @@ namespace ASCOM.Meade.net CheckParked(); LogMessage("AbortSlew", "Aborting slew"); - SharedResourcesWrapper.SendBlind("Q"); + SharedResourcesWrapper.SendBlind(Tl, "Q"); //:Q# Halt all current slewing //Returns:Nothing @@ -1138,13 +1138,13 @@ namespace ASCOM.Meade.net switch (value) { case AlignmentModes.algAltAz: - SharedResourcesWrapper.SendBlind("AA"); + SharedResourcesWrapper.SendBlind(Tl, "AA"); //:AA# Sets telescope the AltAz alignment mode //Returns: nothing break; case AlignmentModes.algPolar: case AlignmentModes.algGermanPolar: - SharedResourcesWrapper.SendBlind("AP"); + SharedResourcesWrapper.SendBlind(Tl, "AP"); //:AP# Sets telescope to Polar alignment mode //Returns: nothing break; @@ -1174,7 +1174,7 @@ namespace ASCOM.Meade.net //D If scope is currently in the Downloader[Autostar II & Autostar] //L If scope in Land Mode //P If scope in Polar Mode - var alignmentString = SharedResourcesWrapper.SendChar(ack.ToString()); + var alignmentString = SharedResourcesWrapper.SendChar(Tl, ack.ToString()); return alignmentString; } @@ -1265,7 +1265,7 @@ namespace ASCOM.Meade.net CheckParked(); //firmware bug in 44Eg, :GA# is returning the dec, not the altitude! - var result = SharedResourcesWrapper.SendString("GA"); + var result = SharedResourcesWrapper.SendString(Tl, "GA"); //:GA# Get Telescope Altitude //Returns: sDD* MM# or sDD*MM'SS# //The current scope altitude. The returned format depending on the current precision setting. @@ -1430,7 +1430,7 @@ namespace ASCOM.Meade.net { CheckParked(); - var result = SharedResourcesWrapper.SendString("GZ"); + var result = SharedResourcesWrapper.SendString(Tl, "GZ"); //:GZ# Get telescope azimuth //Returns: DDD*MM#T or DDD*MM'SS# //The current telescope Azimuth depending on the selected precision. @@ -1787,7 +1787,7 @@ namespace ASCOM.Meade.net { CheckParked(); - var result = SharedResourcesWrapper.SendString("GD"); + var result = SharedResourcesWrapper.SendString(Tl, "GD"); //:GD# Get Telescope Declination. //Returns: sDD*MM# or sDD*MM'SS# //Depending upon the current precision setting for the telescope. @@ -1972,7 +1972,7 @@ namespace ASCOM.Meade.net } LogMessage($"{propertyName} Set", $"Setting new guiderate {value.ToString(CultureInfo.CurrentCulture)} arc seconds/second ({value.ToString(CultureInfo.CurrentCulture)} degrees/second)"); - SharedResourcesWrapper.SendBlind($"Rg{value:00.0}"); + SharedResourcesWrapper.SendBlind(Tl, $"Rg{value:00.0}"); //:RgSS.S# //Set guide rate to +/ -SS.S to arc seconds per second.This rate is added to or subtracted from the current tracking //Rates when the CCD guider or handbox guider buttons are pressed when the guide rate is selected.Rate shall not exceed @@ -2097,22 +2097,22 @@ namespace ASCOM.Meade.net //do nothing, it's ok this time as we're halting the slew. break; case 1: - SharedResourcesWrapper.SendBlind("RG"); + SharedResourcesWrapper.SendBlind(Tl, "RG"); //:RG# Set Slew rate to Guiding Rate (slowest) //Returns: Nothing break; case 2: - SharedResourcesWrapper.SendBlind("RC"); + SharedResourcesWrapper.SendBlind(Tl, "RC"); //:RC# Set Slew rate to Centering rate (2nd slowest) //Returns: Nothing break; case 3: - SharedResourcesWrapper.SendBlind("RM"); + SharedResourcesWrapper.SendBlind(Tl, "RM"); //:RM# Set Slew rate to Find Rate (2nd Fastest) //Returns: Nothing break; case 4: - SharedResourcesWrapper.SendBlind("RS"); + SharedResourcesWrapper.SendBlind(Tl, "RS"); //:RS# Set Slew rate to max (fastest) //Returns: Nothing break; @@ -2132,21 +2132,21 @@ namespace ASCOM.Meade.net } SharedResourcesWrapper.MovingPrimary = false; - SharedResourcesWrapper.SendBlind("Qe"); + SharedResourcesWrapper.SendBlind(Tl, "Qe"); //:Qe# Halt eastward Slews //Returns: Nothing - SharedResourcesWrapper.SendBlind("Qw"); + SharedResourcesWrapper.SendBlind(Tl, "Qw"); //:Qw# Halt westward Slews //Returns: Nothing break; case ComparisonResult.Greater: - SharedResourcesWrapper.SendBlind("Me"); + SharedResourcesWrapper.SendBlind(Tl, "Me"); //:Me# Move Telescope East at current slew rate //Returns: Nothing SharedResourcesWrapper.MovingPrimary = true; break; case ComparisonResult.Lower: - SharedResourcesWrapper.SendBlind("Mw"); + SharedResourcesWrapper.SendBlind(Tl, "Mw"); //:Mw# Move Telescope West at current slew rate //Returns: Nothing SharedResourcesWrapper.MovingPrimary = true; @@ -2164,21 +2164,21 @@ namespace ASCOM.Meade.net } SharedResourcesWrapper.MovingSecondary = false; - SharedResourcesWrapper.SendBlind("Qn"); + SharedResourcesWrapper.SendBlind(Tl, "Qn"); //:Qn# Halt northward Slews //Returns: Nothing - SharedResourcesWrapper.SendBlind("Qs"); + SharedResourcesWrapper.SendBlind(Tl, "Qs"); //:Qs# Halt southward Slews //Returns: Nothing break; case ComparisonResult.Greater: - SharedResourcesWrapper.SendBlind("Mn"); + SharedResourcesWrapper.SendBlind(Tl, "Mn"); //:Mn# Move Telescope North at current slew rate //Returns: Nothing SharedResourcesWrapper.MovingSecondary = true; break; case ComparisonResult.Lower: - SharedResourcesWrapper.SendBlind("Ms"); + SharedResourcesWrapper.SendBlind(Tl, "Ms"); //:Ms# Move Telescope South at current slew rate //Returns: Nothing SharedResourcesWrapper.MovingSecondary = true; @@ -2251,7 +2251,7 @@ namespace ASCOM.Meade.net if (SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC) { - SharedResourcesWrapper.SendBlind("hP"); + SharedResourcesWrapper.SendBlind(Tl, "hP"); //:hP# Autostar, Autostar II and LX 16" Slew to Park Position //Returns: Nothing } @@ -2333,7 +2333,7 @@ namespace ASCOM.Meade.net } LogMessage("PulseGuide", "Using new pulse guiding technique"); - SharedResourcesWrapper.SendBlind($"Mg{d}{duration:0000}"); + SharedResourcesWrapper.SendBlind(Tl, $"Mg{d}{duration:0000}"); //:MgnDDDD# //:MgsDDDD# //:MgeDDDD# @@ -2419,7 +2419,7 @@ namespace ASCOM.Meade.net { CheckParked(); - var result = SharedResourcesWrapper.SendString("GR"); + var result = SharedResourcesWrapper.SendString(Tl, "GR"); //:GR# Get Telescope RA //Returns: HH:MM.T# or HH:MM:SS# //Depending which precision is set for the telescope @@ -2627,7 +2627,7 @@ namespace ASCOM.Meade.net { CheckParked(); - var latitude = SharedResourcesWrapper.SendString("Gt"); + var latitude = SharedResourcesWrapper.SendString(Tl, "Gt"); //:Gt# Get Current Site Latitude //Returns: sDD* MM# //The latitude of the current site. Positive inplies North latitude. @@ -2674,7 +2674,7 @@ namespace ASCOM.Meade.net int m = Convert.ToInt32(60 * (absValue - d)); var commandString = $"St{sign}{d:00}*{m:00}"; - var result = SharedResourcesWrapper.SendChar(commandString); + var result = SharedResourcesWrapper.SendChar(Tl, commandString); //:StsDD*MM# //Sets the current site latitude to sDD* MM# //Returns: @@ -2702,7 +2702,7 @@ namespace ASCOM.Meade.net { CheckParked(); - var longitude = SharedResourcesWrapper.SendString("Gg"); + var longitude = SharedResourcesWrapper.SendString(Tl, "Gg"); //:Gg# Get Current Site Longitude //Returns: sDDD*MM# //The current site Longitude. East Longitudes are expressed as negative @@ -2753,7 +2753,7 @@ namespace ASCOM.Meade.net var commandstring = $"Sg{d:000}*{m:00}"; - var result = SharedResourcesWrapper.SendChar(commandstring); + var result = SharedResourcesWrapper.SendChar(Tl, commandstring); //:SgDDD*MM# //Set current site's longitude to DDD*MM an ASCII position string //Returns: @@ -2907,7 +2907,7 @@ namespace ASCOM.Meade.net var command = $"Sa{s}{dms}"; LogMessage("TargetAltitude Set", $"{command}"); - var response = SharedResourcesWrapper.SendBool(command); + var response = SharedResourcesWrapper.SendBool(Tl, command); //:SasDD*MM# // Set target object altitude to sDD*MM# or sDD*MM’SS# [LX 16”, Autostar, Autostar II] // Returns: @@ -2944,7 +2944,7 @@ namespace ASCOM.Meade.net var command = $"Sz{dms}"; LogMessage("TargetAzimuth Set", $"{command}"); - var response = SharedResourcesWrapper.SendBool(command); + var response = SharedResourcesWrapper.SendBool(Tl, command); //:SzDDD*MM# // Sets the target Object Azimuth[LX 16” and Autostar II only] // Returns: @@ -2978,7 +2978,7 @@ namespace ASCOM.Meade.net { case true: LogMessage("DoSlewAsync", "Executing Polar slew"); - var response = SharedResourcesWrapper.SendChar("MS"); + var response = SharedResourcesWrapper.SendChar(Tl, "MS"); //:MS# Slew to Target Object //Returns: //0 Slew is Possible @@ -3018,7 +3018,7 @@ namespace ASCOM.Meade.net Retry(6, () => { LogMessage("DoSlewAsync", "Executing Alt Az"); - var maResponse = SharedResourcesWrapper.SendChar("MA"); + var maResponse = SharedResourcesWrapper.SendChar(Tl, "MA"); //:MA# Autostar, LX 16", Autostar II - Slew to target Alt and Az //Returns: //0 - No fault @@ -3242,7 +3242,7 @@ namespace ASCOM.Meade.net string result; try { - result = SharedResourcesWrapper.SendString("D"); + result = SharedResourcesWrapper.SendString(Tl, "D"); } catch (TimeoutException) { @@ -3343,7 +3343,7 @@ namespace ASCOM.Meade.net CheckConnected("SyncToTarget"); CheckParked(); - var result = SharedResourcesWrapper.SendString("CM"); + var result = SharedResourcesWrapper.SendString(Tl, "CM"); //:CM# Synchronizes the telescope's position with the currently selected database object's coordinates. //Returns: //LX200's - a "#" terminated string with the name of the object that was synced. @@ -3432,7 +3432,7 @@ namespace ASCOM.Meade.net var command = $"Sd{s}{dms}"; LogMessage("TargetDeclination Set", $"{command}"); - var result = SharedResourcesWrapper.SendChar(command); + var result = SharedResourcesWrapper.SendChar(Tl, command); //:SdsDD*MM# //Set target object declination to sDD*MM or sDD*MM:SS depending on the current precision setting //Returns: @@ -3501,7 +3501,7 @@ namespace ASCOM.Meade.net var command = $"Sr{hms}"; LogMessage("TargetRightAscension Set", $"{command}"); - var response = SharedResourcesWrapper.SendChar(command); + var response = SharedResourcesWrapper.SendChar(Tl, command); //:SrHH:MM.T# //:SrHH:MM:SS# //Set target object RA to HH:MM.T or HH: MM: SS depending on the current precision setting. @@ -3564,7 +3564,7 @@ namespace ASCOM.Meade.net if (!value) { SharedResources.AlignmentMode = AlignmentMode; - SharedResourcesWrapper.SendBlind("AL"); + SharedResourcesWrapper.SendBlind(Tl, "AL"); } else { @@ -3635,22 +3635,22 @@ namespace ASCOM.Meade.net switch (value) { case DriveRates.driveSidereal: - SharedResourcesWrapper.SendBlind("TQ"); + SharedResourcesWrapper.SendBlind(Tl, "TQ"); //:TQ# Selects sidereal tracking rate //Returns: Nothing break; case DriveRates.driveLunar: - SharedResourcesWrapper.SendBlind("TL"); + SharedResourcesWrapper.SendBlind(Tl, "TL"); //:TL# Set Lunar Tracking Rage //Returns: Nothing break; case DriveRates.driveSolar: - SharedResourcesWrapper.SendBlind("TS"); + SharedResourcesWrapper.SendBlind(Tl, "TS"); // //:TS# Select Solar tracking rate. [LS Only] // //Returns: Nothing break; //case DriveRates.driveKing: - // SharedResourcesWrapper.SendBlind("TM"); + // SharedResourcesWrapper.SendBlind(Tl, "TM"); // //:TM# Select custom tracking rate [ no-op in Autostar II] // //Returns: Nothing // break; @@ -3692,7 +3692,7 @@ namespace ASCOM.Meade.net private TimeSpan GetUtcCorrection() { - string utcOffSet = SharedResourcesWrapper.SendString("GG"); + string utcOffSet = SharedResourcesWrapper.SendString(Tl, "GG"); //:GG# Get UTC offset time //Returns: sHH# or sHH.H# //The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the @@ -3723,11 +3723,11 @@ namespace ASCOM.Meade.net var telescopeDateDetails = new TelescopeDateDetails { - TelescopeDate = SharedResourcesWrapper.SendString("GC"), + TelescopeDate = SharedResourcesWrapper.SendString(Tl, "GC"), //:GC# Get current date. //Returns: MM/DD/YY# //The current local calendar date for the telescope. - TelescopeTime = SharedResourcesWrapper.SendString("GL"), + TelescopeTime = SharedResourcesWrapper.SendString(Tl, "GL"), //:GL# Get Local Time in 24 hour format //Returns: HH:MM:SS# //The Local Time in 24 - hour Format @@ -3780,7 +3780,7 @@ namespace ASCOM.Meade.net var localDateTime = value - utcCorrection; string localStingCommand = $"SL{localDateTime:HH:mm:ss}"; - var timeResult = SharedResourcesWrapper.SendChar(localStingCommand); + var timeResult = SharedResourcesWrapper.SendChar(Tl, localStingCommand); //:SLHH:MM:SS# //Set the local Time //Returns: @@ -3792,7 +3792,7 @@ namespace ASCOM.Meade.net } string localDateCommand = $"SC{localDateTime:MM/dd/yy}"; - var dateResult = SharedResourcesWrapper.SendChar(localDateCommand); + var dateResult = SharedResourcesWrapper.SendChar(Tl, localDateCommand); //:SCMM/DD/YY# //Change Handbox Date to MM/DD/YY //Returns: @@ -3833,7 +3833,7 @@ namespace ASCOM.Meade.net { case TelescopeList.RCX400: case TelescopeList.LX200GPS: - SharedResourcesWrapper.SendChar("I"); + SharedResourcesWrapper.SendChar(Tl, "I"); //:I# LX200 GPS Only - Causes the telescope to cease current operations and restart at its power on initialization. //Returns: X once the handset restart has completed @@ -3871,7 +3871,7 @@ namespace ASCOM.Meade.net var localDateTime = _clock.UtcNow - utcCorrection; //localDateTime: HH: mm: ss - var result = SharedResourcesWrapper.SendChar($"hI{localDateTime:yyMMddHHmmss}"); + var result = SharedResourcesWrapper.SendChar(Tl, $"hI{localDateTime:yyMMddHHmmss}"); //:hIYYMMDDHHMMSS# //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 diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index c0e8442..6eef33d 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -38,7 +38,7 @@ namespace Meade.net.UnitTests public void SendBlind_WhenCalled_Then_ClearsBuffersAndSendsMessage(bool raw, string expectedMessage) { var sendMessage = "Test"; - SharedResources.SendBlind(sendMessage, raw); + SharedResources.SendBlind(_traceLoggerMock.Object, sendMessage, raw); _serialMock.Verify(x=> x.ClearBuffers(), Times.Once); _serialMock.Verify(x=>x.Transmit(expectedMessage), Times.Once); diff --git a/Meade.net.focuser/Focuser.cs b/Meade.net.focuser/Focuser.cs index 75ae1cc..9753bb6 100644 --- a/Meade.net.focuser/Focuser.cs +++ b/Meade.net.focuser/Focuser.cs @@ -57,11 +57,11 @@ namespace ASCOM.Meade.net Initialise(nameof(Focuser)); } - public Focuser(IUtil util, ISharedResourcesWrapper sharedResourcesWrapper) : base(sharedResourcesWrapper) + public Focuser(IUtil util, ISharedResourcesWrapper sharedResourcesWrapper, ITraceLogger traceLogger) : base(sharedResourcesWrapper) { _utilities = util; - Initialise(nameof(Focuser)); + Initialise(nameof(Focuser), traceLogger); } // @@ -78,17 +78,17 @@ namespace ASCOM.Meade.net /// public void SetupDialog() { - Tl.LogMessage("SetupDialog", "Opening setup dialog"); + Tl.LogMessage("SetupDialog", "Opening setup dialog", false); SharedResourcesWrapper.SetupDialog(); ReadProfile(); - Tl.LogMessage("SetupDialog", "complete"); + Tl.LogMessage("SetupDialog", "complete", false); } public ArrayList SupportedActions { get { - Tl.LogMessage("SupportedActions Get", "Returning empty arraylist"); + Tl.LogMessage("SupportedActions Get", "Returning empty arraylist", false); return new ArrayList(); } } @@ -105,7 +105,7 @@ namespace ASCOM.Meade.net CheckConnected("CommandBlind"); // Call CommandString and return as soon as it finishes //this.CommandString(command, raw); - SharedResourcesWrapper.SendBlind(command, raw); + SharedResourcesWrapper.SendBlind(Tl, command, raw); // or //throw new ASCOM.MethodNotImplementedException("CommandBlind"); // DO NOT have both these sections! One or the other @@ -116,7 +116,7 @@ namespace ASCOM.Meade.net { LogMessage("CommandBool", "raw: {0} command {0}", raw, command); CheckConnected("CommandBool"); - var result = SharedResourcesWrapper.SendBool(command, raw); + var result = SharedResourcesWrapper.SendBool(Tl, command, raw); LogMessage("CommandBool", "Completed: {0}", result); return result; // or @@ -131,7 +131,7 @@ namespace ASCOM.Meade.net // it's a good idea to put all the low level communication with the device here, // then all communication calls this function // you need something to ensure that only one command is in progress at a time - var result = SharedResourcesWrapper.SendString(command, raw); + var result = SharedResourcesWrapper.SendString(Tl, command, raw); LogMessage("CommandBool", "Completed: {0}", result); return result; //throw new ASCOM.MethodNotImplementedException("CommandString"); @@ -141,8 +141,8 @@ namespace ASCOM.Meade.net { // Clean up the tracelogger and util objects Tl.Enabled = false; - Tl.Dispose(); - Tl = null; + //Tl.Dispose(); + //Tl = null; } public bool Connected @@ -204,7 +204,7 @@ namespace ASCOM.Meade.net { //string name = "Short driver name - please customise"; string name = DriverDescription; - Tl.LogMessage("Name Get", name); + Tl.LogMessage("Name Get", name, false); return name; } } @@ -219,20 +219,20 @@ namespace ASCOM.Meade.net { CheckConnected("Absolute Get"); - Tl.LogMessage("Absolute Get", false.ToString()); + Tl.LogMessage("Absolute Get", false.ToString(), false); return false; // This is a relative focuser } } public void Halt() { - Tl.LogMessage("Halt", "Halting"); + Tl.LogMessage("Halt", "Halting", false); CheckConnected("Halt"); //todo fix this issue: A single halt command is sometimes missed by the #909 apm, so let's do it a few times to be safe. - SharedResourcesWrapper.SendBlind("FQ"); + SharedResourcesWrapper.SendBlind(Tl, "FQ"); //:FQ# Halt Focuser Motion //Returns: Nothing } @@ -241,7 +241,7 @@ namespace ASCOM.Meade.net { get { - Tl.LogMessage("IsMoving Get", false.ToString()); + Tl.LogMessage("IsMoving Get", false.ToString(), false); return false; // This focuser always moves instantaneously so no need for IsMoving ever to be True } } @@ -250,12 +250,12 @@ namespace ASCOM.Meade.net { get { - Tl.LogMessage("Link Get", Connected.ToString()); + Tl.LogMessage("Link Get", Connected.ToString(), false); return Connected; // Direct function to the connected method, the Link method is just here for backwards compatibility } set { - Tl.LogMessage("Link Set", value.ToString()); + Tl.LogMessage("Link Set", value.ToString(), false); Connected = value; // Direct function to the connected method, the Link method is just here for backwards compatibility } } @@ -265,7 +265,7 @@ namespace ASCOM.Meade.net { get { - Tl.LogMessage("MaxIncrement Get", _maxIncrement.ToString()); + Tl.LogMessage("MaxIncrement Get", _maxIncrement.ToString(), false); return _maxIncrement; // Maximum change in one move } } @@ -276,14 +276,14 @@ namespace ASCOM.Meade.net { get { - Tl.LogMessage("MaxStep Get", _maxStep.ToString()); + Tl.LogMessage("MaxStep Get", _maxStep.ToString(), false); return _maxStep; } } public void Move(int position) { - Tl.LogMessage("Move", position.ToString()); + Tl.LogMessage("Move", position.ToString(), false); CheckConnected("Move"); if (position < -MaxIncrement || position > MaxIncrement) @@ -311,7 +311,7 @@ namespace ASCOM.Meade.net //ApplyBacklashCompensation(direction); if (direction & backlashCompensationSteps != 0) { - Tl.LogMessage("Move", "Applying backlash compensation"); + Tl.LogMessage("Move", "Applying backlash compensation", false); MoveFocuser(!direction, backlashCompensationSteps); } @@ -325,7 +325,7 @@ namespace ASCOM.Meade.net if (!_profileProperties.DynamicBreaking) return; - Tl.LogMessage("Move", "Applying dynamic breaking"); + Tl.LogMessage("Move", "Applying dynamic breaking", false); PerformFocuserMove(directionOut); Halt(); @@ -354,7 +354,7 @@ namespace ASCOM.Meade.net private void PerformFocuserMove(bool directionOut) { - SharedResourcesWrapper.SendBlind(directionOut ? "F+" : "F-"); + SharedResourcesWrapper.SendBlind(Tl, directionOut ? "F+" : "F-"); //:F+# Start Focuser moving inward (toward objective) //Returns: None @@ -368,7 +368,7 @@ namespace ASCOM.Meade.net { get { - Tl.LogMessage("StepSize Get", "Not implemented"); + Tl.LogMessage("StepSize Get", "Not implemented", false); throw new PropertyNotImplementedException("StepSize", false); } } @@ -377,13 +377,13 @@ namespace ASCOM.Meade.net { get { - Tl.LogMessage("TempComp Get", false.ToString()); + Tl.LogMessage("TempComp Get", false.ToString(), false); return false; } // ReSharper disable once ValueParameterNotUsed set { - Tl.LogMessage("TempComp Set", "Not implemented"); + Tl.LogMessage("TempComp Set", "Not implemented", false); throw new PropertyNotImplementedException("TempComp", false); } } @@ -392,7 +392,7 @@ namespace ASCOM.Meade.net { get { - Tl.LogMessage("TempCompAvailable Get", false.ToString()); + Tl.LogMessage("TempCompAvailable Get", false.ToString(), false); return false; // Temperature compensation is not available in this driver } } @@ -401,7 +401,7 @@ namespace ASCOM.Meade.net { get { - Tl.LogMessage("Temperature Get", "Not implemented"); + Tl.LogMessage("Temperature Get", "Not implemented", false); throw new PropertyNotImplementedException("Temperature", false); } } diff --git a/Meade.net/MeadeTelescopeBase.cs b/Meade.net/MeadeTelescopeBase.cs index b7b2963..35e38c1 100644 --- a/Meade.net/MeadeTelescopeBase.cs +++ b/Meade.net/MeadeTelescopeBase.cs @@ -3,6 +3,7 @@ using System.Reflection; using System.Runtime.InteropServices; using ASCOM.Meade.net.Wrapper; using ASCOM.Utilities; +using ASCOM.Utilities.Interfaces; namespace ASCOM.Meade.net { @@ -12,7 +13,7 @@ namespace ASCOM.Meade.net /// /// Variable to hold the trace logger object (creates a diagnostic log file with information that you specify) /// - protected static TraceLogger Tl; + protected static ITraceLogger Tl; /// /// Driver description that displays in the ASCOM Chooser. @@ -32,9 +33,9 @@ namespace ASCOM.Meade.net SharedResourcesWrapper = sharedResourcesWrapper; } - protected void Initialise(string className) + protected void Initialise(string className, ITraceLogger traceLogger = null) { - Tl = new TraceLogger("", $"Meade.Generic.{className}"); + Tl = traceLogger ?? new TraceLogger("", $"Meade.Generic.{className}"); ReadProfile(); // Read device configuration from the ASCOM Profile store @@ -79,7 +80,7 @@ namespace ASCOM.Meade.net public static void LogMessage(string identifier, string message, params object[] args) { var msg = string.Format(message, args); - Tl.LogMessage(identifier, msg); + Tl.LogMessage(identifier, msg, false); } /// @@ -91,7 +92,7 @@ namespace ASCOM.Meade.net { get { - Tl.LogMessage("Description Get", DriverDescription); + Tl.LogMessage("Description Get", DriverDescription, false); return DriverDescription; } } diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index a40be75..db51f2e 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -80,7 +80,7 @@ namespace ASCOM.Meade.net } //todo add code to ensure that there is a minimum gap between commands. 5ms as default. - public static void SendBlind(string message, bool raw = false) + public static void SendBlind(ITraceLogger traceLogger, string message, bool raw = false) { lock (LockObject) { diff --git a/Meade.net/Wrapper/SharedResourcesWrapper.cs b/Meade.net/Wrapper/SharedResourcesWrapper.cs index 052350a..d5231a2 100644 --- a/Meade.net/Wrapper/SharedResourcesWrapper.cs +++ b/Meade.net/Wrapper/SharedResourcesWrapper.cs @@ -13,11 +13,11 @@ namespace ASCOM.Meade.net.Wrapper string FirmwareVersion { get; } - string SendString(string message, bool raw = false); - void SendBlind(string message, bool raw = false); - bool SendBool(string command, bool raw = false); - string SendChar(string message, bool raw = false); - string SendChars(string message, bool raw = false, int count = 1); + string SendString(ITraceLogger traceLogger, string message, bool raw = false); + void SendBlind(ITraceLogger traceLogger, string message, bool raw = false); + bool SendBool(ITraceLogger traceLogger, string command, bool raw = false); + string SendChar(ITraceLogger traceLogger, string message, bool raw = false); + string SendChars(ITraceLogger traceLogger, string message, bool raw = false, int count = 1); string ReadTerminated(); @@ -66,27 +66,27 @@ namespace ASCOM.Meade.net.Wrapper public string FirmwareVersion => SharedResources.FirmwareVersion; - public string SendString(string message, bool raw = false) + public string SendString(ITraceLogger traceLogger, string message, bool raw = false) { return SharedResources.SendString(message, raw); } - public void SendBlind(string message, bool raw = false) + public void SendBlind(ITraceLogger traceLogger, string message, bool raw = false) { - SharedResources.SendBlind(message, raw); + SharedResources.SendBlind(traceLogger, message, raw); } - public bool SendBool(string command, bool raw = false) + public bool SendBool(ITraceLogger traceLogger, string command, bool raw = false) { return SharedResources.SendBool(command, raw); } - public string SendChar(string message, bool raw = false) + public string SendChar(ITraceLogger traceLogger, string message, bool raw = false) { return SharedResources.SendChar(message, raw); } - public string SendChars(string message, bool raw = false, int count = 1) + public string SendChars(ITraceLogger traceLogger, string message, bool raw = false, int count = 1) { return SharedResources.SendChars(message, raw, count); }