Skip to content

Commit cda8d3f

Browse files
committed
Make all public types mockable
1 parent 1061def commit cda8d3f

19 files changed

+189
-92
lines changed

LibGit2Sharp/BranchCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public virtual Branch Add(string name, string shaOrReferenceName, bool allowOver
124124
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
125125
/// <returns></returns>
126126
[Obsolete("This method will be removed in the next release. Please use Add() instead.")]
127-
public Branch Create(string name, string shaOrReferenceName, bool allowOverwrite = false)
127+
public virtual Branch Create(string name, string shaOrReferenceName, bool allowOverwrite = false)
128128
{
129129
return Add(name, shaOrReferenceName, allowOverwrite);
130130
}
@@ -154,7 +154,7 @@ public virtual void Remove(string name, bool isRemote = false)
154154
/// <param name = "name">The name of the branch to delete.</param>
155155
/// <param name = "isRemote">True if the provided <paramref name="name"/> is the name of a remote branch, false otherwise.</param>
156156
[Obsolete("This method will be removed in the next release. Please use Remove() instead.")]
157-
public void Delete(string name, bool isRemote = false)
157+
public virtual void Delete(string name, bool isRemote = false)
158158
{
159159
Remove(name, isRemote);
160160
}

LibGit2Sharp/Commit.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public virtual IEnumerable<Commit> Parents
100100
/// <summary>
101101
/// Gets The count of parent commits.
102102
/// </summary>
103-
public int ParentsCount
103+
public virtual int ParentsCount
104104
{
105105
get
106106
{
@@ -114,7 +114,7 @@ public int ParentsCount
114114
/// <summary>
115115
/// Gets the notes of this commit.
116116
/// </summary>
117-
public IEnumerable<Note> Notes
117+
public virtual IEnumerable<Note> Notes
118118
{
119119
get { return notes.Value; }
120120
}

LibGit2Sharp/DirectReference.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ public class DirectReference : Reference
99
{
1010
private readonly Lazy<GitObject> targetBuilder;
1111

12+
/// <summary>
13+
/// Needed for mocking purposes.
14+
/// </summary>
15+
protected DirectReference()
16+
{ }
17+
1218
internal DirectReference(Lazy<GitObject> targetBuilder)
1319
{
1420
this.targetBuilder = targetBuilder;
@@ -17,7 +23,7 @@ internal DirectReference(Lazy<GitObject> targetBuilder)
1723
/// <summary>
1824
/// Gets the target of this <see cref = "DirectReference" />
1925
/// </summary>
20-
public GitObject Target
26+
public virtual GitObject Target
2127
{
2228
get { return targetBuilder.Value; }
2329
}

LibGit2Sharp/Index.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ public class Index : IEnumerable<IndexEntry>
1919
private readonly IndexSafeHandle handle;
2020
private readonly Repository repo;
2121

22+
/// <summary>
23+
/// Needed for mocking purposes.
24+
/// </summary>
25+
protected Index()
26+
{ }
27+
2228
internal Index(Repository repo)
2329
{
2430
this.repo = repo;
@@ -46,15 +52,15 @@ internal IndexSafeHandle Handle
4652
/// <summary>
4753
/// Gets the number of <see cref = "IndexEntry" /> in the index.
4854
/// </summary>
49-
public int Count
55+
public virtual int Count
5056
{
5157
get { return (int)NativeMethods.git_index_entrycount(handle); }
5258
}
5359

5460
/// <summary>
5561
/// Gets the <see cref = "IndexEntry" /> with the specified relative path.
5662
/// </summary>
57-
public IndexEntry this[string path]
63+
public virtual IndexEntry this[string path]
5864
{
5965
get
6066
{
@@ -88,7 +94,7 @@ private IndexEntry this[uint index]
8894
/// Returns an enumerator that iterates through the collection.
8995
/// </summary>
9096
/// <returns>An <see cref = "IEnumerator{T}" /> object that can be used to iterate through the collection.</returns>
91-
public IEnumerator<IndexEntry> GetEnumerator()
97+
public virtual IEnumerator<IndexEntry> GetEnumerator()
9298
{
9399
for (uint i = 0; i < Count; i++)
94100
{
@@ -111,7 +117,7 @@ IEnumerator IEnumerable.GetEnumerator()
111117
/// Promotes to the staging area the latest modifications of a file in the working directory (addition, updation or removal).
112118
/// </summary>
113119
/// <param name = "path">The path of the file within the working directory.</param>
114-
public void Stage(string path)
120+
public virtual void Stage(string path)
115121
{
116122
Ensure.ArgumentNotNull(path, "path");
117123

@@ -122,7 +128,7 @@ public void Stage(string path)
122128
/// Promotes to the staging area the latest modifications of a collection of files in the working directory (addition, updation or removal).
123129
/// </summary>
124130
/// <param name = "paths">The collection of paths of the files within the working directory.</param>
125-
public void Stage(IEnumerable<string> paths)
131+
public virtual void Stage(IEnumerable<string> paths)
126132
{
127133
//TODO: Stage() should support following use cases:
128134
// - Recursively staging the content of a directory
@@ -166,7 +172,7 @@ public void Stage(IEnumerable<string> paths)
166172
/// Removes from the staging area all the modifications of a file since the latest commit (addition, updation or removal).
167173
/// </summary>
168174
/// <param name = "path">The path of the file within the working directory.</param>
169-
public void Unstage(string path)
175+
public virtual void Unstage(string path)
170176
{
171177
Ensure.ArgumentNotNull(path, "path");
172178

@@ -177,7 +183,7 @@ public void Unstage(string path)
177183
/// Removes from the staging area all the modifications of a collection of file since the latest commit (addition, updation or removal).
178184
/// </summary>
179185
/// <param name = "paths">The collection of paths of the files within the working directory.</param>
180-
public void Unstage(IEnumerable<string> paths)
186+
public virtual void Unstage(IEnumerable<string> paths)
181187
{
182188
repo.Reset("HEAD", paths);
183189
}
@@ -187,7 +193,7 @@ public void Unstage(IEnumerable<string> paths)
187193
/// </summary>
188194
/// <param name = "sourcePath">The path of the file within the working directory which has to be moved/renamed.</param>
189195
/// <param name = "destinationPath">The target path of the file within the working directory.</param>
190-
public void Move(string sourcePath, string destinationPath)
196+
public virtual void Move(string sourcePath, string destinationPath)
191197
{
192198
Move(new[] { sourcePath }, new[] { destinationPath });
193199
}
@@ -197,7 +203,7 @@ public void Move(string sourcePath, string destinationPath)
197203
/// </summary>
198204
/// <param name = "sourcePaths">The paths of the files within the working directory which have to be moved/renamed.</param>
199205
/// <param name = "destinationPaths">The target paths of the files within the working directory.</param>
200-
public void Move(IEnumerable<string> sourcePaths, IEnumerable<string> destinationPaths)
206+
public virtual void Move(IEnumerable<string> sourcePaths, IEnumerable<string> destinationPaths)
201207
{
202208
Ensure.ArgumentNotNull(sourcePaths, "sourcePaths");
203209
Ensure.ArgumentNotNull(destinationPaths, "destinationPaths");
@@ -263,7 +269,7 @@ public void Move(IEnumerable<string> sourcePaths, IEnumerable<string> destinatio
263269
/// </para>
264270
/// </summary>
265271
/// <param name = "path">The path of the file within the working directory.</param>
266-
public void Remove(string path)
272+
public virtual void Remove(string path)
267273
{
268274
Ensure.ArgumentNotNull(path, "path");
269275

@@ -278,7 +284,7 @@ public void Remove(string path)
278284
/// </para>
279285
/// </summary>
280286
/// <param name = "paths">The collection of paths of the files within the working directory.</param>
281-
public void Remove(IEnumerable<string> paths)
287+
public virtual void Remove(IEnumerable<string> paths)
282288
{
283289
//TODO: Remove() should support following use cases:
284290
// - Removing a directory and its content
@@ -423,7 +429,7 @@ private static string BuildRelativePathFrom(Repository repo, string path)
423429
/// </summary>
424430
/// <param name = "filePath">The relative path within the working directory to the file.</param>
425431
/// <returns>A <see cref = "FileStatus" /> representing the state of the <paramref name = "filePath" /> parameter.</returns>
426-
public FileStatus RetrieveStatus(string filePath)
432+
public virtual FileStatus RetrieveStatus(string filePath)
427433
{
428434
Ensure.ArgumentNotNullOrEmptyString(filePath, "filePath");
429435

@@ -446,7 +452,7 @@ public FileStatus RetrieveStatus(string filePath)
446452
/// Retrieves the state of all files in the working directory, comparing them against the staging area and the latest commmit.
447453
/// </summary>
448454
/// <returns>A <see cref = "RepositoryStatus" /> holding the state of all the files.</returns>
449-
public RepositoryStatus RetrieveStatus()
455+
public virtual RepositoryStatus RetrieveStatus()
450456
{
451457
return new RepositoryStatus(repo);
452458
}

LibGit2Sharp/Note.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ namespace LibGit2Sharp
99
/// </summary>
1010
public class Note : IEquatable<Note>
1111
{
12+
/// <summary>
13+
/// Needed for mocking purposes.
14+
/// </summary>
15+
protected Note()
16+
{ }
17+
1218
private Note(ObjectId blobId, string message, ObjectId targetObjectId, string @namespace)
1319
{
1420
BlobId = blobId;
@@ -20,23 +26,23 @@ private Note(ObjectId blobId, string message, ObjectId targetObjectId, string @n
2026
/// <summary>
2127
/// The <see cref = "ObjectId"/> of the blob containing the note message.
2228
/// </summary>
23-
public ObjectId BlobId { get; private set; }
29+
public virtual ObjectId BlobId { get; private set; }
2430

2531
/// <summary>
2632
/// The message.
2733
/// </summary>
28-
public string Message { get; private set; }
34+
public virtual string Message { get; private set; }
2935

3036
/// <summary>
3137
/// The namespace with which this note is associated.
3238
/// <para>This is the abbreviated namespace (e.g.: commits), and not the canonical namespace (e.g.: refs/notes/commits).</para>
3339
/// </summary>
34-
public string Namespace { get; private set; }
40+
public virtual string Namespace { get; private set; }
3541

3642
/// <summary>
3743
/// The <see cref = "ObjectId"/> of the target object.
3844
/// </summary>
39-
public ObjectId TargetObjectId { get; private set; }
45+
public virtual ObjectId TargetObjectId { get; private set; }
4046

4147
internal static Note BuildFromPtr(Repository repo, string @namespace, ObjectId targetObjectId, NoteSafeHandle note)
4248
{

LibGit2Sharp/NoteCollection.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ public class NoteCollection : IEnumerable<Note>
1818

1919
private const string refsNotesPrefix = "refs/notes/";
2020

21+
/// <summary>
22+
/// Needed for mocking purposes.
23+
/// </summary>
24+
protected NoteCollection()
25+
{ }
26+
2127
internal NoteCollection(Repository repo)
2228
{
2329
this.repo = repo;
@@ -30,7 +36,7 @@ internal NoteCollection(Repository repo)
3036
/// Returns an enumerator that iterates through the collection.
3137
/// </summary>
3238
/// <returns>An <see cref = "IEnumerator{T}" /> object that can be used to iterate through the collection.</returns>
33-
public IEnumerator<Note> GetEnumerator()
39+
public virtual IEnumerator<Note> GetEnumerator()
3440
{
3541
return this[DefaultNamespace].GetEnumerator();
3642
}
@@ -49,15 +55,15 @@ IEnumerator IEnumerable.GetEnumerator()
4955
/// <summary>
5056
/// The default namespace for notes.
5157
/// </summary>
52-
public string DefaultNamespace
58+
public virtual string DefaultNamespace
5359
{
5460
get { return defaultNamespace.Value; }
5561
}
5662

5763
/// <summary>
5864
/// The list of canonicalized namespaces related to notes.
5965
/// </summary>
60-
public IEnumerable<string> Namespaces
66+
public virtual IEnumerable<string> Namespaces
6167
{
6268
get
6369
{
@@ -80,7 +86,7 @@ where refCanonical.StartsWith(refsNotesPrefix) && refCanonical != NormalizeToCan
8086
/// <summary>
8187
/// Gets the collection of <see cref = "Note"/> associated with the specified <see cref = "ObjectId"/>.
8288
/// </summary>
83-
public IEnumerable<Note> this[ObjectId id]
89+
public virtual IEnumerable<Note> this[ObjectId id]
8490
{
8591
get
8692
{
@@ -96,7 +102,7 @@ public IEnumerable<Note> this[ObjectId id]
96102
/// Gets the collection of <see cref = "Note"/> associated with the specified namespace.
97103
/// <para>This is similar to the 'get notes list' command.</para>
98104
/// </summary>
99-
public IEnumerable<Note> this[string @namespace]
105+
public virtual IEnumerable<Note> this[string @namespace]
100106
{
101107
get
102108
{
@@ -180,7 +186,7 @@ internal string UnCanonicalizeName(string name)
180186
/// <param name = "committer">The committer.</param>
181187
/// <param name = "namespace">The namespace on which the note will be created. It can be either a canonical namespace or an abbreviated namespace ('refs/notes/myNamespace' or just 'myNamespace').</param>
182188
/// <returns>The note which was just saved.</returns>
183-
public Note Add(ObjectId targetId, string message, Signature author, Signature committer, string @namespace)
189+
public virtual Note Add(ObjectId targetId, string message, Signature author, Signature committer, string @namespace)
184190
{
185191
Ensure.ArgumentNotNull(targetId, "targetId");
186192
Ensure.ArgumentNotNullOrEmptyString(message, "message");
@@ -214,7 +220,7 @@ public Note Add(ObjectId targetId, string message, Signature author, Signature c
214220
/// <param name = "namespace">The namespace on which the note will be created. It can be either a canonical namespace or an abbreviated namespace ('refs/notes/myNamespace' or just 'myNamespace').</param>
215221
/// <returns>The note which was just saved.</returns>
216222
[Obsolete("This method will be removed in the next release. Please use Add() instead.")]
217-
public Note Create(ObjectId targetId, string message, Signature author, Signature committer, string @namespace)
223+
public virtual Note Create(ObjectId targetId, string message, Signature author, Signature committer, string @namespace)
218224
{
219225
return Add(targetId, message, author, committer, @namespace);
220226
}
@@ -226,7 +232,7 @@ public Note Create(ObjectId targetId, string message, Signature author, Signatur
226232
/// <param name = "author">The author.</param>
227233
/// <param name = "committer">The committer.</param>
228234
/// <param name = "namespace">The namespace on which the note will be removed. It can be either a canonical namespace or an abbreviated namespace ('refs/notes/myNamespace' or just 'myNamespace').</param>
229-
public void Remove(ObjectId targetId, Signature author, Signature committer, string @namespace)
235+
public virtual void Remove(ObjectId targetId, Signature author, Signature committer, string @namespace)
230236
{
231237
Ensure.ArgumentNotNull(targetId, "targetId");
232238
Ensure.ArgumentNotNull(author, "author");
@@ -260,7 +266,7 @@ public void Remove(ObjectId targetId, Signature author, Signature committer, str
260266
/// <param name = "committer">The committer.</param>
261267
/// <param name = "namespace">The namespace on which the note will be removed. It can be either a canonical namespace or an abbreviated namespace ('refs/notes/myNamespace' or just 'myNamespace').</param>
262268
[Obsolete("This method will be removed in the next release. Please use Remove() instead.")]
263-
public void Delete(ObjectId targetId, Signature author, Signature committer, string @namespace)
269+
public virtual void Delete(ObjectId targetId, Signature author, Signature committer, string @namespace)
264270
{
265271
Remove(targetId, author, committer, @namespace);
266272
}

LibGit2Sharp/ObjectDatabase.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public class ObjectDatabase
1616
private readonly Repository repo;
1717
private readonly ObjectDatabaseSafeHandle handle;
1818

19+
/// <summary>
20+
/// Needed for mocking purposes.
21+
/// </summary>
22+
protected ObjectDatabase()
23+
{ }
24+
1925
internal ObjectDatabase(Repository repo)
2026
{
2127
this.repo = repo;
@@ -29,7 +35,7 @@ internal ObjectDatabase(Repository repo)
2935
/// </summary>
3036
/// <param name="objectId">Identifier of the object being searched for.</param>
3137
/// <returns>True if the object has been found; false otherwise.</returns>
32-
public bool Contains(ObjectId objectId)
38+
public virtual bool Contains(ObjectId objectId)
3339
{
3440
var oid = objectId.Oid;
3541

@@ -41,7 +47,7 @@ public bool Contains(ObjectId objectId)
4147
/// </summary>
4248
/// <param name="path">Path to the file to create the blob from.</param>
4349
/// <returns>The created <see cref="Blob"/>.</returns>
44-
public Blob CreateBlob(string path)
50+
public virtual Blob CreateBlob(string path)
4551
{
4652
Ensure.ArgumentNotNullOrEmptyString(path, "path");
4753

@@ -64,7 +70,7 @@ public Blob CreateBlob(string path)
6470
/// </summary>
6571
/// <param name = "treeDefinition">The <see cref = "TreeDefinition"/>.</param>
6672
/// <returns>The created <see cref = "Tree"/>.</returns>
67-
public Tree CreateTree(TreeDefinition treeDefinition)
73+
public virtual Tree CreateTree(TreeDefinition treeDefinition)
6874
{
6975
return treeDefinition.Build(repo);
7076
}
@@ -78,7 +84,7 @@ public Tree CreateTree(TreeDefinition treeDefinition)
7884
/// <param name = "tree">The <see cref = "Tree"/> of the <see cref = "Commit"/> to be created.</param>
7985
/// <param name = "parents">The parents of the <see cref = "Commit"/> to be created.</param>
8086
/// <returns>The created <see cref = "Commit"/>.</returns>
81-
public Commit CreateCommit(string message, Signature author, Signature committer, Tree tree, IEnumerable<Commit> parents)
87+
public virtual Commit CreateCommit(string message, Signature author, Signature committer, Tree tree, IEnumerable<Commit> parents)
8288
{
8389
return CreateCommit(message, author, committer, tree, parents, null);
8490
}

LibGit2Sharp/Reference.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ public abstract class Reference : IEquatable<Reference>
1414
private static readonly LambdaEqualityHelper<Reference> equalityHelper =
1515
new LambdaEqualityHelper<Reference>(new Func<Reference, object>[] { x => x.CanonicalName, x => x.TargetIdentifier });
1616

17+
/// <summary>
18+
/// Needed for mocking purposes.
19+
/// </summary>
20+
protected Reference()
21+
{ }
22+
1723
/// <summary>
1824
/// Gets the full name of this reference.
1925
/// </summary>
20-
public string CanonicalName { get; protected set; }
26+
public virtual string CanonicalName { get; protected set; }
2127

2228
internal static T BuildFromPtr<T>(ReferenceSafeHandle handle, Repository repo) where T : Reference
2329
{
@@ -87,7 +93,7 @@ private static ReferenceSafeHandle PeelToDirectReference(ReferenceSafeHandle han
8793
/// </para>
8894
/// </summary>
8995
// TODO: Maybe find a better name for this property.
90-
public string TargetIdentifier { get; private set; }
96+
public virtual string TargetIdentifier { get; private set; }
9197

9298
/// <summary>
9399
/// Determines whether the specified <see cref = "Object" /> is equal to the current <see cref = "Reference" />.

0 commit comments

Comments
 (0)