Skip to content

Commit 4985376

Browse files
committed
Make Configuration mockable
1 parent a9d6e0c commit 4985376

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

LibGit2Sharp/Configuration.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public class Configuration : IDisposable
2121
private ConfigurationSafeHandle globalHandle;
2222
private ConfigurationSafeHandle localHandle;
2323

24+
/// <summary>
25+
/// Needed for mocking purposes.
26+
/// </summary>
27+
protected Configuration()
28+
{ }
29+
2430
internal Configuration(Repository repository, string globalConfigurationFileLocation, string systemConfigurationFileLocation)
2531
{
2632
this.repository = repository;
@@ -90,15 +96,15 @@ private bool HasLocalConfig
9096
/// <summary>
9197
/// Determines if a Git configuration file specific to the current interactive user has been found.
9298
/// </summary>
93-
public bool HasGlobalConfig
99+
public virtual bool HasGlobalConfig
94100
{
95101
get { return globalConfigPath != null; }
96102
}
97103

98104
/// <summary>
99105
/// Determines if a system-wide Git configuration file has been found.
100106
/// </summary>
101-
public bool HasSystemConfig
107+
public virtual bool HasSystemConfig
102108
{
103109
get { return systemConfigPath != null; }
104110
}
@@ -143,7 +149,7 @@ public void Dispose()
143149
/// </summary>
144150
/// <param name = "key">The key to unset.</param>
145151
/// <param name = "level">The configuration file which should be considered as the target of this operation</param>
146-
public void Unset(string key, ConfigurationLevel level = ConfigurationLevel.Local)
152+
public virtual void Unset(string key, ConfigurationLevel level = ConfigurationLevel.Local)
147153
{
148154
ConfigurationSafeHandle h = RetrieveConfigurationHandle(level);
149155

@@ -200,7 +206,7 @@ protected virtual void Dispose(bool disposing)
200206
/// <param name = "key">The key</param>
201207
/// <param name = "defaultValue">The default value</param>
202208
/// <returns>The configuration value, or <c>defaultValue</c> if not set</returns>
203-
public T Get<T>(string key, T defaultValue)
209+
public virtual T Get<T>(string key, T defaultValue)
204210
{
205211
Ensure.ArgumentNotNullOrEmptyString(key, "key");
206212

@@ -240,7 +246,7 @@ public T Get<T>(string key, T defaultValue)
240246
/// <param name = "secondKeyPart">The second key part</param>
241247
/// <param name = "defaultValue">The default value</param>
242248
/// <returns>The configuration value, or <c>defaultValue</c> if not set</returns>
243-
public T Get<T>(string firstKeyPart, string secondKeyPart, T defaultValue)
249+
public virtual T Get<T>(string firstKeyPart, string secondKeyPart, T defaultValue)
244250
{
245251
Ensure.ArgumentNotNull(firstKeyPart, "firstKeyPart");
246252
Ensure.ArgumentNotNull(secondKeyPart, "secondKeyPart");
@@ -271,7 +277,7 @@ public T Get<T>(string firstKeyPart, string secondKeyPart, T defaultValue)
271277
/// <param name = "thirdKeyPart">The third key part</param>
272278
/// <param name = "defaultValue">The default value</param>
273279
/// <returns>The configuration value, or <c>defaultValue</c> if not set</returns>
274-
public T Get<T>(string firstKeyPart, string secondKeyPart, string thirdKeyPart, T defaultValue)
280+
public virtual T Get<T>(string firstKeyPart, string secondKeyPart, string thirdKeyPart, T defaultValue)
275281
{
276282
Ensure.ArgumentNotNull(firstKeyPart, "firstKeyPart");
277283
Ensure.ArgumentNotNull(secondKeyPart, "secondKeyPart");
@@ -301,7 +307,7 @@ public T Get<T>(string firstKeyPart, string secondKeyPart, string thirdKeyPart,
301307
/// <param name = "keyParts">The key parts</param>
302308
/// <param name = "defaultValue">The default value</param>
303309
/// <returns>The configuration value, or <c>defaultValue</c> if not set</returns>
304-
public T Get<T>(string[] keyParts, T defaultValue)
310+
public virtual T Get<T>(string[] keyParts, T defaultValue)
305311
{
306312
Ensure.ArgumentNotNull(keyParts, "keyParts");
307313

@@ -331,7 +337,7 @@ private void Save()
331337
/// <param name = "key">The key parts</param>
332338
/// <param name = "value">The default value</param>
333339
/// <param name = "level">The configuration file which should be considered as the target of this operation</param>
334-
public void Set<T>(string key, T value, ConfigurationLevel level = ConfigurationLevel.Local)
340+
public virtual void Set<T>(string key, T value, ConfigurationLevel level = ConfigurationLevel.Local)
335341
{
336342
Ensure.ArgumentNotNullOrEmptyString(key, "key");
337343

0 commit comments

Comments
 (0)