Merged in develop (pull request #3)
Develop
* Removed unwanted files
* Adding git ignore file
* Started working on getting the basic communications with the scope working.
Working on routines to get and set the date and time in the handbox.
* Switched the serial port over to using the .net frameworks serial port.
Extracted the serial port into it's own class and created a simpler command processing mechanism.
* Implemented AbortSlew and did some code tidy up.
* Forced all code to 64-bit only, will make this 32/64 bit before release.
Fixed issue in the SerialProcessor when setting the time, makes sure that there's no chance of thread stealing when pulling out the junk messages
Added ConformanceResult.txt to show the progress of the driver development
* Added code for the site latitude
and started work on the longitude.
* Added unit tests for reading and writing the utcDate.
Fixed a couple of defects in the code that was setting the utcDate.
* Corrected Longitude value range
* Added support for UTC offset.
* Pulse guiding support added
* Added SiteLatitude unit tests
* Added unit tests for SiteLongitude
* Added unit tests for the new Pulse guide implementation.
* Added support for AlignmentMode
* Added support for AtPark and Park
* Added support for parking the scope
Added support for reading the scope Azimuth
* Added support for reading Declination
* Added 5 second timeout for the serial port.
Fixed problem with the GW command not working on the Autostar 497.
* Fixed broken unit test
* Added support for altitude
* Tidying up resharper warinings
* Implemented RightAscension
TargetRightAscension
TargetDec
SlewToCoord
and SlewToCoordAsync
* Sorted out the target RA and Dec exceptions to be compliant with ascom.
* Implemented SlewToAltAz and SlewToAltAzAsync
* Implemented SyncToTarget functionality
* Implemented slew to target
* Added support for MoveAxis
* Added support for tracking rate
* Added IFocuserV3 to the driver and made sure that it's registered for ASCOM as a focuser as well.
* Fixed issue with Target RA and Dec loosing precision
* Telescope driver now passes the Ascom conformance.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<#
|
||||
This script initializes a bare minimum set of registry entries required for ASCOM.Utilities.Profile to work
|
||||
without throwing any exceptions. When building on a build server, or on a computer without the ASCOM Platform installed,
|
||||
it may be useful to execute this script as a build step prior to running any unit tests, or calling any code that relies on
|
||||
ASCOM.Utilities.Profile. The alternative is to install the ASCOM Platform on the build agent.
|
||||
|
||||
NOTE: This script equires elevated permissions because it creates registry keys in the LocalMachine hive.
|
||||
#>
|
||||
|
||||
$wow = Test-Path HKLM:\SOFTWARE\Wow6432Node
|
||||
if ($wow)
|
||||
{
|
||||
$root = "HKLM:\SOFTWARE\Wow6432Node"
|
||||
}
|
||||
else
|
||||
{
|
||||
$root = "HKLM:\SOFTWARE"
|
||||
}
|
||||
$ascomRoot = $root + "\ASCOM"
|
||||
|
||||
if (Test-Path $ascomRoot)
|
||||
{
|
||||
<# Don't upset an already-existing ASCOM registry #>
|
||||
exit
|
||||
}
|
||||
|
||||
<# Create the ASCOM root key and set it's ACL to allow all users read/write access #>
|
||||
New-Item -Path $root -Name ASCOM –Force
|
||||
$ascomAcl = Get-Acl $ascomRoot
|
||||
$aclRule = New-Object System.Security.AccessControl.RegistryAccessRule ("Users","FullControl","Allow")
|
||||
$ascomAcl.SetAccessRule($aclRule)
|
||||
$ascomAcl | Set-Acl -Path $ascomRoot
|
||||
|
||||
<# Now create the bare minimum keys required so that ASCOM.Utilities.Profile doesn't crash and burn #>
|
||||
New-ItemProperty -Path $ascomRoot -Name PlatformVersion -Value "6.1" -PropertyType String –Force
|
||||
New-ItemProperty -Path $ascomRoot -Name SerTraceFile -Value "C:\SerialTraceAuto.txt" -PropertyType String –Force
|
||||
@@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\NUnit.3.11.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{9638DA27-77C7-4B30-A730-6E7159A4A09F}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>MeadeAutostar497.UnitTests</RootNamespace>
|
||||
<AssemblyName>MeadeAutostar497.UnitTests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="ASCOM.Astrometry, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Astrometry.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ASCOM.Attributes, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Attributes.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ASCOM.Cache, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Cache.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ASCOM.Controls, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Controls.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ASCOM.DeviceInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.DeviceInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ASCOM.DriverAccess, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.DriverAccess.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ASCOM.Exceptions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Exceptions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ASCOM.Internal.Extensions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Internal.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ASCOM.SettingsProvider, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.SettingsProvider.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ASCOM.Utilities, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Utilities.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ASCOM.Utilities.Video, Version=6.1.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Utilities.Video.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Moq, Version=4.10.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Moq.4.10.1\lib\net45\Moq.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=3.11.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Transactions" />
|
||||
<Reference Include="System.Windows" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="TelescopeControllerUnitTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MeadeAutostar497\MeadeAutostar497.csproj">
|
||||
<Project>{64308775-bd4a-469c-bcab-3ed830b811af}</Project>
|
||||
<Name>MeadeAutostar497</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="BootstrapAscomProfileStore.ps1" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.11.0\build\NUnit.props'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("MeadeAutostar497.UnitTests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("MeadeAutostar497.UnitTests")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("9638da27-77c7-4b30-a730-6e7159a4a09f")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,556 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO.Ports;
|
||||
using ASCOM;
|
||||
using ASCOM.DeviceInterface;
|
||||
using ASCOM.MeadeAutostar497.Controller;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MeadeAutostar497.UnitTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class TelescopeControllerUnitTests
|
||||
{
|
||||
private Mock<ISerialProcessor> serialMock;
|
||||
|
||||
private readonly List<string> _availableComPorts = new List<string> { "COM1", "COM2", "COM3" };
|
||||
private TelescopeController _telescopeController;
|
||||
|
||||
private string _stringToRecieve = string.Empty;
|
||||
private bool _isConnected = false;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_stringToRecieve = string.Empty;
|
||||
_isConnected = false;
|
||||
|
||||
serialMock = new Mock<ISerialProcessor>();
|
||||
serialMock.SetupAllProperties();
|
||||
serialMock.Setup(x => x.GetPortNames()).Returns(() => _availableComPorts.ToArray());
|
||||
serialMock.Setup(x => x.CommandTerminated(It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns(() => _stringToRecieve);
|
||||
serialMock.Setup(x => x.IsOpen).Returns(() => _isConnected);
|
||||
|
||||
//Todo inject the serialMock instead of using a singleton to increase code stability.
|
||||
_telescopeController = TelescopeController.Instance;
|
||||
_telescopeController.SerialPort = serialMock.Object;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
_isConnected = false;
|
||||
_telescopeController.Connected = false;
|
||||
_telescopeController.Port = "COM1";
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ImplementsExpectedInterfaces()
|
||||
{
|
||||
Assert.That(_telescopeController, Is.Not.Null);
|
||||
Assert.That(_telescopeController, Is.AssignableTo<ITelescopeController>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NotConnectedByDefault()
|
||||
{
|
||||
Assert.That(_telescopeController.Connected, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConnectedCanBeSetTrue()
|
||||
{
|
||||
_stringToRecieve = "test#";
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
Assert.That(_telescopeController.Connected, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnsureThatTheSerialCommunicationsAreSetCorrectly()
|
||||
{
|
||||
Assert.That(serialMock.Object.IsOpen, Is.False);
|
||||
|
||||
_stringToRecieve = "test#";
|
||||
_telescopeController.Connected = true;
|
||||
_isConnected = true;
|
||||
Assert.That(_telescopeController.Connected, Is.True);
|
||||
|
||||
serialMock.Verify(x => x.Open(), Times.Once);
|
||||
|
||||
Assert.That(serialMock.Object.DtrEnable, Is.False);
|
||||
Assert.That(serialMock.Object.RtsEnable, Is.False);
|
||||
Assert.That(serialMock.Object.BaudRate, Is.EqualTo(9600));
|
||||
Assert.That(serialMock.Object.DataBits, Is.EqualTo(8));
|
||||
Assert.That(serialMock.Object.StopBits, Is.EqualTo(StopBits.One));
|
||||
Assert.That(serialMock.Object.Parity, Is.EqualTo(Parity.None));
|
||||
Assert.That(serialMock.Object.PortName, Is.EqualTo(_telescopeController.Port));
|
||||
Assert.That(serialMock.Object.IsOpen, Is.True);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenOpensComPortToNonAutostarThrowException()
|
||||
{
|
||||
Assert.That(serialMock.Object.IsOpen, Is.False);
|
||||
var exception = Assert.Throws<ASCOM.InvalidOperationException>(() => { _telescopeController.Connected = true; });
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo("Failed to communicate with telescope."));
|
||||
|
||||
Assert.That(_telescopeController.Connected, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CannotChangeSerialPortObjectWhenConnected()
|
||||
{
|
||||
_stringToRecieve = "test#";
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
Mock<ISerialProcessor> newSerialMock = new Mock<ISerialProcessor>();
|
||||
|
||||
var exception = Assert.Throws<ASCOM.InvalidOperationException>( () => { _telescopeController.SerialPort = newSerialMock.Object; });
|
||||
|
||||
Assert.That(exception, Is.Not.Null);
|
||||
Assert.That(exception.Message, Is.EqualTo("Please disconnect before changing the serial engine."));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PortIsSetToCom1ByDefault()
|
||||
{
|
||||
Assert.That(_telescopeController.Port, Is.EqualTo("COM1"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SettingPortToValidPortAllowed()
|
||||
{
|
||||
_telescopeController.Port = "COM2";
|
||||
|
||||
Assert.That(_telescopeController.Port, Is.EqualTo("COM2"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SettingPortToValidPortWhenConnectedFails()
|
||||
{
|
||||
_stringToRecieve = "test#";
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
var exception = Assert.Throws<ASCOM.InvalidOperationException>( () => _telescopeController.Port = "COM2");
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo("Please disconnect from the scope before changing port."));
|
||||
|
||||
Assert.That(_telescopeController.Port, Is.EqualTo("COM1")); //port hasn't changed
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SettingPortToInvalidPortFails()
|
||||
{
|
||||
var exception = Assert.Throws<ASCOM.InvalidOperationException>(() => _telescopeController.Port = "COM5");
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo("Unable to select port COM5 as it does not exist."));
|
||||
|
||||
Assert.That(_telescopeController.Port, Is.EqualTo("COM1")); //port hasn't changed
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AbortSlewWorks()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
_telescopeController.AbortSlew();
|
||||
|
||||
serialMock.Verify(x => x.Command("#:Q#"), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SlewingReturnTrueAsExpected()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
serialMock.Setup(x => x.CommandTerminated(":D#", "#")).Returns("|");
|
||||
|
||||
var slewing = _telescopeController.Slewing;
|
||||
|
||||
Assert.That(slewing, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SlewingReturnFalseAsExpected()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
serialMock.Setup(x => x.CommandTerminated(":D#", "#")).Returns(string.Empty);
|
||||
|
||||
var slewing = _telescopeController.Slewing;
|
||||
|
||||
Assert.That(slewing, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void utcDate_Get_ReturnsExpectedValue()
|
||||
{
|
||||
DateTime expectedDate = new DateTime(2019, 04, 30, 11, 32, 24, DateTimeKind.Local);
|
||||
|
||||
var dateString = "04/30/19";
|
||||
var timeString = "12:32:24";
|
||||
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
serialMock.Setup(x => x.CommandTerminated(":GG#", "#")).Returns("-01");
|
||||
serialMock.Setup(x => x.CommandTerminated(":GC#", "#")).Returns(dateString);
|
||||
serialMock.Setup(x => x.CommandTerminated(":GL#", "#")).Returns(timeString);
|
||||
|
||||
var result = _telescopeController.utcDate;
|
||||
|
||||
Assert.That(result, Is.EqualTo(expectedDate));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void utcDate_Set_SetsTelescopeDateAndTime()
|
||||
{
|
||||
DateTime testDateTime = new DateTime(2019, 04, 30, 19, 53, 32, DateTimeKind.Utc);
|
||||
|
||||
serialMock.Setup(x => x.CommandTerminated(":GG#", "#")).Returns("-01");
|
||||
serialMock.Setup(x => x.CommandChar($":SL{testDateTime.Hour+1:00}:{testDateTime.Minute:00}:{testDateTime.Second:00}#")).Returns('1');
|
||||
serialMock.Setup(x => x.CommandChar($":SC{testDateTime.Month:00}/{testDateTime.Day:00}/{testDateTime:yy}#")).Returns('1');
|
||||
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
_telescopeController.utcDate = testDateTime;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void utcDate_Set_ThrowsExceptionWhenTimeInvalid()
|
||||
{
|
||||
DateTime testDateTime = new DateTime(2019, 04, 30, 19, 53, 32, DateTimeKind.Utc);
|
||||
|
||||
serialMock.Setup(x => x.CommandTerminated(":GG#", "#")).Returns("-01");
|
||||
//serialMock.Setup(x => x.CommandChar($":SL{testDateTime.Hour:00}:{testDateTime.Minute:00}:{testDateTime.Second:00}#")).Returns('1');
|
||||
serialMock.Setup(x => x.CommandChar($":SC{testDateTime.Month:00}/{testDateTime.Day:00}/{testDateTime:yy}#")).Returns('1');
|
||||
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
var exception = Assert.Throws<ASCOM.InvalidOperationException>( () => {_telescopeController.utcDate = testDateTime; });
|
||||
|
||||
Assert.That( exception.Message, Is.EqualTo("Failed to set local time"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void utcDate_Set_ThrowsExceptionWhenDateInvalid()
|
||||
{
|
||||
DateTime testDateTime = new DateTime(2019, 04, 30, 19, 53, 32, DateTimeKind.Local);
|
||||
|
||||
serialMock.Setup(x => x.CommandTerminated(":GG#", "#")).Returns("-01");
|
||||
serialMock.Setup(x => x.CommandChar($":SL{testDateTime.Hour+1:00}:{testDateTime.Minute:00}:{testDateTime.Second:00}#")).Returns('1');
|
||||
//serialMock.Setup(x => x.CommandChar($":SC{testDateTime.Month:00}/{testDateTime.Day:00}/{testDateTime:yy}#")).Returns('1');
|
||||
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
var exception = Assert.Throws<ASCOM.InvalidOperationException>(() => { _telescopeController.utcDate = testDateTime; });
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo("Failed to set local date"));
|
||||
}
|
||||
|
||||
[TestCase("+12*34", 12.566666666666666)]
|
||||
[TestCase("+12*34.56", 12.582222222222223)]
|
||||
[TestCase("-67*34.56", -67.582222222222214)]
|
||||
public void SiteLatitude_Get_ReturnsExpectedDouble( string latitude, double expectedResult)
|
||||
{
|
||||
serialMock.Setup(x => x.CommandTerminated(":Gt#", "#")).Returns(latitude);
|
||||
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
var result = _telescopeController.SiteLatitude;
|
||||
|
||||
Assert.That(result, Is.EqualTo(expectedResult));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SiteLatitude_Set_ThrowsExeptionWhenValueTooSmall()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
var exception = Assert.Throws<InvalidValueException>( () => { _telescopeController.SiteLatitude = -91;});
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo("Latitude cannot be less than -90 degrees."));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SiteLatitude_Set_ThrowsExeptionWhenValueTooLarge()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
var exception = Assert.Throws<InvalidValueException>(() => { _telescopeController.SiteLatitude = 91; });
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo("Latitude cannot be greater than 90 degrees."));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SiteLatitude_Set_ThrowsExeptionWhenTelescopeReportsFail()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
var exception = Assert.Throws<ASCOM.InvalidOperationException>(() => { _telescopeController.SiteLatitude = 10; });
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo("Failed to set site latitude."));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SiteLatitude_Set_NoErrorWhenValidValueSentSuccessfully()
|
||||
{
|
||||
serialMock.Setup(x => x.CommandChar(":Sts10*00#")).Returns('1');
|
||||
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
_telescopeController.SiteLatitude = 10;
|
||||
}
|
||||
|
||||
|
||||
[TestCase("012*34", 12.566666666666666)]
|
||||
[TestCase("012:34.56", 12.582222222222223)]
|
||||
[TestCase("350:34.56", -9.4177777777777578)]
|
||||
public void SiteLongitude_Get_ReturnsExpectedDouble(string longitude, double expectedResult)
|
||||
{
|
||||
serialMock.Setup(x => x.CommandTerminated(":Gg#", "#")).Returns(longitude);
|
||||
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
var result = _telescopeController.SiteLongitude;
|
||||
|
||||
Assert.That(result, Is.EqualTo(expectedResult));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SiteLongitude_Set_ThrowsExeptionWhenValueTooSmall()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
var exception = Assert.Throws<InvalidValueException>(() => { _telescopeController.SiteLongitude = -181; });
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo("Longitude cannot be lower than -180 degrees."));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SiteLongitude_Set_ThrowsExeptionWhenValueTooLarge()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
var exception = Assert.Throws<InvalidValueException>(() => { _telescopeController.SiteLongitude = 181; });
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo("Longitude cannot be greater than 180 degrees."));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SiteLongitude_Set_ThrowsExeptionWhenTelescopeReportsFail()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
var exception = Assert.Throws<ASCOM.InvalidOperationException>(() => { _telescopeController.SiteLongitude = 10; });
|
||||
|
||||
Assert.That(exception.Message, Is.EqualTo("Failed to set site longitude."));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SiteLongitude_Set_NoErrorWhenValidValueSentSuccessfully()
|
||||
{
|
||||
serialMock.Setup(x => x.CommandChar(":Sg010*00#")).Returns('1');
|
||||
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
_telescopeController.SiteLongitude = 10;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PulseGuideEast()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
_telescopeController.PulseGuide(GuideDirections.guideEast,100);
|
||||
|
||||
serialMock.Verify( x => x.Command(":Mge0100#"), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PulseGuideWest()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
_telescopeController.PulseGuide(GuideDirections.guideWest, 1200);
|
||||
|
||||
serialMock.Verify(x => x.Command(":Mgw1200#"), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PulseGuideNorth()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
_telescopeController.PulseGuide(GuideDirections.guideNorth, 256);
|
||||
|
||||
serialMock.Verify(x => x.Command(":Mgn0256#"), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PulseGuideSouth()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
_telescopeController.PulseGuide(GuideDirections.guideSouth, 1024);
|
||||
|
||||
serialMock.Verify(x => x.Command(":Mgs1024#"), Times.Once);
|
||||
}
|
||||
|
||||
[TestCase('A', AlignmentModes.algAltAz)]
|
||||
[TestCase('P', AlignmentModes.algPolar)]
|
||||
public void AlignmentMode_Get_ReturnsExpectedValue(char commandResponse, AlignmentModes mode)
|
||||
{
|
||||
const char ack = (char)6;
|
||||
|
||||
serialMock.Setup(x => x.CommandChar(ack.ToString())).Returns(commandResponse);
|
||||
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
var result = _telescopeController.AlignmentMode;
|
||||
|
||||
Assert.That(result, Is.EqualTo(mode));
|
||||
}
|
||||
|
||||
[TestCase(AlignmentModes.algAltAz, ":AA#")]
|
||||
[TestCase(AlignmentModes.algPolar, ":AP#")]
|
||||
[TestCase(AlignmentModes.algGermanPolar, ":AP#")]
|
||||
public void AligmentMode_Set_WorksAsExpected(AlignmentModes mode, string command)
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
_telescopeController.AlignmentMode = mode;
|
||||
|
||||
serialMock.Verify( x => x.Command(command), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AtParkIsFalseByDefault()
|
||||
{
|
||||
_isConnected = true;
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
Assert.That( _telescopeController.AtPark, Is.False );
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AtParkIsTrueAfterParkingScope()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
_telescopeController.Park();
|
||||
|
||||
Assert.That(_telescopeController.AtPark, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Park_CallingParkSendsTheParkCommand()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
_telescopeController.Park();
|
||||
|
||||
serialMock.Verify( x => x.Command(":hP#"), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Park_ParkingSecondTimeDoesNothing()
|
||||
{
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
_telescopeController.Park();
|
||||
|
||||
_telescopeController.Park();
|
||||
|
||||
serialMock.Verify(x => x.Command(":hP#"), Times.Once);
|
||||
}
|
||||
|
||||
[TestCase("356*13",356.21666666666664)]
|
||||
[TestCase("356*13'21", 356.22249999999997)]
|
||||
public void Azimuth_CanGetValue( string response, double expectedResult )
|
||||
{
|
||||
serialMock.Setup(x => x.CommandTerminated(":GZ#", "#")).Returns(response);
|
||||
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
var az = _telescopeController.Azimuth;
|
||||
|
||||
Assert.That( az, Is.EqualTo(expectedResult));
|
||||
}
|
||||
|
||||
[TestCase("+75*13", 75.2166666666666654)]
|
||||
[TestCase("+65*13'21", 65.222499999999997)]
|
||||
public void Declination_CanGetValue(string response, double expectedResult)
|
||||
{
|
||||
serialMock.Setup(x => x.CommandTerminated(":GD#", "#")).Returns(response);
|
||||
|
||||
_isConnected = true;
|
||||
|
||||
_telescopeController.Connected = true;
|
||||
|
||||
var result = _telescopeController.Declination;
|
||||
|
||||
Assert.That(result, Is.EqualTo(expectedResult));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="ASCOM.Platform" version="6.4.2" targetFramework="net45" />
|
||||
<package id="Castle.Core" version="4.3.1" targetFramework="net45" />
|
||||
<package id="Moq" version="4.10.1" targetFramework="net45" />
|
||||
<package id="NUnit" version="3.11.0" targetFramework="net45" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.0" targetFramework="net45" requireReinstallation="true" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net45" requireReinstallation="true" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user