Permalink
Browse files

Make all public types mockable

  • Loading branch information...
1 parent 1061def commit cda8d3feeabe804af3ba685c27b8ab4ccf4794a1 @yorah yorah committed Jun 19, 2012
@@ -124,7 +124,7 @@ public virtual Branch Add(string name, string shaOrReferenceName, bool allowOver
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
/// <returns></returns>
[Obsolete("This method will be removed in the next release. Please use Add() instead.")]
- public Branch Create(string name, string shaOrReferenceName, bool allowOverwrite = false)
+ public virtual Branch Create(string name, string shaOrReferenceName, bool allowOverwrite = false)
{
return Add(name, shaOrReferenceName, allowOverwrite);
}
@@ -154,7 +154,7 @@ public virtual void Remove(string name, bool isRemote = false)
/// <param name = "name">The name of the branch to delete.</param>
/// <param name = "isRemote">True if the provided <paramref name="name"/> is the name of a remote branch, false otherwise.</param>
[Obsolete("This method will be removed in the next release. Please use Remove() instead.")]
- public void Delete(string name, bool isRemote = false)
+ public virtual void Delete(string name, bool isRemote = false)
{
Remove(name, isRemote);
}
View
@@ -100,7 +100,7 @@ public virtual IEnumerable<Commit> Parents
/// <summary>
/// Gets The count of parent commits.
/// </summary>
- public int ParentsCount
+ public virtual int ParentsCount
{
get
{
@@ -114,7 +114,7 @@ public int ParentsCount
/// <summary>
/// Gets the notes of this commit.
/// </summary>
- public IEnumerable<Note> Notes
+ public virtual IEnumerable<Note> Notes
{
get { return notes.Value; }
}
@@ -9,6 +9,12 @@ public class DirectReference : Reference
{
private readonly Lazy<GitObject> targetBuilder;
+ /// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected DirectReference()
+ { }
+
internal DirectReference(Lazy<GitObject> targetBuilder)
{
this.targetBuilder = targetBuilder;
@@ -17,7 +23,7 @@ internal DirectReference(Lazy<GitObject> targetBuilder)
/// <summary>
/// Gets the target of this <see cref = "DirectReference" />
/// </summary>
- public GitObject Target
+ public virtual GitObject Target
{
get { return targetBuilder.Value; }
}
View
@@ -19,6 +19,12 @@ public class Index : IEnumerable<IndexEntry>
private readonly IndexSafeHandle handle;
private readonly Repository repo;
+ /// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected Index()
+ { }
+
internal Index(Repository repo)
{
this.repo = repo;
@@ -46,15 +52,15 @@ internal IndexSafeHandle Handle
/// <summary>
/// Gets the number of <see cref = "IndexEntry" /> in the index.
/// </summary>
- public int Count
+ public virtual int Count
{
get { return (int)NativeMethods.git_index_entrycount(handle); }
}
/// <summary>
/// Gets the <see cref = "IndexEntry" /> with the specified relative path.
/// </summary>
- public IndexEntry this[string path]
+ public virtual IndexEntry this[string path]
{
get
{
@@ -88,7 +94,7 @@ public int Count
/// Returns an enumerator that iterates through the collection.
/// </summary>
/// <returns>An <see cref = "IEnumerator{T}" /> object that can be used to iterate through the collection.</returns>
- public IEnumerator<IndexEntry> GetEnumerator()
+ public virtual IEnumerator<IndexEntry> GetEnumerator()
{
for (uint i = 0; i < Count; i++)
{
@@ -111,7 +117,7 @@ IEnumerator IEnumerable.GetEnumerator()
/// Promotes to the staging area the latest modifications of a file in the working directory (addition, updation or removal).
/// </summary>
/// <param name = "path">The path of the file within the working directory.</param>
- public void Stage(string path)
+ public virtual void Stage(string path)
{
Ensure.ArgumentNotNull(path, "path");
@@ -122,7 +128,7 @@ public void Stage(string path)
/// Promotes to the staging area the latest modifications of a collection of files in the working directory (addition, updation or removal).
/// </summary>
/// <param name = "paths">The collection of paths of the files within the working directory.</param>
- public void Stage(IEnumerable<string> paths)
+ public virtual void Stage(IEnumerable<string> paths)
{
//TODO: Stage() should support following use cases:
// - Recursively staging the content of a directory
@@ -166,7 +172,7 @@ public void Stage(IEnumerable<string> paths)
/// Removes from the staging area all the modifications of a file since the latest commit (addition, updation or removal).
/// </summary>
/// <param name = "path">The path of the file within the working directory.</param>
- public void Unstage(string path)
+ public virtual void Unstage(string path)
{
Ensure.ArgumentNotNull(path, "path");
@@ -177,7 +183,7 @@ public void Unstage(string path)
/// Removes from the staging area all the modifications of a collection of file since the latest commit (addition, updation or removal).
/// </summary>
/// <param name = "paths">The collection of paths of the files within the working directory.</param>
- public void Unstage(IEnumerable<string> paths)
+ public virtual void Unstage(IEnumerable<string> paths)
{
repo.Reset("HEAD", paths);
}
@@ -187,7 +193,7 @@ public void Unstage(IEnumerable<string> paths)
/// </summary>
/// <param name = "sourcePath">The path of the file within the working directory which has to be moved/renamed.</param>
/// <param name = "destinationPath">The target path of the file within the working directory.</param>
- public void Move(string sourcePath, string destinationPath)
+ public virtual void Move(string sourcePath, string destinationPath)
{
Move(new[] { sourcePath }, new[] { destinationPath });
}
@@ -197,7 +203,7 @@ public void Move(string sourcePath, string destinationPath)
/// </summary>
/// <param name = "sourcePaths">The paths of the files within the working directory which have to be moved/renamed.</param>
/// <param name = "destinationPaths">The target paths of the files within the working directory.</param>
- public void Move(IEnumerable<string> sourcePaths, IEnumerable<string> destinationPaths)
+ public virtual void Move(IEnumerable<string> sourcePaths, IEnumerable<string> destinationPaths)
{
Ensure.ArgumentNotNull(sourcePaths, "sourcePaths");
Ensure.ArgumentNotNull(destinationPaths, "destinationPaths");
@@ -263,7 +269,7 @@ public void Move(IEnumerable<string> sourcePaths, IEnumerable<string> destinatio
/// </para>
/// </summary>
/// <param name = "path">The path of the file within the working directory.</param>
- public void Remove(string path)
+ public virtual void Remove(string path)
{
Ensure.ArgumentNotNull(path, "path");
@@ -278,7 +284,7 @@ public void Remove(string path)
/// </para>
/// </summary>
/// <param name = "paths">The collection of paths of the files within the working directory.</param>
- public void Remove(IEnumerable<string> paths)
+ public virtual void Remove(IEnumerable<string> paths)
{
//TODO: Remove() should support following use cases:
// - Removing a directory and its content
@@ -423,7 +429,7 @@ private static string BuildRelativePathFrom(Repository repo, string path)
/// </summary>
/// <param name = "filePath">The relative path within the working directory to the file.</param>
/// <returns>A <see cref = "FileStatus" /> representing the state of the <paramref name = "filePath" /> parameter.</returns>
- public FileStatus RetrieveStatus(string filePath)
+ public virtual FileStatus RetrieveStatus(string filePath)
{
Ensure.ArgumentNotNullOrEmptyString(filePath, "filePath");
@@ -446,7 +452,7 @@ public FileStatus RetrieveStatus(string filePath)
/// Retrieves the state of all files in the working directory, comparing them against the staging area and the latest commmit.
/// </summary>
/// <returns>A <see cref = "RepositoryStatus" /> holding the state of all the files.</returns>
- public RepositoryStatus RetrieveStatus()
+ public virtual RepositoryStatus RetrieveStatus()
{
return new RepositoryStatus(repo);
}
View
@@ -9,6 +9,12 @@ namespace LibGit2Sharp
/// </summary>
public class Note : IEquatable<Note>
{
+ /// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected Note()
+ { }
+
private Note(ObjectId blobId, string message, ObjectId targetObjectId, string @namespace)
{
BlobId = blobId;
@@ -20,23 +26,23 @@ private Note(ObjectId blobId, string message, ObjectId targetObjectId, string @n
/// <summary>
/// The <see cref = "ObjectId"/> of the blob containing the note message.
/// </summary>
- public ObjectId BlobId { get; private set; }
+ public virtual ObjectId BlobId { get; private set; }
/// <summary>
/// The message.
/// </summary>
- public string Message { get; private set; }
+ public virtual string Message { get; private set; }
/// <summary>
/// The namespace with which this note is associated.
/// <para>This is the abbreviated namespace (e.g.: commits), and not the canonical namespace (e.g.: refs/notes/commits).</para>
/// </summary>
- public string Namespace { get; private set; }
+ public virtual string Namespace { get; private set; }
/// <summary>
/// The <see cref = "ObjectId"/> of the target object.
/// </summary>
- public ObjectId TargetObjectId { get; private set; }
+ public virtual ObjectId TargetObjectId { get; private set; }
internal static Note BuildFromPtr(Repository repo, string @namespace, ObjectId targetObjectId, NoteSafeHandle note)
{
@@ -18,6 +18,12 @@ public class NoteCollection : IEnumerable<Note>
private const string refsNotesPrefix = "refs/notes/";
+ /// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected NoteCollection()
+ { }
+
internal NoteCollection(Repository repo)
{
this.repo = repo;
@@ -30,7 +36,7 @@ internal NoteCollection(Repository repo)
/// Returns an enumerator that iterates through the collection.
/// </summary>
/// <returns>An <see cref = "IEnumerator{T}" /> object that can be used to iterate through the collection.</returns>
- public IEnumerator<Note> GetEnumerator()
+ public virtual IEnumerator<Note> GetEnumerator()
{
return this[DefaultNamespace].GetEnumerator();
}
@@ -49,15 +55,15 @@ IEnumerator IEnumerable.GetEnumerator()
/// <summary>
/// The default namespace for notes.
/// </summary>
- public string DefaultNamespace
+ public virtual string DefaultNamespace
{
get { return defaultNamespace.Value; }
}
/// <summary>
/// The list of canonicalized namespaces related to notes.
/// </summary>
- public IEnumerable<string> Namespaces
+ public virtual IEnumerable<string> Namespaces
{
get
{
@@ -80,7 +86,7 @@ where refCanonical.StartsWith(refsNotesPrefix) && refCanonical != NormalizeToCan
/// <summary>
/// Gets the collection of <see cref = "Note"/> associated with the specified <see cref = "ObjectId"/>.
/// </summary>
- public IEnumerable<Note> this[ObjectId id]
+ public virtual IEnumerable<Note> this[ObjectId id]
{
get
{
@@ -96,7 +102,7 @@ where refCanonical.StartsWith(refsNotesPrefix) && refCanonical != NormalizeToCan
/// Gets the collection of <see cref = "Note"/> associated with the specified namespace.
/// <para>This is similar to the 'get notes list' command.</para>
/// </summary>
- public IEnumerable<Note> this[string @namespace]
+ public virtual IEnumerable<Note> this[string @namespace]
{
get
{
@@ -180,7 +186,7 @@ internal string UnCanonicalizeName(string name)
/// <param name = "committer">The committer.</param>
/// <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>
/// <returns>The note which was just saved.</returns>
- public Note Add(ObjectId targetId, string message, Signature author, Signature committer, string @namespace)
+ public virtual Note Add(ObjectId targetId, string message, Signature author, Signature committer, string @namespace)
{
Ensure.ArgumentNotNull(targetId, "targetId");
Ensure.ArgumentNotNullOrEmptyString(message, "message");
@@ -214,7 +220,7 @@ public Note Add(ObjectId targetId, string message, Signature author, Signature c
/// <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>
/// <returns>The note which was just saved.</returns>
[Obsolete("This method will be removed in the next release. Please use Add() instead.")]
- public Note Create(ObjectId targetId, string message, Signature author, Signature committer, string @namespace)
+ public virtual Note Create(ObjectId targetId, string message, Signature author, Signature committer, string @namespace)
{
return Add(targetId, message, author, committer, @namespace);
}
@@ -226,7 +232,7 @@ public Note Create(ObjectId targetId, string message, Signature author, Signatur
/// <param name = "author">The author.</param>
/// <param name = "committer">The committer.</param>
/// <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>
- public void Remove(ObjectId targetId, Signature author, Signature committer, string @namespace)
+ public virtual void Remove(ObjectId targetId, Signature author, Signature committer, string @namespace)
{
Ensure.ArgumentNotNull(targetId, "targetId");
Ensure.ArgumentNotNull(author, "author");
@@ -260,7 +266,7 @@ public void Remove(ObjectId targetId, Signature author, Signature committer, str
/// <param name = "committer">The committer.</param>
/// <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>
[Obsolete("This method will be removed in the next release. Please use Remove() instead.")]
- public void Delete(ObjectId targetId, Signature author, Signature committer, string @namespace)
+ public virtual void Delete(ObjectId targetId, Signature author, Signature committer, string @namespace)
{
Remove(targetId, author, committer, @namespace);
}
@@ -16,6 +16,12 @@ public class ObjectDatabase
private readonly Repository repo;
private readonly ObjectDatabaseSafeHandle handle;
+ /// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected ObjectDatabase()
+ { }
+
internal ObjectDatabase(Repository repo)
{
this.repo = repo;
@@ -29,7 +35,7 @@ internal ObjectDatabase(Repository repo)
/// </summary>
/// <param name="objectId">Identifier of the object being searched for.</param>
/// <returns>True if the object has been found; false otherwise.</returns>
- public bool Contains(ObjectId objectId)
+ public virtual bool Contains(ObjectId objectId)
{
var oid = objectId.Oid;
@@ -41,7 +47,7 @@ public bool Contains(ObjectId objectId)
/// </summary>
/// <param name="path">Path to the file to create the blob from.</param>
/// <returns>The created <see cref="Blob"/>.</returns>
- public Blob CreateBlob(string path)
+ public virtual Blob CreateBlob(string path)
{
Ensure.ArgumentNotNullOrEmptyString(path, "path");
@@ -64,7 +70,7 @@ public Blob CreateBlob(string path)
/// </summary>
/// <param name = "treeDefinition">The <see cref = "TreeDefinition"/>.</param>
/// <returns>The created <see cref = "Tree"/>.</returns>
- public Tree CreateTree(TreeDefinition treeDefinition)
+ public virtual Tree CreateTree(TreeDefinition treeDefinition)
{
return treeDefinition.Build(repo);
}
@@ -78,7 +84,7 @@ public Tree CreateTree(TreeDefinition treeDefinition)
/// <param name = "tree">The <see cref = "Tree"/> of the <see cref = "Commit"/> to be created.</param>
/// <param name = "parents">The parents of the <see cref = "Commit"/> to be created.</param>
/// <returns>The created <see cref = "Commit"/>.</returns>
- public Commit CreateCommit(string message, Signature author, Signature committer, Tree tree, IEnumerable<Commit> parents)
+ public virtual Commit CreateCommit(string message, Signature author, Signature committer, Tree tree, IEnumerable<Commit> parents)
{
return CreateCommit(message, author, committer, tree, parents, null);
}
View
@@ -15,9 +15,15 @@ public abstract class Reference : IEquatable<Reference>
new LambdaEqualityHelper<Reference>(new Func<Reference, object>[] { x => x.CanonicalName, x => x.TargetIdentifier });
/// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected Reference()
+ { }
+
+ /// <summary>
/// Gets the full name of this reference.
/// </summary>
- public string CanonicalName { get; protected set; }
+ public virtual string CanonicalName { get; protected set; }
internal static T BuildFromPtr<T>(ReferenceSafeHandle handle, Repository repo) where T : Reference
{
@@ -87,7 +93,7 @@ private static ReferenceSafeHandle PeelToDirectReference(ReferenceSafeHandle han
/// </para>
/// </summary>
// TODO: Maybe find a better name for this property.
- public string TargetIdentifier { get; private set; }
+ public virtual string TargetIdentifier { get; private set; }
/// <summary>
/// Determines whether the specified <see cref = "Object" /> is equal to the current <see cref = "Reference" />.
Oops, something went wrong.

0 comments on commit cda8d3f

Please sign in to comment.