public void Parse_Name()
        {
            var registryPath = RegistryPath.Parse("Foo");

            registryPath.Namespace.Verify().IsNullOrEmpty();
            registryPath.WeakName.Verify().IsEqual(@"Foo");
        }
        public void Parse_NameWithNamespace()
        {
            var registryPath = RegistryPath.Parse(@"qux\Foo\Bar\Baz");

            registryPath.Namespace.Verify().IsEqual(@"qux\Foo\Bar");
            registryPath.WeakName.Verify().IsEqual(@"Baz");
        }
 public void Parse_should_recognize_an_integer_value()
 {
     RegistryPath.Parse(@"HKEY_DYN_DATA\SubKey\IntValue=123")
     .Should()
     .BeEquivalentTo(
         RegistryPath.CreateValuePath(RegistryHive.DynData, "SubKey", "IntValue", 123),
         GetEquivalenceOptions);
 }
 public void Parse_should_recognize_just_a_hive()
 {
     RegistryPath.Parse("HKCU")
     .Should()
     .BeEquivalentTo(RegistryPath.CreatePath(RegistryHive.CurrentUser), GetEquivalenceOptions);
     RegistryPath.Parse("HKEY_CURRENT_USER")
     .Should()
     .BeEquivalentTo(RegistryPath.CreatePath(RegistryHive.CurrentUser), GetEquivalenceOptions);
 }
        public void Parse_should_recognize_a_string_value()
        {
            RegistryPath.Parse(@"HKCR\SubKey\StringValue=""s""")
            .Should()
            .BeEquivalentTo(
                RegistryPath.CreateValuePath(RegistryHive.ClassesRoot, "SubKey", "StringValue", "s"),
                GetEquivalenceOptions);

            RegistryPath.Parse(@"HKEY_PERFORMANCE_DATA\SubKey\StringValue='s'")
            .Should()
            .BeEquivalentTo(
                RegistryPath.CreateValuePath(RegistryHive.PerformanceData, "SubKey", "StringValue", "s"),
                GetEquivalenceOptions);
        }
        //// ===========================================================================================================
        //// Constructors
        //// ===========================================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="FakeRegistry"/> class with the specified keys and value.
        /// </summary>
        /// <param name="keysAndValues">
        /// The string needs to be in the form "BASE\SubKey[\Value=123]", where BASE is one of <c>HKEY_CLASSES_ROOT</c>
        /// (or <c>HKCR</c>), <c>HKEY_CURRENT_USER</c> (or <c>HKCU</c>), <c>HKEY_LOCAL_MACHINE</c> (or <c>HKLM</c>), or
        /// HKEY_USERS (or <c>HKU</c>). The value can either be an integer or a string with single or double quotes.
        /// </param>
        public FakeRegistry(params string[] keysAndValues)
        {
            foreach (string keyAndValue in keysAndValues)
            {
                var parsedPath = RegistryPath.Parse(keyAndValue);
                using (IWin32RegistryKey key = OpenBaseKey(parsedPath.Hive, RegistryView.Registry64)
                                               .CreateSubKey(parsedPath.Path, writable: true))
                {
                    if (!string.IsNullOrEmpty(parsedPath.ValueName))
                    {
                        RegistryValueKind kind = parsedPath.Value is string
                                                 ?RegistryValueKind.String
                                                 : RegistryValueKind.DWord;
                        key.SetValue(parsedPath.ValueName, parsedPath.Value, kind);
                    }
                }
            }
        }
 public void Parse_should_recognize_a_single_sub_level_in_the_path()
 {
     RegistryPath.Parse(@"HKLM\SubKey")
     .Should()
     .BeEquivalentTo(RegistryPath.CreatePath(RegistryHive.LocalMachine, "SubKey"), GetEquivalenceOptions);
 }
        public void Parse_should_throw_a_FormatException_when_the_value_is_not_a_string_or_integer()
        {
            Action action = () => RegistryPath.Parse(@"HKEY_CURRENT_CONFIG\SubKey\Value=$123");

            action.Should().ThrowExactly <FormatException>();
        }
 public void Parse_should_recognize_a_nested_path()
 {
     RegistryPath.Parse(@"HKU\Level1\Level2\Level3")
     .Should()
     .BeEquivalentTo(RegistryPath.CreatePath(RegistryHive.Users, @"Level1\Level2\Level3"), GetEquivalenceOptions);
 }