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