Skip to content

Commit 82a68d1

Browse files
committed
Make Commit mockable
1 parent 70aff86 commit 82a68d1

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

LibGit2Sharp/Commit.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ public class Commit : GitObject
1717
private readonly Lazy<string> shortMessage;
1818
private readonly Lazy<IEnumerable<Note>> notes;
1919

20+
/// <summary>
21+
/// Needed for mocking purposes.
22+
/// </summary>
23+
protected Commit()
24+
{ }
25+
2026
internal Commit(ObjectId id, ObjectId treeId, Repository repo)
2127
: base(id)
2228
{
@@ -32,20 +38,20 @@ internal Commit(ObjectId id, ObjectId treeId, Repository repo)
3238
/// </summary>
3339
/// <param name = "relativePath">The relative path to the <see cref = "TreeEntry" /> from the <see cref = "Commit" /> working directory.</param>
3440
/// <returns><c>null</c> if nothing has been found, the <see cref = "TreeEntry" /> otherwise.</returns>
35-
public TreeEntry this[string relativePath]
41+
public virtual TreeEntry this[string relativePath]
3642
{
3743
get { return Tree[relativePath]; }
3844
}
3945

4046
/// <summary>
4147
/// Gets the commit message.
4248
/// </summary>
43-
public string Message { get; private set; }
49+
public virtual string Message { get; private set; }
4450

4551
/// <summary>
4652
/// Gets the short commit message which is usually the first line of the commit.
4753
/// </summary>
48-
public string MessageShort
54+
public virtual string MessageShort
4955
{
5056
get { return shortMessage.Value; }
5157
}
@@ -63,30 +69,30 @@ private string ExtractShortMessage()
6369
/// <summary>
6470
/// Gets the encoding of the message.
6571
/// </summary>
66-
public string Encoding { get; private set; }
72+
public virtual string Encoding { get; private set; }
6773

6874
/// <summary>
6975
/// Gets the author of this commit.
7076
/// </summary>
71-
public Signature Author { get; private set; }
77+
public virtual Signature Author { get; private set; }
7278

7379
/// <summary>
7480
/// Gets the committer.
7581
/// </summary>
76-
public Signature Committer { get; private set; }
82+
public virtual Signature Committer { get; private set; }
7783

7884
/// <summary>
7985
/// Gets the Tree associated to this commit.
8086
/// </summary>
81-
public Tree Tree
87+
public virtual Tree Tree
8288
{
8389
get { return tree.Value; }
8490
}
8591

8692
/// <summary>
8793
/// Gets the parents of this commit. This property is lazy loaded and can throw an exception if the commit no longer exists in the repo.
8894
/// </summary>
89-
public IEnumerable<Commit> Parents
95+
public virtual IEnumerable<Commit> Parents
9096
{
9197
get { return parents.Value; }
9298
}

LibGit2Sharp/GitObject.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public class GitObject : IEquatable<GitObject>
2323
private static readonly LambdaEqualityHelper<GitObject> equalityHelper =
2424
new LambdaEqualityHelper<GitObject>(new Func<GitObject, object>[] { x => x.Id });
2525

26+
/// <summary>
27+
/// Needed for mocking purposes.
28+
/// </summary>
29+
protected GitObject()
30+
{ }
31+
2632
/// <summary>
2733
/// Initializes a new instance of the <see cref = "GitObject" /> class.
2834
/// </summary>
@@ -35,12 +41,12 @@ protected GitObject(ObjectId id)
3541
/// <summary>
3642
/// Gets the id of this object
3743
/// </summary>
38-
public ObjectId Id { get; private set; }
44+
public virtual ObjectId Id { get; private set; }
3945

4046
/// <summary>
4147
/// Gets the 40 character sha1 of this object.
4248
/// </summary>
43-
public string Sha
49+
public virtual string Sha
4450
{
4551
get { return Id.Sha; }
4652
}

0 commit comments

Comments
 (0)