我想模拟windows注册表,我需要使用C#在单元测试中使用它。我已经为HKLM和HKCU.How编写了设置注册表的函数,以便为下面的函数编写单元测试。我不想用systemWrapper,有人能帮我吗?
  public static bool createHkcuRegistry(string registryPath, string valueName, string value, RegistryValueKind valueKind = RegistryValueKind.String)
    {
        try
        {
            RegistryKey key = Registry.CurrentUser.OpenSubKey(registryPath, true);
            if (key != null)
            {
                key.SetValue(valueName, value, valueKind);
                key.Close();
            }
            else
            {
                RegistryKey newKey = Registry.CurrentUser.CreateSubKey(registryPath);
                newKey.SetValue(valueName, value, valueKind);
            }
            return true;
        }        
      }https://stackoverflow.com/questions/38472987
复制相似问题