diff --git a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs index 638cb56..9dfd50b 100644 --- a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs +++ b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs @@ -6,6 +6,7 @@ using ASCOM.Meade.net.Wrapper; using ASCOM.Utilities.Interfaces; using Moq; using NUnit.Framework; +using NotImplementedException = System.NotImplementedException; namespace Meade.net.Focuser.UnitTests { @@ -31,6 +32,9 @@ namespace Meade.net.Focuser.UnitTests _utilMock = new Mock(); _sharedResourcesWrapperMock = new Mock(); + + _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny())).Callback(action => { action(); }); + _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(() => _profileProperties); _focuser = new ASCOM.Meade.net.Focuser(_utilMock.Object, _sharedResourcesWrapperMock.Object); @@ -361,12 +365,12 @@ namespace Meade.net.Focuser.UnitTests [TestCase(-7001)] [TestCase(7001)] - public void Move_WhenLargerThanMaxIncrement_ThenThrowsException(int increment) + public void Move_WhenLargerThanMaxIncrement_ThenThrowsException(int position) { ConnectFocuser(); - var exception = Assert.Throws(() => { _focuser.Move(increment); }); - Assert.That(exception.Message, Is.EqualTo($"position out of range -{_focuser.MaxIncrement} < {increment} < {_focuser.MaxIncrement}")); + var exception = Assert.Throws(() => { _focuser.Move(position); }); + Assert.That(exception.Message, Is.EqualTo($"position out of range -{_focuser.MaxIncrement} < {position} < {_focuser.MaxIncrement}")); } [Test] @@ -378,5 +382,74 @@ namespace Meade.net.Focuser.UnitTests _utilMock.Verify( x => x.WaitForMilliseconds(It.IsAny()), Times.Never); } + + [TestCase(200)] + [TestCase(-200)] + public void Move_WhenIncrementIsNot0_ThenMovesFocuserAndStopsFocuser( int position) + { + ConnectFocuser(); + + _focuser.Move(position); + + if (position < 0) + { + _sharedResourcesWrapperMock.Verify( x => x.SendBlind(":F-#"), Times.AtLeastOnce); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F+#"), Times.Never); + } + else + { + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F-#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F+#"), Times.AtLeastOnce); + } + + _sharedResourcesWrapperMock.Verify( x => x.Lock(It.IsAny()), Times.Once); + + _utilMock.Verify(x => x.WaitForMilliseconds(250), Times.AtLeastOnce); + + _utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Once()); + _utilMock.Verify(x => x.WaitForMilliseconds(1000), Times.Once()); + } + + [Test] + public void Position_WhenCalled_ThenThrowsException() + { + var exception = Assert.Throws(() => { var result = _focuser.Position; }); + Assert.That(exception.Message, Is.EqualTo("Property read Position is not implemented in this driver.")); + } + + [Test] + public void StepSize_WhenCalled_ThenThrowsException() + { + var exception = Assert.Throws(() => { var result = _focuser.StepSize; }); + Assert.That(exception.Message, Is.EqualTo("Property read StepSize is not implemented in this driver.")); + } + + [Test] + public void TempComp_WhenRead_ThenReturnsFalse() + { + var result = _focuser.TempComp; + Assert.That(result, Is.False); + } + + [Test] + public void TempComp_WhenWrite_ThenThrowsException() + { + var exception = Assert.Throws(() => { _focuser.TempComp = false; }); + Assert.That(exception.Message, Is.EqualTo("Property read TempComp is not implemented in this driver.")); + } + + [Test] + public void TempCompAvailable_WhenRead_ThenReturnsFalse() + { + var result = _focuser.TempCompAvailable; + Assert.That(result, Is.False); + } + + [Test] + public void Temperature_WhenCalled_ThenThrowsException() + { + var exception = Assert.Throws(() => { var result = _focuser.Temperature; }); + Assert.That(exception.Message, Is.EqualTo("Property read Temperature is not implemented in this driver.")); + } } } diff --git a/Meade.net.focuser/Focuser.cs b/Meade.net.focuser/Focuser.cs index a49bfbe..81362d9 100644 --- a/Meade.net.focuser/Focuser.cs +++ b/Meade.net.focuser/Focuser.cs @@ -5,7 +5,6 @@ using System.Diagnostics; using System.Runtime.InteropServices; using ASCOM.Utilities; using ASCOM.DeviceInterface; -using System.Globalization; using System.Collections; using System.Reflection; using ASCOM.Meade.net.Wrapper;