Created tests for PuttyConnectionManagerDeserializer

This commit is contained in:
David Sparer
2016-09-25 14:01:43 -06:00
parent c4c255d560
commit ddfbb1d42e
7 changed files with 134 additions and 5 deletions

View File

@@ -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();
}
}
}

View File

@@ -60,6 +60,22 @@ namespace mRemoteNGTests.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;
///&lt;!-- ****************************************************************--&gt;
///&lt;!-- * *--&gt;
///&lt;!-- * PuTTY Configuration Manager save file - All right reserved. *--&gt;
///&lt;!-- * *--&gt;
///&lt;!-- ****************************************************************--&gt;
///&lt;!-- The following lines can be modified at your own risks. --&gt;
///&lt;configuration version=&quot;0.7.1.136&quot; [rest of string was truncated]&quot;;.
/// </summary>
internal static string test_puttyConnectionManager_database {
get {
return ResourceManager.GetString("test_puttyConnectionManager_database", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
///&lt;RDCMan schemaVersion=&quot;1&quot;&gt;

View File

@@ -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>

View File

@@ -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" />

View File

@@ -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;