public void SetUp() { // When running a test, use the in-memory registry. Let the ComAdmin APIs know to use this instance instead // of the default WindowsRegistry. _registry = new InMemoryRegistry(); ComAdmin.SetRegistryImplementation(_registry); }
public void Get_Returns_Null_For_Missing_Extensions() { // Given an empty registry, we should return null for the class of any extension. var registry = new InMemoryRegistry(); var className = FileExtensionClass.Get(registry.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Default), ".some_type", false); Assert.That(className, Is.Null); }
public void Can_Create_Deep_SubKey() { var registry = new InMemoryRegistry(); using var key = registry.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64); var subkey = key.OpenSubKey(@"Deep\Subkey"); Assert.That(subkey, Is.Null); }
public void Open_SubKey_Returns_Null_For_Missing_Keys() { var registry = new InMemoryRegistry(); using var key = registry.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64); var subkey = key.OpenSubKey("Missing"); Assert.That(subkey, Is.Null); }
public LiveCamRegistryTests() { persistenceRegistry = new InMemoryRegistry <LiveCamEntity>(); InMemoryRegistry <LiveCamEntity> builtinLiveCamRegistry = new InMemoryRegistry <LiveCamEntity>(); liveCamRegistry = new LiveCamRegistry( persistenceRegistry, builtinLiveCamRegistry ); }
public void Can_Get_And_Set_Default_Values() { // Bounce a default value, which has slightly different treatment in the code. var registry = new InMemoryRegistry(); using var key = registry.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64); key.SetValue(null, @"Default"); Assert.That(key.GetValue(null), Is.EqualTo(@"Default")); Assert.That(key.GetValue(null, "(This is used if missing)"), Is.EqualTo(@"Default")); }
public void ZoneNoZoneInformationReturnsProtected() { if (!OperatingSystem.IsWindows()) { return; } var registry = new InMemoryRegistry(); Assert.IsTrue(new Zone(2, registry).IsProtected); }
public void Can_assert_structure() { // Create an in-memory registry, with a given structure. var registry = new InMemoryRegistry(); registry.AddStructure(RegistryView.Registry32, @"HKEY_CLASSES_ROOT .myp (Default) = MyProgram.1 CLSID {00000000-1111-2222-3333-444444444444} InProcServer32 (Default) = C:\MyDir\MyCommand.dll ThreadingModel = Apartment {11111111-2222-3333-4444-555555555555} InProcServer32 (Default) = C:\MyDir\MyPropSheet.dll ThreadingModel = Apartment MyProgram.1 (Default) = MyProgram Application ShellEx ContextMenuHandler MyCommand (Default) = {00000000-1111-2222-3333-444444444444} PropertySheetHandlers MyPropSheet (Default) = {11111111-2222-3333-4444-555555555555}"); var print = registry.Print(RegistryView.Registry32); Assert.That(print, Is.EqualTo( @"HKEY_CLASSES_ROOT .myp (Default) = MyProgram.1 CLSID {00000000-1111-2222-3333-444444444444} InProcServer32 (Default) = C:\MyDir\MyCommand.dll ThreadingModel = Apartment {11111111-2222-3333-4444-555555555555} InProcServer32 (Default) = C:\MyDir\MyPropSheet.dll ThreadingModel = Apartment MyProgram.1 (Default) = MyProgram Application ShellEx ContextMenuHandler MyCommand (Default) = {00000000-1111-2222-3333-444444444444} PropertySheetHandlers MyPropSheet (Default) = {11111111-2222-3333-4444-555555555555}")); }
public void ZoneListFactoryCreateTest() { var registry = new InMemoryRegistry(); var zoneListFactory = new ZoneListFactory(registry); var zoneList = zoneListFactory.CreateZoneList(); Assert.AreEqual(4, zoneList.Count, "count is 4"); var index = 1; foreach (var zone in zoneList) { Assert.AreEqual(index++, zone.Id); var expectedItemsList = new[] { string.Empty, "Machine Policies", "User Policies", "User", "Machine" }; Assert.IsTrue(expectedItemsList.Contains(zone.FoundIn), "[" + zone.FoundIn + " not found"); } }
[TestCase(".")] // no actual extension public void Invalid_Exceptions_Throw_On_Get(string extension) { try { var registry = new InMemoryRegistry(); FileExtensionClass.Get(registry.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Default), extension, false); Assert.Fail($@"An exception should be thrown for extension '{extension}'"); } catch (Exception exception) { // We should have an exception which includes the invalid extension in the message. if (!string.IsNullOrEmpty(extension)) { Assert.That(exception.Message, Contains.Substring(extension)); } } }
public async void ReadTest() { InMemoryRegistry registry = new InMemoryRegistry(); ServiceCollection services = TestUtil.GetTestServices(); services.ReplaceSingleton <IRegistry>(p => registry); IServiceProvider serviceProvider = services.BuildServiceProvider(); Solutions sr = Solutions.FromFile(serviceProvider, TestUtil.GetLocalFile("../test-solutions.json5")); // Test reading, with some values set string input = @"HKEY_CURRENT_USER test path settingOne = abc settingTwo = xyz"; registry.AddStructure(RegistryView.Default, input); (string settingId, object?expect)[] tests =
public void ZoneInitialProtectedModeTest(string testId, object hklmPoliciesValue, object hkcuPoliciesValue, object hkcuValue, object hklmValue, bool expectedProtected) { if (!OperatingSystem.IsWindows()) { return; } var registry = new InMemoryRegistry(); var hkcu = registry.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default); var hklm = registry.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default); AddValue(hklm, true, hklmPoliciesValue); AddValue(hklm, false, hklmValue); AddValue(hkcu, true, hkcuPoliciesValue); AddValue(hkcu, false, hkcuValue); var zone = new Zone(1, registry); Assert.AreEqual(expectedProtected, zone.IsProtected, testId); }
public void Can_Print_Simple_Structure() { // Create an in-memory registry, some simple structure. var registry = new InMemoryRegistry(); using (var key = registry.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64)) { var user = key.CreateSubKey("User"); user.SetValue("Name", "Dave"); user.SetValue("Number", 34); var address = key.CreateSubKey("Address"); address.SetValue("City", "Singapore"); } var print = registry.Print(RegistryView.Registry64); Assert.That(print, Is.EqualTo( @"HKEY_CURRENT_USER Address City = Singapore User Name = Dave Number = 34")); }
public void SetUp() { // Create a test registry, register in the service registry. _registry = new InMemoryRegistry(); SharpShell.ServiceRegistry.ServiceRegistry.RegisterService <IRegistry>(() => _registry); }