Removing all unnecessary old files

This commit is contained in:
xRushG
2024-06-11 09:07:04 +02:00
parent 08eb35a360
commit 8b3a68f58e
11 changed files with 0 additions and 1743 deletions

View File

@@ -1,188 +0,0 @@
using Microsoft.Win32;
using mRemoteNG.Tools.WindowsRegistry;
using NUnit.Framework;
namespace mRemoteNGTests.Tools.Registry
{
internal class WindowsRegistryAdvancedTests : WindowsRegistryAdvanced
{
private const string _TestRootKey = @"Software\mRemoteNGTest";
private const RegistryHive _TestHive = RegistryHive.CurrentUser;
[SetUp]
public void Setup()
{
// GetBoolean && GetBoolValue (GetBoolValue -> Not Advanced but not tested jet)
SetRegistryValue(_TestHive, _TestRootKey, "TestBoolAsString", "true", RegistryValueKind.String);
SetRegistryValue(_TestHive, _TestRootKey, "TestBoolAsDWord", 0, RegistryValueKind.DWord);
// GetInteger Tests
SetRegistryValue(_TestHive, _TestRootKey, "TestInteger", "4711", RegistryValueKind.DWord);
// GetString Tests
SetRegistryValue(_TestHive, _TestRootKey, "TestString1", "Banane", RegistryValueKind.String);
SetRegistryValue(_TestHive, _TestRootKey, "TestString2", "Hund", RegistryValueKind.String);
}
[TearDown]
public void Cleanup()
{
// Delete the registry keys here
DeleteRegistryKey(_TestHive, _TestRootKey, true);
}
#region GetBoolean() Tests
// Non object returns
[Test]
public void GetBooleanFromString_ReturnsTrue()
{
var key = GetBoolean(_TestHive, _TestRootKey, "TestBoolAsString");
Assert.That(key.Value, Is.EqualTo(true));
}
[Test]
public void GetBooleanFromDword_ReturnsFalse()
{
var key = GetBoolean(_TestHive, _TestRootKey, "TestBoolAsDWord");
Assert.That(key.Value, Is.EqualTo(false));
}
[Test]
public void GetBooleanNotProvided_ReturnsDefaultTrue()
{
var key = GetBoolean(_TestHive, _TestRootKey, "TestBoolNotProvided", true);
Assert.Multiple(() =>
{
Assert.That(key.Value, Is.EqualTo(true), "Value should be the default (true)");
Assert.That(key.IsKeyPresent, Is.EqualTo(false), "IsProvided should be false");
});
}
#endregion
#region GetBoolValue()___No Object, just bool value returns
[Test]
public void GetBoolValueFromString_ReturnsTrue()
{
var key = GetBoolValue(_TestHive, _TestRootKey, "TestBoolAsString");
Assert.That(key, Is.EqualTo(true));
}
[Test]
public void GetBoolValueFromDword_ReturnsFalse()
{
var key = GetBoolValue(_TestHive, _TestRootKey, "TestBoolAsDWord", true);
Assert.That(key, Is.EqualTo(false));
}
[Test]
public void GetBoolValue_ReturnsDefaultTrue()
{
var key = GetBoolValue(_TestHive, _TestRootKey, "TestBoolNotProvided", true);
Assert.That(key, Is.EqualTo(true));
}
#endregion
#region GetInteger()
[Test]
public void GetInteger()
{
var key = GetInteger(_TestHive, _TestRootKey, "TestInteger");
Assert.Multiple(() =>
{
Assert.That(key.Value, Is.EqualTo(4711));
Assert.That(key.IsKeyPresent, Is.EqualTo(true));
});
}
[Test]
public void GetInteger_returnObjectDefault()
{
var key = GetInteger(_TestHive, _TestRootKey, "TestIntegerNotProvided");
Assert.Multiple(() =>
{
Assert.That(key.Value, Is.EqualTo(-1), "Value should be the default (-1)");
Assert.That(key.IsKeyPresent, Is.EqualTo(false));
});
}
[Test]
public void GetInteger_returnSpecifiedDefault()
{
var key = GetInteger(_TestHive, _TestRootKey, "TestIntegerNotProvided", 2096);
Assert.Multiple(() =>
{
Assert.That(key.Value, Is.EqualTo(-1), "Value should be the default (-1)");
Assert.That(key.IsKeyPresent, Is.EqualTo(false));
});
}
[Test]
public void GetDwordValue_returnIntegerValue()
{
int value = GetDwordValue(_TestHive, _TestRootKey, "TestInteger");
Assert.That(value, Is.EqualTo(4711));
}
#endregion
#region GetString()
[Test]
public void GetString()
{
var key = GetString(_TestHive, _TestRootKey, "TestString1");
Assert.Multiple(() =>
{
Assert.That(key.Value, Is.EqualTo("Banane"));
Assert.That(key.IsKeyPresent, Is.EqualTo(true));
});
}
[Test]
public void GetString_ReturnsDefault()
{
var key = GetString(_TestHive, _TestRootKey, "TestStringNotProvided", "Banane");
Assert.Multiple(() =>
{
Assert.That(key.Value, Is.EqualTo("Banane"));
Assert.That(key.IsKeyPresent, Is.EqualTo(false));
});
}
[Test]
public void GetStringValidated_Valid()
{
string[] fruits = { "Banane", "Erdbeere", "Apfel" };
var key = GetStringValidated(_TestHive, _TestRootKey, "TestString1", fruits);
Assert.Multiple(() =>
{
Assert.That(key.Value, Is.EqualTo("Banane"));
Assert.That(key.IsKeyPresent, Is.EqualTo(true));
Assert.That(key.IsValid, Is.EqualTo(true));
});
}
[Test]
public void GetStringValidated_NotValidNull()
{
string[] fruits = { "Banane", "Erdbeere", "Apfel" };
var key = GetStringValidated(_TestHive, _TestRootKey, "TestString2", fruits);
Assert.Multiple(() =>
{
Assert.That(key.Value, Is.EqualTo(null));
Assert.That(key.IsKeyPresent, Is.EqualTo(true));
Assert.That(key.IsValid, Is.EqualTo(false));
});
}
[Test]
public void GetStringValidated_NotValidDefault()
{
string[] fruits = { "Banane", "Erdbeere", "Apfel" };
var key = GetStringValidated(_TestHive, _TestRootKey, "TestString2", fruits, false, "Banane");
Assert.Multiple(() =>
{
Assert.That(key.Value, Is.EqualTo("Banane"));
Assert.That(key.IsKeyPresent, Is.EqualTo(true));
Assert.That(key.IsValid, Is.EqualTo(false));
});
}
#endregion
}
}

View File

@@ -1,386 +0,0 @@
using Microsoft.Win32;
using mRemoteNG.Tools.WindowsRegistry;
using NUnit.Framework;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;
namespace mRemoteNGTests.Tools.Registry
{
internal class WindowsRegistryKeyTests
{
private WindowsRegistryKey CompleteRegistryKey { get; set; }
private WindowsRegistryKey PartialRegistryKey { get; set; }
[SetUp]
public void Setup()
{
CompleteRegistryKey = new WindowsRegistryKey()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.String,
Name = "Test",
Path = @"SOFTWARE\TEST\TEST\Test",
Value = "CompleteRegistryKey"
};
PartialRegistryKey = new WindowsRegistryKey()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.DWord,
};
}
#region WindowsRegistryKey() tests
[Test]
public void WindowsRegistryKeyReadable()
{
Assert.That(CompleteRegistryKey.IsKeyReadable, Is.EqualTo(true));
}
[Test]
public void WindowsRegistryKeyNotReadable()
{
Assert.That(PartialRegistryKey.IsKeyReadable, Is.EqualTo(false));
}
[Test]
public void WindowsRegistryKeyWriteable()
{
Assert.That(CompleteRegistryKey.IsKeyWritable, Is.EqualTo(true));
}
[Test]
public void WindowsRegistryKeyNotWriteable()
{
Assert.That(PartialRegistryKey.IsKeyWritable, Is.EqualTo(false));
}
[Test]
public void WindowsRegistryKeyProvided()
{
Assert.That(CompleteRegistryKey.IsKeyPresent, Is.EqualTo(true));
}
[Test]
public void WindowsRegistryKeyNotProvided()
{
Assert.That(PartialRegistryKey.IsKeyPresent, Is.EqualTo(false));
}
#endregion
#region WindowsRegistryKeyBoolean tests
[Test]
public void WindowsRegistryKeyBoolean_FromStringTrue()
{
WindowsRegistryKey TestKey = new()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.String,
Name = "TestBoolString",
Path = @"SOFTWARE\Test",
Value = "true"
};
WindowsRegistryKeyBoolean boolKey = new ();
boolKey.ConvertFromWindowsRegistryKey(TestKey);
Assert.That(boolKey.IsKeyPresent, Is.EqualTo(true));
Assert.That(boolKey.Value, Is.EqualTo(true));
}
[Test]
public void WindowsRegistryKeyBoolean_FromStringFalse()
{
WindowsRegistryKey TestKey = new()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.String,
Name = "TestBoolString",
Path = @"SOFTWARE\Test",
Value = "false"
};
WindowsRegistryKeyBoolean boolKey = new();
boolKey.ConvertFromWindowsRegistryKey(TestKey);
Assert.That(boolKey.IsKeyPresent, Is.EqualTo(true));
Assert.That(boolKey.Value, Is.EqualTo(false));
}
[Test]
public void WindowsRegistryKeyBoolean_FromDwordTrue()
{
WindowsRegistryKey TestKey = new()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.DWord,
Name = "TestBoolString",
Path = @"SOFTWARE\Test",
Value = "1"
};
WindowsRegistryKeyBoolean boolKey = new();
boolKey.ConvertFromWindowsRegistryKey(TestKey);
Assert.That(boolKey.IsKeyPresent, Is.EqualTo(true));
Assert.That(boolKey.Value, Is.EqualTo(true));
}
[Test]
public void WindowsRegistryKeyBoolean_FromDwordFalse()
{
WindowsRegistryKey TestKey = new()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.DWord,
Name = "TestBoolString",
Path = @"SOFTWARE\Test",
Value = "0"
};
WindowsRegistryKeyBoolean boolKey = new();
boolKey.ConvertFromWindowsRegistryKey(TestKey);
Assert.That(boolKey.IsKeyPresent, Is.EqualTo(true));
Assert.That(boolKey.Value, Is.EqualTo(false));
}
[Test]
public void WindowsRegistryKeyBoolean_ReturnDefault()
{
WindowsRegistryKey TestKey = new()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.DWord,
Name = "TestBoolString",
Path = @"SOFTWARE\Test",
Value = null
};
WindowsRegistryKeyBoolean boolKey = new();
boolKey.ConvertFromWindowsRegistryKey(TestKey, true);
Assert.That(boolKey.IsKeyPresent, Is.EqualTo(false));
Assert.That(boolKey.Value, Is.EqualTo(true));
}
#endregion
#region WindowsRegistryKeyInteger tests
[Test]
public void WindowsRegistryKeyInteger()
{
WindowsRegistryKey TestKey = new()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.DWord,
Name = "TestIntigerString",
Path = @"SOFTWARE\Test",
Value = "4711"
};
WindowsRegistryKeyInteger IntKey = new();
IntKey.ConvertFromWindowsRegistryKey(TestKey);
Assert.That(IntKey.IsKeyPresent, Is.EqualTo(true));
Assert.That(IntKey.Value, Is.EqualTo(4711));
}
[Test]
public void WindowsRegistryKeyInteger_ReturnDefault()
{
WindowsRegistryKey TestKey = new()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.DWord,
Name = "TestIntigerString",
Path = @"SOFTWARE\Test",
Value = null
};
WindowsRegistryKeyInteger IntKey = new();
IntKey.ConvertFromWindowsRegistryKey(TestKey, 2096);
Assert.That(IntKey.IsKeyPresent, Is.EqualTo(false));
Assert.That(IntKey.Value, Is.EqualTo(2096));
}
#endregion
#region WindowsRegistryKeyString tests
[Test]
public void WindowsRegistryKeyString()
{
WindowsRegistryKey TestKey = new()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.DWord,
Name = "TestRegString",
Path = @"SOFTWARE\Test",
Value = "The Big Bang Theory"
};
WindowsRegistryKeyString StrKey = new();
StrKey.ConvertFromWindowsRegistryKey(TestKey);
Assert.That(StrKey.IsKeyPresent, Is.EqualTo(true));
Assert.That(StrKey.Value, Is.EqualTo("The Big Bang Theory"));
}
[Test]
public void WindowsRegistryKeyString_ReturnDefault()
{
WindowsRegistryKey TestKey = new()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.DWord,
Name = "TestRegString",
Path = @"SOFTWARE\Test",
Value = null
};
WindowsRegistryKeyString StrKey = new();
StrKey.ConvertFromWindowsRegistryKey(TestKey, "South Park");
Assert.That(StrKey.IsKeyPresent, Is.EqualTo(false));
Assert.That(StrKey.Value, Is.EqualTo("South Park"));
}
[Test]
public void WindowsRegistryKeyString_ValidateSuccess()
{
WindowsRegistryKey TestKey = new()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.DWord,
Name = "TestRegString",
Path = @"SOFTWARE\Test",
Value = "Big Bang"
};
WindowsRegistryKeyString StrKey = new()
{
AllowedValues = new[] { "Big Bang", "Big Bang Theory", "The Big Bang Theory" }
};
StrKey.ConvertFromWindowsRegistryKey(TestKey);
Assert.That(StrKey.IsKeyPresent, Is.EqualTo(true));
Assert.That(StrKey.IsValid, Is.EqualTo(true));
}
[Test]
public void WindowsRegistryKeyString_ValidateNotSuccess()
{
WindowsRegistryKey TestKey = new()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.DWord,
Name = "TestRegString",
Path = @"SOFTWARE\Test",
Value = "ig ang"
};
WindowsRegistryKeyString StrKey = new()
{
AllowedValues = new[] { "Big Bang", "Big Bang Theory", "The Big Bang Theory" }
};
StrKey.ConvertFromWindowsRegistryKey(TestKey);
Assert.That(StrKey.IsKeyPresent, Is.EqualTo(true));
Assert.That(StrKey.IsValid, Is.EqualTo(false));
}
[Test]
public void WindowsRegistryKeyString_ValidateSuccessCase()
{
WindowsRegistryKey TestKey = new()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.DWord,
Name = "TestRegString",
Path = @"SOFTWARE\Test",
Value = "BiG BAng"
};
WindowsRegistryKeyString StrKey = new()
{
AllowedValues = new[] { "BiG BAng", "Big Bang Theory", "The Big Bang Theory" },
IsCaseSensitiveValidation = true
};
StrKey.ConvertFromWindowsRegistryKey(TestKey);
Assert.That(StrKey.IsKeyPresent, Is.EqualTo(true));
Assert.That(StrKey.IsValid, Is.EqualTo(true));
}
[Test]
public void WindowsRegistryKeyString_ValidateNotSuccessCase()
{
WindowsRegistryKey TestKey = new()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.DWord,
Name = "TestRegString",
Path = @"SOFTWARE\Test",
Value = "BiG BAng"
};
WindowsRegistryKeyString StrKey = new()
{
AllowedValues = new[] { "Big Bang", "Big Bang Theory", "The Big Bang Theory" },
IsCaseSensitiveValidation = true
};
StrKey.ConvertFromWindowsRegistryKey(TestKey);
Assert.That(StrKey.IsKeyPresent, Is.EqualTo(true));
Assert.That(StrKey.IsValid, Is.EqualTo(false));
}
[Test]
public void WindowsRegistryKeyString_ValidateNotSuccessReturnNull()
{
WindowsRegistryKey TestKey = new()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.DWord,
Name = "TestRegString",
Path = @"SOFTWARE\Test",
Value = "ig ang"
};
WindowsRegistryKeyString StrKey = new()
{
AllowedValues = new[] { "Big Bang", "Big Bang Theory", "The Big Bang Theory" }
};
StrKey.ConvertFromWindowsRegistryKey(TestKey);
Assert.That(StrKey.IsKeyPresent, Is.EqualTo(true));
Assert.That(StrKey.IsValid, Is.EqualTo(false));
Assert.That(StrKey.Value, Is.EqualTo(null));
}
[Test]
public void WindowsRegistryKeyString_ValidateNotSuccessValidValue()
{
WindowsRegistryKey TestKey = new()
{
Hive = RegistryHive.CurrentUser,
ValueKind = RegistryValueKind.DWord,
Name = "TestRegString",
Path = @"SOFTWARE\Test",
Value = "ig ang"
};
WindowsRegistryKeyString StrKey = new()
{
AllowedValues = new[] { "Big Bang", "Big Bang Theory", "The Big Bang Theory" }
};
StrKey.ConvertFromWindowsRegistryKey(TestKey, "Big Bang Theory");
Assert.That(StrKey.IsKeyPresent, Is.EqualTo(true));
Assert.That(StrKey.IsValid, Is.EqualTo(false));
Assert.That(StrKey.Value, Is.EqualTo("Big Bang Theory"));
}
#endregion
}
}