-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
RegistryKey_GetValueKind_str.cs
63 lines (53 loc) · 2.17 KB
/
RegistryKey_GetValueKind_str.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.IO;
using Xunit;
namespace Microsoft.Win32.RegistryTests
{
public class RegistryKey_GetValueKind_str : RegistryTestsBase
{
[Fact]
public void NegativeTests()
{
// Registry Key does not exist
Assert.Throws<IOException>(() => TestRegistryKey.GetValueKind("DoesNotExist"));
// RegistryKey is closed
Assert.Throws<ObjectDisposedException>(() =>
{
TestRegistryKey.Dispose();
TestRegistryKey.GetValueKind("FooBar");
});
}
[Fact]
public void GetValueKindForDefaultvalue()
{
const RegistryValueKind expectedValueKind = RegistryValueKind.QWord;
TestRegistryKey.SetValue(null, 42, expectedValueKind);
Assert.Equal(expectedValueKind, TestRegistryKey.GetValueKind(null));
Assert.Equal(expectedValueKind, TestRegistryKey.GetValueKind(string.Empty));
}
[Fact]
public void GetValueKindFromReadonlyRegistryKey()
{
// [] RegistryKey is readonly
const string valueName = null;
const long expectedValue = long.MaxValue;
const RegistryValueKind expectedValueKind = RegistryValueKind.QWord;
TestRegistryKey.SetValue(valueName, expectedValue, expectedValueKind);
using (RegistryKey rk = Registry.CurrentUser.OpenSubKey(TestRegistryKeyName, false))
{
Assert.Equal(expectedValue.ToString(), rk.GetValue(valueName).ToString());
Assert.Equal(expectedValueKind, rk.GetValueKind(valueName));
}
}
[Fact]
public void ValueKindNoneTests()
{
const string valueName = "NoneKind";
const RegistryValueKind expectedValueKind = RegistryValueKind.None;
TestRegistryKey.SetValue(valueName, new byte[] { 23, 32 }, RegistryValueKind.None);
Assert.Equal(expectedValueKind, TestRegistryKey.GetValueKind(valueName));
}
}
}