mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
improved tests for default connection info
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Connection.Protocol;
|
||||
using mRemoteNGTests.TestHelpers;
|
||||
using NUnit.Framework;
|
||||
|
||||
@@ -9,28 +8,42 @@ using NUnit.Framework;
|
||||
namespace mRemoteNGTests.Connection
|
||||
{
|
||||
public class DefaultConnectionInfoTests
|
||||
{
|
||||
{
|
||||
private ConnectionInfo _randomizedConnectionInfo;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
DefaultConnectionInfo.Instance.Domain = "";
|
||||
_randomizedConnectionInfo = ConnectionInfoHelpers.GetRandomizedConnectionInfo();
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(GetConnectionInfoProperties))]
|
||||
public void LoadingDefaultInfoUpdatesAllProperties(PropertyInfo property)
|
||||
{
|
||||
var connectionInfoSource = ConnectionInfoHelpers.GetRandomizedConnectionInfo();
|
||||
DefaultConnectionInfo.Instance.LoadFrom(connectionInfoSource);
|
||||
DefaultConnectionInfo.Instance.LoadFrom(_randomizedConnectionInfo);
|
||||
var valueInDestination = property.GetValue(DefaultConnectionInfo.Instance);
|
||||
var valueInSource = property.GetValue(connectionInfoSource);
|
||||
var valueInSource = property.GetValue(_randomizedConnectionInfo);
|
||||
Assert.That(valueInDestination, Is.EqualTo(valueInSource));
|
||||
}
|
||||
|
||||
//TODO - finish test
|
||||
//[TestCaseSource(nameof(GetInheritanceProperties))]
|
||||
public void LoadingDefaultInfoUpdatesAllInheritanceProperties(PropertyInfo property)
|
||||
{
|
||||
DefaultConnectionInfo.Instance.Inheritance.TurnOffInheritanceCompletely();
|
||||
_randomizedConnectionInfo.Inheritance.TurnOnInheritanceCompletely();
|
||||
|
||||
DefaultConnectionInfo.Instance.LoadFrom(_randomizedConnectionInfo);
|
||||
var valueInDestination = property.GetValue(DefaultConnectionInfo.Instance.Inheritance);
|
||||
var valueInSource = property.GetValue(_randomizedConnectionInfo.Inheritance);
|
||||
Assert.That(valueInDestination, Is.EqualTo(valueInSource));
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(GetConnectionInfoProperties))]
|
||||
public void SavingDefaultConnectionInfoExportsAllProperties(PropertyInfo property)
|
||||
{
|
||||
var saveTarget = new ConnectionInfo();
|
||||
var randomizedValue = property.GetValue(ConnectionInfoHelpers.GetRandomizedConnectionInfo());
|
||||
var randomizedValue = property.GetValue(_randomizedConnectionInfo);
|
||||
property.SetValue(DefaultConnectionInfo.Instance, randomizedValue);
|
||||
DefaultConnectionInfo.Instance.SaveTo(saveTarget);
|
||||
var valueInDestination = property.GetValue(saveTarget);
|
||||
@@ -38,47 +51,30 @@ namespace mRemoteNGTests.Connection
|
||||
Assert.That(valueInDestination, Is.EqualTo(valueInSource));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanSaveEnumValuesToString()
|
||||
{
|
||||
const ProtocolType targetProtocol = ProtocolType.RAW;
|
||||
var saveTarget = new AllStringPropertySaveTarget();
|
||||
DefaultConnectionInfo.Instance.Protocol = targetProtocol;
|
||||
[TestCaseSource(nameof(GetConnectionInfoProperties))]
|
||||
public void CanSaveDefaultConnectionToModelWithAllStringProperties(PropertyInfo property)
|
||||
{
|
||||
var saveTarget = new SerializableConnectionInfoAllPropertiesOfType<string>();
|
||||
|
||||
// randomize default connnection values to ensure we dont get false passing tests
|
||||
var randomizedValue = property.GetValue(_randomizedConnectionInfo);
|
||||
property.SetValue(DefaultConnectionInfo.Instance, randomizedValue);
|
||||
|
||||
DefaultConnectionInfo.Instance.SaveTo(saveTarget);
|
||||
Assert.That(saveTarget.Protocol, Is.EqualTo(targetProtocol.ToString()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanSaveIntegerValuesToString()
|
||||
{
|
||||
const int targetValue = 123;
|
||||
var saveTarget = new AllStringPropertySaveTarget();
|
||||
DefaultConnectionInfo.Instance.RDPMinutesToIdleTimeout = targetValue;
|
||||
DefaultConnectionInfo.Instance.SaveTo(saveTarget);
|
||||
Assert.That(saveTarget.RDPMinutesToIdleTimeout, Is.EqualTo(targetValue.ToString()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanSaveStringValuesToString()
|
||||
{
|
||||
const string targetName = "hello";
|
||||
var saveTarget = new AllStringPropertySaveTarget();
|
||||
DefaultConnectionInfo.Instance.Username = targetName;
|
||||
DefaultConnectionInfo.Instance.SaveTo(saveTarget);
|
||||
Assert.That(saveTarget.Username, Is.EqualTo(targetName));
|
||||
}
|
||||
|
||||
|
||||
private class AllStringPropertySaveTarget
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public string Protocol { get; set; }
|
||||
public string RDPMinutesToIdleTimeout { get; set; }
|
||||
var valueInSource = property.GetValue(DefaultConnectionInfo.Instance).ToString();
|
||||
var valueInDestination = saveTarget.GetType().GetProperty(property.Name).GetValue(saveTarget).ToString();
|
||||
Assert.That(valueInDestination, Is.EqualTo(valueInSource));
|
||||
}
|
||||
|
||||
private static IEnumerable<PropertyInfo> GetConnectionInfoProperties()
|
||||
{
|
||||
return new ConnectionInfo().GetSerializableProperties();
|
||||
}
|
||||
|
||||
private static IEnumerable<PropertyInfo> GetInheritanceProperties()
|
||||
{
|
||||
return new ConnectionInfoInheritance(new object(), true).GetProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
namespace mRemoteNGTests.TestHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// A ConnectionInfo that has only the serializable properties as string types.
|
||||
/// Only used for testing.
|
||||
/// </summary>
|
||||
internal class SerializableConnectionInfoAllPropertiesOfType<TType>
|
||||
{
|
||||
public TType Description { get; set; }
|
||||
public TType Icon { get; set; }
|
||||
public TType Panel { get; set; }
|
||||
public TType Username { get; set; }
|
||||
public TType Password { get; set; }
|
||||
public TType Domain { get; set; }
|
||||
public TType Protocol { get; set; }
|
||||
public TType ExtApp { get; set; }
|
||||
public TType PuttySession { get; set; }
|
||||
public TType ICAEncryptionStrength { get; set; }
|
||||
public TType UseConsoleSession { get; set; }
|
||||
public TType RDPAuthenticationLevel { get; set; }
|
||||
public TType RDPMinutesToIdleTimeout { get; set; }
|
||||
public TType RDPAlertIdleTimeout { get; set; }
|
||||
public TType LoadBalanceInfo { get; set; }
|
||||
public TType RenderingEngine { get; set; }
|
||||
public TType UseCredSsp { get; set; }
|
||||
public TType RDGatewayUsageMethod { get; set; }
|
||||
public TType RDGatewayHostname { get; set; }
|
||||
public TType RDGatewayUseConnectionCredentials { get; set; }
|
||||
public TType RDGatewayUsername { get; set; }
|
||||
public TType RDGatewayPassword { get; set; }
|
||||
public TType RDGatewayDomain { get; set; }
|
||||
public TType Resolution { get; set; }
|
||||
public TType AutomaticResize { get; set; }
|
||||
public TType Colors { get; set; }
|
||||
public TType CacheBitmaps { get; set; }
|
||||
public TType DisplayWallpaper { get; set; }
|
||||
public TType DisplayThemes { get; set; }
|
||||
public TType EnableFontSmoothing { get; set; }
|
||||
public TType EnableDesktopComposition { get; set; }
|
||||
public TType RedirectKeys { get; set; }
|
||||
public TType RedirectDiskDrives { get; set; }
|
||||
public TType RedirectPrinters { get; set; }
|
||||
public TType RedirectPorts { get; set; }
|
||||
public TType RedirectSmartCards { get; set; }
|
||||
public TType RedirectSound { get; set; }
|
||||
public TType SoundQuality { get; set; }
|
||||
public TType PreExtApp { get; set; }
|
||||
public TType PostExtApp { get; set; }
|
||||
public TType MacAddress { get; set; }
|
||||
public TType UserField { get; set; }
|
||||
public TType VNCCompression { get; set; }
|
||||
public TType VNCEncoding { get; set; }
|
||||
public TType VNCAuthMode { get; set; }
|
||||
public TType VNCProxyType { get; set; }
|
||||
public TType VNCProxyIP { get; set; }
|
||||
public TType VNCProxyPort { get; set; }
|
||||
public TType VNCProxyUsername { get; set; }
|
||||
public TType VNCProxyPassword { get; set; }
|
||||
public TType VNCColors { get; set; }
|
||||
public TType VNCSmartSizeMode { get; set; }
|
||||
public TType VNCViewOnly { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -174,6 +174,7 @@
|
||||
<Compile Include="TestHelpers\ConnectionTreeModelBuilder.cs" />
|
||||
<Compile Include="Security\XmlCryptoProviderBuilderTests.cs" />
|
||||
<Compile Include="TestHelpers\FileTestHelpers.cs" />
|
||||
<Compile Include="TestHelpers\SerializableConnectionInfoAllPropertiesOfType.cs" />
|
||||
<Compile Include="Tools\ExternalToolsArgumentParserTests.cs" />
|
||||
<Compile Include="Tools\FullyObservableCollectionTests.cs" />
|
||||
<Compile Include="Tools\OptionalTests.cs" />
|
||||
|
||||
Reference in New Issue
Block a user