mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Created tests for PuttyConnectionManagerDeserializer
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
using System.Linq;
|
||||
using mRemoteNG.Config.Serializers;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Connection.Protocol;
|
||||
using mRemoteNG.Container;
|
||||
using mRemoteNGTests.Properties;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
||||
namespace mRemoteNGTests.Config.Serializers
|
||||
{
|
||||
public class PuttyConnectionManagerDeserializerTests
|
||||
{
|
||||
private PuttyConnectionManagerDeserializer _deserializer;
|
||||
private ContainerInfo _rootImportedFolder;
|
||||
private const string ExpectedRootFolderName = "test_puttyConnectionManager_database";
|
||||
private const string ExpectedConnectionDisplayName = "my ssh connection";
|
||||
private const string ExpectedConnectionHostname = "server1.mydomain.com";
|
||||
private const string ExpectedConnectionDescription = "My Description Here";
|
||||
private const int ExpectedConnectionPort = 22;
|
||||
private const ProtocolType ExpectedProtocolType = ProtocolType.SSH2;
|
||||
private const string ExpectedPuttySession = "MyCustomPuttySession";
|
||||
private const string ExpectedConnectionUsername = "mysshusername";
|
||||
private const string ExpectedConnectionPassword = "password123";
|
||||
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OnetimeSetup()
|
||||
{
|
||||
var fileContents = Resources.test_puttyConnectionManager_database;
|
||||
_deserializer = new PuttyConnectionManagerDeserializer(fileContents);
|
||||
var connectionTreeModel = _deserializer.Deserialize();
|
||||
var rootNode = connectionTreeModel.RootNodes.First();
|
||||
_rootImportedFolder = rootNode.Children.Cast<ContainerInfo>().First();
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void OnetimeTeardown()
|
||||
{
|
||||
_deserializer = null;
|
||||
_rootImportedFolder = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RootFolderImportedWithCorrectName()
|
||||
{
|
||||
Assert.That(_rootImportedFolder.Name, Is.EqualTo(ExpectedRootFolderName));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConnectionDisplayNameImported()
|
||||
{
|
||||
var connection = GetSshConnection();
|
||||
Assert.That(connection.Name, Is.EqualTo(ExpectedConnectionDisplayName));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConnectionHostNameImported()
|
||||
{
|
||||
var connection = GetSshConnection();
|
||||
Assert.That(connection.Hostname, Is.EqualTo(ExpectedConnectionHostname));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConnectionDescriptionImported()
|
||||
{
|
||||
var connection = GetSshConnection();
|
||||
Assert.That(connection.Description, Is.EqualTo(ExpectedConnectionDescription));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConnectionPortImported()
|
||||
{
|
||||
var connection = GetSshConnection();
|
||||
Assert.That(connection.Port, Is.EqualTo(ExpectedConnectionPort));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConnectionProtocolTypeImported()
|
||||
{
|
||||
var connection = GetSshConnection();
|
||||
Assert.That(connection.Protocol, Is.EqualTo(ExpectedProtocolType));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConnectionPuttySessionImported()
|
||||
{
|
||||
var connection = GetSshConnection();
|
||||
Assert.That(connection.PuttySession, Is.EqualTo(ExpectedPuttySession));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConnectionUsernameImported()
|
||||
{
|
||||
var connection = GetSshConnection();
|
||||
Assert.That(connection.Username, Is.EqualTo(ExpectedConnectionUsername));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConnectionPasswordImported()
|
||||
{
|
||||
var connection = GetSshConnection();
|
||||
Assert.That(connection.Password, Is.EqualTo(ExpectedConnectionPassword));
|
||||
}
|
||||
|
||||
private ConnectionInfo GetSshConnection()
|
||||
{
|
||||
var sshFolder = _rootImportedFolder.Children.OfType<ContainerInfo>().First(node => node.Name == "SSHFolder");
|
||||
return sshFolder.Children.First();
|
||||
}
|
||||
}
|
||||
}
|
||||
16
mRemoteNGTests/Properties/Resources.Designer.cs
generated
16
mRemoteNGTests/Properties/Resources.Designer.cs
generated
@@ -60,6 +60,22 @@ namespace mRemoteNGTests.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to <?xml version="1.0" encoding="utf-16"?>
|
||||
///<!-- ****************************************************************-->
|
||||
///<!-- * *-->
|
||||
///<!-- * PuTTY Configuration Manager save file - All right reserved. *-->
|
||||
///<!-- * *-->
|
||||
///<!-- ****************************************************************-->
|
||||
///<!-- The following lines can be modified at your own risks. -->
|
||||
///<configuration version="0.7.1.136" [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string test_puttyConnectionManager_database {
|
||||
get {
|
||||
return ResourceManager.GetString("test_puttyConnectionManager_database", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to <?xml version="1.0" encoding="utf-8"?>
|
||||
///<RDCMan schemaVersion="1">
|
||||
|
||||
@@ -121,6 +121,9 @@
|
||||
<data name="TestConfCons" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\TestConfCons.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
||||
</data>
|
||||
<data name="test_puttyConnectionManager_database" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\test_puttyConnectionManager_database.dat;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16</value>
|
||||
</data>
|
||||
<data name="test_rdcman_badVersionNumber" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\test_rdcman_badVersionNumber.rdg;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
|
||||
</data>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -109,6 +109,7 @@
|
||||
<Compile Include="BinaryFileTests.cs" />
|
||||
<Compile Include="Config\Serializers\DataTableSerializerTests.cs" />
|
||||
<Compile Include="Config\Serializers\PortScanDeserializerTests.cs" />
|
||||
<Compile Include="Config\Serializers\PuttyConnectionManagerDeserializerTests.cs" />
|
||||
<Compile Include="Config\Serializers\XmlConnectionsDeserializerTests.cs" />
|
||||
<Compile Include="Config\Serializers\RemoteDesktopConnectionDeserializerTests.cs" />
|
||||
<Compile Include="Config\Serializers\RemoteDesktopConnectionManagerDeserializerTests.cs" />
|
||||
@@ -167,6 +168,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Resources\TestConfCons.xml" />
|
||||
<None Include="Resources\test_puttyConnectionManager_database.dat" />
|
||||
<None Include="Resources\test_rdcman_badVersionNumber.rdg" />
|
||||
<None Include="Resources\test_rdcman_noversion.rdg" />
|
||||
<None Include="Resources\test_rdcman_v2_2_badschemaversion.rdg" />
|
||||
|
||||
@@ -62,8 +62,6 @@ namespace mRemoteNG.Config.Serializers
|
||||
throw (new FileFormatException($"Unrecognized child node ({childNode.Name})."));
|
||||
}
|
||||
}
|
||||
|
||||
Runtime.ContainerList.Add(newContainer);
|
||||
}
|
||||
|
||||
private void VerifyNodeType(XmlNode xmlNode)
|
||||
@@ -108,8 +106,6 @@ namespace mRemoteNG.Config.Serializers
|
||||
|
||||
var connectionInfo = ConnectionInfoFromXml(connectionNode);
|
||||
parentContainer.AddChild(connectionInfo);
|
||||
|
||||
Runtime.ConnectionList.Add(connectionInfo);
|
||||
}
|
||||
|
||||
private ConnectionInfo ConnectionInfoFromXml(XmlNode xmlNode)
|
||||
@@ -129,7 +125,7 @@ namespace mRemoteNG.Config.Serializers
|
||||
connectionInfo.Protocol = ProtocolType.SSH2;
|
||||
break;
|
||||
default:
|
||||
throw (new FileFormatException($"Unrecognized protocol ({protocol})."));
|
||||
throw new FileFormatException($"Unrecognized protocol ({protocol}).");
|
||||
}
|
||||
|
||||
connectionInfo.Hostname = connectionInfoNode.SelectSingleNode("./host")?.InnerText;
|
||||
|
||||
Reference in New Issue
Block a user