Exemple #1
0
        public void RegKey_Basic()
        {
            RegKey key;

            Assert.IsFalse(RegKey.Exists(@"HKEY_LOCAL_MACHINE\Software\RegTest"));
            key = RegKey.Create(@"HKEY_LOCAL_MACHINE\Software\RegTest");
            Assert.IsTrue(RegKey.Exists(@"HKEY_LOCAL_MACHINE\Software\RegTest"));

            key.Set("Test1", "value1");
            key.Set("Test2", "value2");
            key.Set("Test3", 3);

            Assert.AreEqual("value1", key.Get("Test1"));
            Assert.AreEqual("value2", key.Get("Test2"));
            Assert.AreEqual("3", key.Get("Test3"));

            key.Set("Test1", "hello");
            Assert.AreEqual("hello", key.Get("Test1"));

            Assert.AreEqual("default", key.Get("foobar", "default"));

            key.Close();

            Assert.AreEqual("hello", RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1"));
            Assert.AreEqual("value2", RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test2"));
            Assert.AreEqual("3", RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test3"));

            RegKey.SetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test4", "Hello");
            Assert.AreEqual("Hello", RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test4"));

            RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest");
        }