diff --git a/mRemoteNGTests/TestHelpers/ConnectionInfoHelpers.cs b/mRemoteNGTests/TestHelpers/ConnectionInfoHelpers.cs index d920923bc..9014ace65 100644 --- a/mRemoteNGTests/TestHelpers/ConnectionInfoHelpers.cs +++ b/mRemoteNGTests/TestHelpers/ConnectionInfoHelpers.cs @@ -1,94 +1,17 @@ -using System; -using mRemoteNG.Connection; -using mRemoteNG.Connection.Protocol; -using mRemoteNG.Connection.Protocol.Http; -using mRemoteNG.Connection.Protocol.ICA; -using mRemoteNG.Connection.Protocol.RDP; -using mRemoteNG.Connection.Protocol.VNC; +using mRemoteNG.Connection; +using mRemoteNG.Container; namespace mRemoteNGTests.TestHelpers { - internal static class ConnectionInfoHelpers + internal static class ConnectionInfoHelpers { - private static readonly Random _random = new Random(); - /// /// Returns a object with randomized /// values in all fields. /// internal static ConnectionInfo GetRandomizedConnectionInfo(bool randomizeInheritance = false) { - var connectionInfo = new ConnectionInfo - { - // string types - Name = RandomString(), - Hostname = RandomString(), - Description = RandomString(), - Domain = RandomString(), - ExtApp = RandomString(), - Icon = RandomString(), - LoadBalanceInfo = RandomString(), - MacAddress = RandomString(), - Panel = RandomString(), - Password = RandomString(), - PostExtApp = RandomString(), - PreExtApp = RandomString(), - PuttySession = RandomString(), - RDGatewayHostname = RandomString(), - RDGatewayUsername = RandomString(), - RDGatewayDomain = RandomString(), - RDGatewayPassword = RandomString(), - UserField = RandomString(), - Username = RandomString(), - VNCProxyIP = RandomString(), - VNCProxyPassword = RandomString(), - VNCProxyUsername = RandomString(), - - // bool types - AutomaticResize = RandomBool(), - CacheBitmaps = RandomBool(), - DisplayThemes = RandomBool(), - DisplayWallpaper = RandomBool(), - EnableDesktopComposition = RandomBool(), - EnableFontSmoothing = RandomBool(), - IsContainer = RandomBool(), - IsDefault = RandomBool(), - IsQuickConnect = RandomBool(), - PleaseConnect = RandomBool(), - RDPAlertIdleTimeout = RandomBool(), - RedirectDiskDrives = RandomBool(), - RedirectKeys = RandomBool(), - RedirectPorts = RandomBool(), - RedirectPrinters = RandomBool(), - RedirectSmartCards = RandomBool(), - UseConsoleSession = RandomBool(), - UseCredSsp = RandomBool(), - VNCViewOnly = RandomBool(), - Favorite = RandomBool(), - - // ints - Port = RandomInt(), - RDPMinutesToIdleTimeout = RandomInt(), - VNCProxyPort = RandomInt(), - - // enums - Colors = RandomEnum(), - ICAEncryptionStrength = RandomEnum (), - Protocol = RandomEnum(), - RDGatewayUsageMethod = RandomEnum(), - RDGatewayUseConnectionCredentials = RandomEnum(), - RDPAuthenticationLevel = RandomEnum(), - RedirectSound = RandomEnum(), - RenderingEngine = RandomEnum(), - Resolution = RandomEnum(), - SoundQuality = RandomEnum(), - VNCAuthMode = RandomEnum(), - VNCColors = RandomEnum(), - VNCCompression = RandomEnum(), - VNCEncoding = RandomEnum(), - VNCProxyType = RandomEnum(), - VNCSmartSizeMode = RandomEnum(), - }; + var connectionInfo = new ConnectionInfo().RandomizeValues(); if (randomizeInheritance) connectionInfo.Inheritance = GetRandomizedInheritance(connectionInfo); @@ -96,38 +19,24 @@ namespace mRemoteNGTests.TestHelpers return connectionInfo; } + internal static ContainerInfo GetRandomizedContainerInfo(bool randomizeInheritance = false) + { + var containerInfo = new ContainerInfo().RandomizeValues(); + + if (randomizeInheritance) + containerInfo.Inheritance = GetRandomizedInheritance(containerInfo); + + return containerInfo; + } + internal static ConnectionInfoInheritance GetRandomizedInheritance(ConnectionInfo parent) { var inheritance = new ConnectionInfoInheritance(parent, true); foreach (var property in inheritance.GetProperties()) { - property.SetValue(inheritance, RandomBool()); + property.SetValue(inheritance, Randomizer.RandomBool()); } return inheritance; } - - internal static string RandomString() - { - return Guid.NewGuid().ToString("N"); - } - - internal static bool RandomBool() - { - return _random.Next() % 2 == 0; - } - - internal static int RandomInt() - { - return _random.Next(); - } - - internal static T RandomEnum() where T : struct, IConvertible - { - if (!typeof(T).IsEnum) - throw new ArgumentException("T must be an enum"); - - var values = Enum.GetValues(typeof(T)); - return (T)values.GetValue(_random.Next(values.Length)); - } } }