Skip to content

Commit a9d6e0c

Browse files
committed
Make BranchCollection mockable
1 parent 82a68d1 commit a9d6e0c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

LibGit2Sharp/BranchCollection.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ public class BranchCollection : IEnumerable<Branch>
1414
{
1515
private readonly Repository repo;
1616

17+
/// <summary>
18+
/// Needed for mocking purposes.
19+
/// </summary>
20+
protected BranchCollection()
21+
{ }
22+
1723
/// <summary>
1824
/// Initializes a new instance of the <see cref = "BranchCollection" /> class.
1925
/// </summary>
@@ -26,7 +32,7 @@ internal BranchCollection(Repository repo)
2632
/// <summary>
2733
/// Gets the <see cref = "LibGit2Sharp.Branch" /> with the specified name.
2834
/// </summary>
29-
public Branch this[string name]
35+
public virtual Branch this[string name]
3036
{
3137
get
3238
{
@@ -69,7 +75,7 @@ private Branch BuildFromReferenceName(string canonicalName)
6975
/// Returns an enumerator that iterates through the collection.
7076
/// </summary>
7177
/// <returns>An <see cref = "IEnumerator{T}" /> object that can be used to iterate through the collection.</returns>
72-
public IEnumerator<Branch> GetEnumerator()
78+
public virtual IEnumerator<Branch> GetEnumerator()
7379
{
7480
return Libgit2UnsafeHelper
7581
.ListAllBranchNames(repo.Handle, GitBranchType.GIT_BRANCH_LOCAL | GitBranchType.GIT_BRANCH_REMOTE)
@@ -95,7 +101,7 @@ IEnumerator IEnumerable.GetEnumerator()
95101
/// <param name = "shaOrReferenceName">The target which can be sha or a canonical reference name.</param>
96102
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
97103
/// <returns></returns>
98-
public Branch Add(string name, string shaOrReferenceName, bool allowOverwrite = false)
104+
public virtual Branch Add(string name, string shaOrReferenceName, bool allowOverwrite = false)
99105
{
100106
Ensure.ArgumentNotNullOrEmptyString(name, "name");
101107

@@ -128,7 +134,7 @@ public Branch Create(string name, string shaOrReferenceName, bool allowOverwrite
128134
/// </summary>
129135
/// <param name = "name">The name of the branch to delete.</param>
130136
/// <param name = "isRemote">True if the provided <paramref name="name"/> is the name of a remote branch, false otherwise.</param>
131-
public void Remove(string name, bool isRemote = false)
137+
public virtual void Remove(string name, bool isRemote = false)
132138
{
133139
Ensure.ArgumentNotNullOrEmptyString(name, "name");
134140

@@ -160,7 +166,7 @@ public void Delete(string name, bool isRemote = false)
160166
///<param name = "newName">The new name of the existing branch should bear.</param>
161167
///<param name = "allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
162168
///<returns></returns>
163-
public Branch Move(string currentName, string newName, bool allowOverwrite = false)
169+
public virtual Branch Move(string currentName, string newName, bool allowOverwrite = false)
164170
{
165171
Ensure.ArgumentNotNullOrEmptyString(currentName, "currentName");
166172
Ensure.ArgumentNotNullOrEmptyString(newName, "name");

0 commit comments

Comments
 (0)