Overrides registry hives and allows data to be imported into those hives for the current process.
The following registry hives are supported. HKEY_CLASSES_ROOT HKEY_CURRENT_USER HKEY_LOCAL_MACHINE HKEY_USERS Only a single instance of this class may be active at a time. Overriding registry hives is a per-process operation so modifying the registry key overrides may corrupt other threads.
Inheritance: IDisposable
Example #1
0
        /// <summary>
        /// Creates a new <see cref="MockRegistry"/> and loads either the default or specified registry data file and properties.
        /// </summary>
        /// <param name="path">Optional path to the registry data file. If null, "Regstry.xml" is used from the <see cref="TestContext.DesloymentDirectory"/>.</param>
        /// <param name="properties">Additional properties to populate in the specified registry data file.</param>
        /// <returns>A new <see cref="MockRegistry"/> that must be disposed.</returns>
        internal MockRegistry OverrideRegistry(string path = null, Dictionary <string, string> properties = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                path = Path.Combine(this.TestContext.DeploymentDirectory, "Registry.xml");
            }

            if (null == properties)
            {
                properties = this.DefaultRegistryProperties;
            }

            var reg = new MockRegistry();

            reg.Import(path, properties);

            return(reg);
        }
Example #2
0
        /// <summary>
        /// Creates a new <see cref="MockRegistry"/> and loads either the default or specified registry data file and properties.
        /// </summary>
        /// <param name="path">Optional path to the registry data file. If null, "Regstry.xml" is used from the <see cref="TestContext.DesloymentDirectory"/>.</param>
        /// <param name="properties">Additional properties to populate in the specified registry data file.</param>
        /// <returns>A new <see cref="MockRegistry"/> that must be disposed.</returns>
        internal MockRegistry OverrideRegistry(string path = null, Dictionary<string, string> properties = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                path = Path.Combine(this.TestContext.DeploymentDirectory, "Registry.xml");
            }

            if (null == properties)
            {
                properties = this.DefaultRegistryProperties;
            }

            var reg = new MockRegistry();
            reg.Import(path, properties);

            return reg;
        }