Пример #1
0
        public void RegKey_GetTypeOf()
        {
            RegKey key;

            key = RegKey.Create(@"HKEY_LOCAL_MACHINE\Software\RegTest");

            Assert.AreEqual(WinApi.REG_NONE, key.GetTypeOf("foo"));

            key.SetDWORD("Test1", 10);
            Assert.AreEqual(WinApi.REG_DWORD, key.GetTypeOf("Test1"));

            key.Set("Test2", "foobar");
            Assert.AreEqual(WinApi.REG_SZ, key.GetTypeOf("Test2"));

            key.Close();

            Assert.AreEqual(WinApi.REG_DWORD, RegKey.GetValueType(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1"));
            Assert.AreEqual(WinApi.REG_SZ, RegKey.GetValueType(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test2"));

            RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest");
        }
Пример #2
0
        /// <summary>
        /// Installs the registry key.
        /// </summary>
        /// <param name="state">The installer state.</param>
        public override void Install(IDictionary state)
        {
            object orgValue;

            base.Install(state);

            switch (RegKey.GetValueType(keyPath))
            {
            case WinApi.REG_NONE:

                orgValue = null;
                break;

            case WinApi.REG_DWORD:

                orgValue = RegKey.GetValue(keyPath, 0);
                break;

            case WinApi.REG_SZ:

                orgValue = RegKey.GetValue(keyPath, string.Empty);
                break;

            default:

                throw new InvalidOperationException("RegInstaller works only for REG_DWORD and REG_SZ registry values.");
            }

            state[InstallTools.GetStateKey(this, "KeyPath")]  = keyPath;
            state[InstallTools.GetStateKey(this, "OrgValue")] = orgValue;

            if (strValue != null)
            {
                RegKey.SetValue(keyPath, strValue);
            }
            else
            {
                RegKey.SetValue(keyPath, intValue);
            }
        }
Пример #3
0
        public void InstallTools_RegInstaller()
        {
            // $todo(jeff.lill): I need to come up with a better test harness for this
#if FALSE
            Hashtable    state = new Hashtable();
            RegInstaller installer;

            installer = new RegInstaller(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1", 10);
            installer.Install(state);
            Assert.AreEqual(10, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1", 0));
            installer.Commit(state);
            Assert.AreEqual(10, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1", 0));
            installer.Uninstall(state);
            Assert.AreEqual(WinApi.REG_NONE, RegKey.GetValueType(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1"));

            installer = new RegInstaller(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1", 10);
            installer.Install(state);
            Assert.AreEqual(10, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1", 0));
            installer.Rollback(state);
            Assert.AreEqual(WinApi.REG_NONE, RegKey.GetValueType(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1"));
#else
            Assert.Inconclusive("Test Disabled");
#endif
        }