Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make all public types mockable #187

Merged
merged 3 commits into from

2 participants

@yorah

Fixes #186.

Summary:

  • Added a meta test to check that all public types have either a public constructor, or at least an empty protected constructor & virtual properties/methods
  • Made the test pass...
  • Fixed two IEquatable<> definition issues
@nulltoken nulltoken merged commit cda8d3f into from
@nulltoken
Owner

AWESOME!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
1  LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -57,6 +57,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
+ <Compile Include="MetaFixture.cs" />
<Compile Include="MockedRepositoryFixture.cs" />
<Compile Include="ConfigurationFixture.cs" />
<Compile Include="AttributesFixture.cs" />
View
89 LibGit2Sharp.Tests/MetaFixture.cs
@@ -0,0 +1,89 @@
+using System.Text;
+using Xunit;
+using System.Reflection;
+using System;
+using System.Linq;
+using System.Collections.Generic;
+
+namespace LibGit2Sharp.Tests
+{
+ public class MetaFixture
+ {
+ private static readonly Type[] excludedTypes = new[] { typeof(Repository) };
+
+ // Related to https://github.com/libgit2/libgit2sharp/pull/185
+ [Fact]
+ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
+ {
+ var nonTestableTypes = new Dictionary<Type, IEnumerable<string>>();
+
+ IEnumerable<Type> libGit2SharpTypes = Assembly.GetAssembly(typeof(Repository)).GetExportedTypes().Where(t => !excludedTypes.Contains(t) && t.Namespace == typeof(Repository).Namespace);
+
+ foreach (Type type in libGit2SharpTypes)
+ {
+ if (type.IsInterface || type.IsEnum || IsStatic(type))
+ continue;
+
+ ConstructorInfo[] publicConstructor = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
+ if (publicConstructor.Any())
+ {
+ continue;
+ }
+
+ var nonVirtualMethodNamesForType = GetNonVirtualPublicMethodsNames(type).ToList();
+ if (nonVirtualMethodNamesForType.Any())
+ {
+ nonTestableTypes.Add(type, nonVirtualMethodNamesForType);
+ continue;
+ }
+
+ if (!HasEmptyProtectedConstructor(type))
+ {
+ nonTestableTypes.Add(type, new List<string>());
+ }
+ }
+
+ if (nonTestableTypes.Any())
+ {
+ Assert.True(false, Environment.NewLine + BuildNonTestableTypesMessage(nonTestableTypes));
+ }
+ }
+
+ private static string BuildNonTestableTypesMessage(Dictionary<Type, IEnumerable<string>> nonTestableTypes)
+ {
+ var sb = new StringBuilder();
+
+ foreach (var kvp in nonTestableTypes)
+ {
+ sb.AppendFormat("'{0}' cannot be easily abstracted in a testing context. Please make sure it either has a public constructor, or an empty protected constructor.{1}",
+ kvp.Key, Environment.NewLine);
+
+ foreach (string methodName in kvp.Value)
+ {
+ sb.AppendFormat(" - Method '{0}' must be virtual{1}", methodName, Environment.NewLine);
+ }
+ }
+
+ return sb.ToString();
+ }
+
+ private static IEnumerable<string> GetNonVirtualPublicMethodsNames(Type type)
+ {
+ var publicMethods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
+
+ return from mi in publicMethods where !mi.IsVirtual && !mi.IsStatic select mi.ToString();
+ }
+
+ private static bool HasEmptyProtectedConstructor(Type type)
+ {
+ ConstructorInfo[] nonPublicConstructors = type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance);
+
+ return nonPublicConstructors.Any(ci => !ci.IsPrivate && !ci.IsAssembly && !ci.IsFinal && !ci.GetParameters().Any());
+ }
+
+ private static bool IsStatic(Type type)
+ {
+ return type.IsAbstract && type.IsSealed;
+ }
+ }
+}
View
4 LibGit2Sharp/BranchCollection.cs
@@ -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
4 LibGit2Sharp/Commit.cs
@@ -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; }
}
View
8 LibGit2Sharp/DirectReference.cs
@@ -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
32 LibGit2Sharp/Index.cs
@@ -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,7 +52,7 @@ 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); }
}
@@ -54,7 +60,7 @@ public int Count
/// <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
16 LibGit2Sharp/Note.cs
@@ -7,8 +7,14 @@ namespace LibGit2Sharp
/// <summary>
/// A note, attached to a given <see cref = "GitObject"/>.
/// </summary>
- public class Note
+ 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)
{
View
24 LibGit2Sharp/NoteCollection.cs
@@ -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,7 +55,7 @@ IEnumerator IEnumerable.GetEnumerator()
/// <summary>
/// The default namespace for notes.
/// </summary>
- public string DefaultNamespace
+ public virtual string DefaultNamespace
{
get { return defaultNamespace.Value; }
}
@@ -57,7 +63,7 @@ public string DefaultNamespace
/// <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);
}
View
14 LibGit2Sharp/ObjectDatabase.cs
@@ -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
10 LibGit2Sharp/Reference.cs
@@ -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" />.
View
22 LibGit2Sharp/ReferenceCollection.cs
@@ -16,6 +16,12 @@ public class ReferenceCollection : IEnumerable<Reference>
private readonly Repository repo;
/// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected ReferenceCollection()
+ { }
+
+ /// <summary>
/// Initializes a new instance of the <see cref = "ReferenceCollection" /> class.
/// </summary>
/// <param name = "repo">The repo.</param>
@@ -29,7 +35,7 @@ internal ReferenceCollection(Repository repo)
/// </summary>
/// <param name = "name">The canonical name of the reference to resolve.</param>
/// <returns>The resolved <see cref = "LibGit2Sharp.Reference" /> if it has been found, null otherwise.</returns>
- public Reference this[string name]
+ public virtual Reference this[string name]
{
get { return Resolve<Reference>(name); }
}
@@ -40,7 +46,7 @@ internal ReferenceCollection(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<Reference> GetEnumerator()
+ public virtual IEnumerator<Reference> GetEnumerator()
{
return Libgit2UnsafeHelper
.ListAllReferenceNames(repo.Handle, GitReferenceType.ListAll)
@@ -66,7 +72,7 @@ IEnumerator IEnumerable.GetEnumerator()
/// <param name = "target">The target which can be either a sha or the canonical name of another reference.</param>
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing reference, false otherwise.</param>
/// <returns>A new <see cref = "Reference" />.</returns>
- public Reference Add(string name, string target, bool allowOverwrite = false)
+ public virtual Reference Add(string name, string target, bool allowOverwrite = false)
{
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(target, "target");
@@ -97,7 +103,7 @@ public Reference Add(string name, string target, bool allowOverwrite = false)
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing reference, false otherwise.</param>
/// <returns>A new <see cref = "Reference" />.</returns>
[Obsolete("This method will be removed in the next release. Please use Add() instead.")]
- public Reference Create(string name, string target, bool allowOverwrite = false)
+ public virtual Reference Create(string name, string target, bool allowOverwrite = false)
{
return Add(name, target, allowOverwrite);
}
@@ -141,7 +147,7 @@ private ObjectId Unabbreviate(ObjectId targetId)
/// Delete a reference with the specified name
/// </summary>
/// <param name = "name">The name of the reference to delete.</param>
- public void Remove(string name)
+ public virtual void Remove(string name)
{
Ensure.ArgumentNotNullOrEmptyString(name, "name");
@@ -161,7 +167,7 @@ public void Remove(string name)
/// </summary>
/// <param name = "name">The name of the reference to delete.</param>
[Obsolete("This method will be removed in the next release. Please use Remove() instead.")]
- public void Delete(string name)
+ public virtual void Delete(string name)
{
Remove(name);
}
@@ -173,7 +179,7 @@ public void Delete(string name)
/// <param name = "newName">The new canonical name.</param>
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing reference, false otherwise.</param>
/// <returns></returns>
- public Reference Move(string currentName, string newName, bool allowOverwrite = false)
+ public virtual Reference Move(string currentName, string newName, bool allowOverwrite = false)
{
Ensure.ArgumentNotNullOrEmptyString(currentName, "currentName");
Ensure.ArgumentNotNullOrEmptyString(newName, "newName");
@@ -202,7 +208,7 @@ public Reference Move(string currentName, string newName, bool allowOverwrite =
/// </summary>
/// <param name = "name">The name of the reference.</param>
/// <param name = "target">The target which can be either a sha or the name of another reference.</param>
- public Reference UpdateTarget(string name, string target)
+ public virtual Reference UpdateTarget(string name, string target)
{
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(target, "target");
View
4 LibGit2Sharp/RemoteCollection.cs
@@ -106,7 +106,7 @@ public virtual Remote Add(string name, string url)
/// <param name = "url">The location of the repository.</param>
/// <returns>A new <see cref = "Remote" />.</returns>
[Obsolete("This method will be removed in the next release. Please use Add() instead.")]
- public Remote Create(string name, string url)
+ public virtual Remote Create(string name, string url)
{
return Add(name, url);
}
@@ -146,7 +146,7 @@ public virtual Remote Add(string name, string url, string fetchRefSpec)
/// <param name = "fetchRefSpec">The refSpec to be used when fetching from this remote..</param>
/// <returns>A new <see cref = "Remote" />.</returns>
[Obsolete("This method will be removed in the next release. Please use Add() instead.")]
- public Remote Create(string name, string url, string fetchRefSpec)
+ public virtual Remote Create(string name, string url, string fetchRefSpec)
{
return Add(name, url);
}
View
24 LibGit2Sharp/RepositoryStatus.cs
@@ -38,6 +38,12 @@ public class RepositoryStatus : IEnumerable<StatusEntry>
};
}
+ /// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected RepositoryStatus()
+ { }
+
internal RepositoryStatus(Repository repo)
{
Ensure.Success(NativeMethods.git_status_foreach(repo.Handle, StateChanged, IntPtr.Zero));
@@ -67,7 +73,7 @@ private int StateChanged(IntPtr filePathPtr, uint state, IntPtr payload)
/// 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<StatusEntry> GetEnumerator()
+ public virtual IEnumerator<StatusEntry> GetEnumerator()
{
return statusEntries.GetEnumerator();
}
@@ -84,7 +90,7 @@ IEnumerator IEnumerable.GetEnumerator()
/// <summary>
/// List of files added to the index, which are not in the current commit
/// </summary>
- public IEnumerable<string> Added
+ public virtual IEnumerable<string> Added
{
get { return added; }
}
@@ -92,7 +98,7 @@ public IEnumerable<string> Added
/// <summary>
/// List of files added to the index, which are already in the current commit with different content
/// </summary>
- public IEnumerable<string> Staged
+ public virtual IEnumerable<string> Staged
{
get { return staged; }
}
@@ -100,7 +106,7 @@ public IEnumerable<string> Staged
/// <summary>
/// List of files removed from the index but are existent in the current commit
/// </summary>
- public IEnumerable<string> Removed
+ public virtual IEnumerable<string> Removed
{
get { return removed; }
}
@@ -108,7 +114,7 @@ public IEnumerable<string> Removed
/// <summary>
/// List of files existent in the index but are missing in the working directory
/// </summary>
- public IEnumerable<string> Missing
+ public virtual IEnumerable<string> Missing
{
get { return missing; }
}
@@ -116,7 +122,7 @@ public IEnumerable<string> Missing
/// <summary>
/// List of files with unstaged modifications. A file may be modified and staged at the same time if it has been modified after adding.
/// </summary>
- public IEnumerable<string> Modified
+ public virtual IEnumerable<string> Modified
{
get { return modified; }
}
@@ -124,7 +130,7 @@ public IEnumerable<string> Modified
/// <summary>
/// List of files existing in the working directory but are neither tracked in the index nor in the current commit.
/// </summary>
- public IEnumerable<string> Untracked
+ public virtual IEnumerable<string> Untracked
{
get { return untracked; }
}
@@ -132,7 +138,7 @@ public IEnumerable<string> Untracked
/// <summary>
/// List of files existing in the working directory that are ignored.
/// </summary>
- public IEnumerable<string> Ignored
+ public virtual IEnumerable<string> Ignored
{
get { return ignored; }
}
@@ -140,7 +146,7 @@ public IEnumerable<string> Ignored
/// <summary>
/// True if the index or the working directory has been altered since the last commit. False otherwise.
/// </summary>
- public bool IsDirty
+ public virtual bool IsDirty
{
get { return isDirty; }
}
View
10 LibGit2Sharp/StatusEntry.cs
@@ -14,6 +14,12 @@ public class StatusEntry : IEquatable<StatusEntry>
private static readonly LambdaEqualityHelper<StatusEntry> equalityHelper =
new LambdaEqualityHelper<StatusEntry>(new Func<StatusEntry, object>[] { x => x.FilePath, x => x.State });
+ /// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected StatusEntry()
+ { }
+
internal StatusEntry(string filePath, FileStatus state)
{
this.filePath = filePath;
@@ -23,7 +29,7 @@ internal StatusEntry(string filePath, FileStatus state)
/// <summary>
/// Gets the <see cref="FileStatus"/> of the file.
/// </summary>
- public FileStatus State
+ public virtual FileStatus State
{
get { return state; }
}
@@ -31,7 +37,7 @@ public FileStatus State
/// <summary>
/// Gets the relative filepath to the working directory of the file.
/// </summary>
- public string FilePath
+ public virtual string FilePath
{
get { return filePath; }
}
View
12 LibGit2Sharp/Tag.cs
@@ -8,6 +8,12 @@ namespace LibGit2Sharp
/// </summary>
public class Tag : ReferenceWrapper<GitObject>
{
+ /// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected Tag()
+ { }
+
internal Tag(Repository repo, Reference reference, string canonicalName)
: base(repo, reference, _ => canonicalName)
{
@@ -17,7 +23,7 @@ internal Tag(Repository repo, Reference reference, string canonicalName)
/// Gets the optional information associated to this tag.
/// <para>When the <see cref = "Tag" /> is a lightweight tag, <c>null</c> is returned.</para>
/// </summary>
- public TagAnnotation Annotation
+ public virtual TagAnnotation Annotation
{
get { return TargetObject as TagAnnotation; }
}
@@ -25,7 +31,7 @@ public TagAnnotation Annotation
/// <summary>
/// Gets the <see cref = "GitObject" /> that this tag points to.
/// </summary>
- public GitObject Target
+ public virtual GitObject Target
{
get
{
@@ -43,7 +49,7 @@ public GitObject Target
/// <summary>
/// Indicates whether the tag holds any metadata.
/// </summary>
- public bool IsAnnotated
+ public virtual bool IsAnnotated
{
get { return Annotation != null; }
}
View
14 LibGit2Sharp/TagAnnotation.cs
@@ -11,6 +11,12 @@ public class TagAnnotation : GitObject
{
private Lazy<GitObject> targetBuilder;
+ /// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected TagAnnotation()
+ { }
+
internal TagAnnotation(ObjectId id)
: base(id)
{
@@ -19,17 +25,17 @@ internal TagAnnotation(ObjectId id)
/// <summary>
/// Gets the name of this tag.
/// </summary>
- public string Name { get; private set; }
+ public virtual string Name { get; private set; }
/// <summary>
/// Gets the message of this tag.
/// </summary>
- public string Message { get; private set; }
+ public virtual string Message { get; private set; }
/// <summary>
/// Gets the <see cref = "GitObject" /> that this tag annotation points to.
/// </summary>
- public GitObject Target
+ public virtual GitObject Target
{
get { return targetBuilder.Value; }
}
@@ -37,7 +43,7 @@ public GitObject Target
/// <summary>
/// Gets the tagger.
/// </summary>
- public Signature Tagger { get; private set; }
+ public virtual Signature Tagger { get; private set; }
internal static TagAnnotation BuildFromPtr(GitObjectSafeHandle obj, ObjectId id, Repository repo)
{
View
22 LibGit2Sharp/TagCollection.cs
@@ -16,6 +16,12 @@ public class TagCollection : IEnumerable<Tag>
private const string refsTagsPrefix = "refs/tags/";
/// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected TagCollection()
+ { }
+
+ /// <summary>
/// Initializes a new instance of the <see cref = "TagCollection" /> class.
/// </summary>
/// <param name = "repo">The repo.</param>
@@ -27,7 +33,7 @@ internal TagCollection(Repository repo)
/// <summary>
/// Gets the <see cref = "Tag" /> with the specified name.
/// </summary>
- public Tag this[string name]
+ public virtual Tag this[string name]
{
get
{
@@ -44,7 +50,7 @@ internal TagCollection(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<Tag> GetEnumerator()
+ public virtual IEnumerator<Tag> GetEnumerator()
{
return Libgit2UnsafeHelper
.ListAllTagNames(repo.Handle)
@@ -72,7 +78,7 @@ IEnumerator IEnumerable.GetEnumerator()
/// <param name = "message">The message.</param>
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing tag, false otherwise.</param>
/// <returns></returns>
- public Tag Add(string name, string target, Signature tagger, string message, bool allowOverwrite = false)
+ public virtual Tag Add(string name, string target, Signature tagger, string message, bool allowOverwrite = false)
{
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(target, "target");
@@ -104,7 +110,7 @@ public Tag Add(string name, string target, Signature tagger, string message, boo
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing tag, false otherwise.</param>
/// <returns></returns>
[Obsolete("This method will be removed in the next release. Please use Add() instead.")]
- public Tag Create(string name, string target, Signature tagger, string message, bool allowOverwrite = false)
+ public virtual Tag Create(string name, string target, Signature tagger, string message, bool allowOverwrite = false)
{
return Add(name, target, tagger, message, allowOverwrite);
}
@@ -116,7 +122,7 @@ public Tag Create(string name, string target, Signature tagger, string message,
/// <param name = "target">The target which can be sha or a canonical reference name.</param>
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing tag, false otherwise.</param>
/// <returns></returns>
- public Tag Add(string name, string target, bool allowOverwrite = false)
+ public virtual Tag Add(string name, string target, bool allowOverwrite = false)
{
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(target, "target");
@@ -143,7 +149,7 @@ public Tag Add(string name, string target, bool allowOverwrite = false)
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing tag, false otherwise.</param>
/// <returns></returns>
[Obsolete("This method will be removed in the next release. Please use Add() instead.")]
- public Tag Create(string name, string target, bool allowOverwrite = false)
+ public virtual Tag Create(string name, string target, bool allowOverwrite = false)
{
return Add(name, target, allowOverwrite);
}
@@ -152,7 +158,7 @@ public Tag Create(string name, string target, bool allowOverwrite = false)
/// Deletes the tag with the specified name.
/// </summary>
/// <param name = "name">The short or canonical name of the tag to delete.</param>
- public void Remove(string name)
+ public virtual void Remove(string name)
{
Ensure.ArgumentNotNullOrEmptyString(name, "name");
@@ -165,7 +171,7 @@ public void Remove(string name)
/// </summary>
/// <param name = "name">The short or canonical name of the tag to delete.</param>
[Obsolete("This method will be removed in the next release. Please use Remove() instead.")]
- public void Delete(string name)
+ public virtual void Delete(string name)
{
Remove(name);
}
View
16 LibGit2Sharp/Tree.cs
@@ -14,6 +14,12 @@ public class Tree : GitObject, IEnumerable<TreeEntry>
private readonly Repository repo;
private readonly FilePath path;
+ /// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected Tree()
+ { }
+
internal Tree(ObjectId id, FilePath path, int treeEntriesCount, Repository repository)
: base(id)
{
@@ -25,14 +31,14 @@ internal Tree(ObjectId id, FilePath path, int treeEntriesCount, Repository repos
/// <summary>
/// Gets the number of <see cref = "TreeEntry" /> immediately under this <see cref = "Tree" />.
/// </summary>
- public int Count { get; private set; }
+ public virtual int Count { get; private set; }
/// <summary>
/// Gets the <see cref = "TreeEntry" /> pointed at by the <paramref name = "relativePath" /> in this <see cref = "Tree" /> instance.
/// </summary>
/// <param name = "relativePath">The relative path to the <see cref = "TreeEntry" /> from this instance.</param>
/// <returns><c>null</c> if nothing has been found, the <see cref = "TreeEntry" /> otherwise.</returns>
- public TreeEntry this[string relativePath]
+ public virtual TreeEntry this[string relativePath]
{
get { return RetrieveFromPath(relativePath); }
}
@@ -76,7 +82,7 @@ private TreeEntry RetrieveFromPath(FilePath relativePath)
/// <summary>
/// Gets the <see cref = "Tree" />s immediately under this <see cref = "Tree" />.
/// </summary>
- public IEnumerable<Tree> Trees
+ public virtual IEnumerable<Tree> Trees
{
get
{
@@ -90,7 +96,7 @@ public IEnumerable<Tree> Trees
/// <summary>
/// Gets the <see cref = "Blob" />s immediately under this <see cref = "Tree" />.
/// </summary>
- public IEnumerable<Blob> Blobs
+ public virtual IEnumerable<Blob> Blobs
{
get
{
@@ -112,7 +118,7 @@ internal string Path
/// 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<TreeEntry> GetEnumerator()
+ public virtual IEnumerator<TreeEntry> GetEnumerator()
{
using (var obj = new ObjectSafeWrapper(Id, repo))
{
View
26 LibGit2Sharp/TreeChanges.cs
@@ -34,6 +34,12 @@ public class TreeChanges : IEnumerable<TreeEntryChanges>
};
}
+ /// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected TreeChanges()
+ { }
+
internal TreeChanges(DiffListSafeHandle diff)
{
Ensure.Success(NativeMethods.git_diff_print_patch(diff, IntPtr.Zero, PrintCallBack));
@@ -98,11 +104,13 @@ private void AddFileChange(GitDiffDelta delta)
changes.Add(newFilePath, diffFile);
}
+ #region IEnumerable<Tag> Members
+
/// <summary>
/// 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<TreeEntryChanges> GetEnumerator()
+ public virtual IEnumerator<TreeEntryChanges> GetEnumerator()
{
return changes.Values.GetEnumerator();
}
@@ -116,10 +124,12 @@ IEnumerator IEnumerable.GetEnumerator()
return GetEnumerator();
}
+ #endregion
+
/// <summary>
/// Gets the <see cref = "TreeEntryChanges"/> corresponding to the specified <paramref name = "path"/>.
/// </summary>
- public TreeEntryChanges this[string path]
+ public virtual TreeEntryChanges this[string path]
{
get { return this[(FilePath)path]; }
}
@@ -141,7 +151,7 @@ IEnumerator IEnumerable.GetEnumerator()
/// <summary>
/// List of <see cref = "TreeEntryChanges"/> that have been been added.
/// </summary>
- public IEnumerable<TreeEntryChanges> Added
+ public virtual IEnumerable<TreeEntryChanges> Added
{
get { return added; }
}
@@ -149,7 +159,7 @@ public IEnumerable<TreeEntryChanges> Added
/// <summary>
/// List of <see cref = "TreeEntryChanges"/> that have been deleted.
/// </summary>
- public IEnumerable<TreeEntryChanges> Deleted
+ public virtual IEnumerable<TreeEntryChanges> Deleted
{
get { return deleted; }
}
@@ -157,7 +167,7 @@ public IEnumerable<TreeEntryChanges> Deleted
/// <summary>
/// List of <see cref = "TreeEntryChanges"/> that have been modified.
/// </summary>
- public IEnumerable<TreeEntryChanges> Modified
+ public virtual IEnumerable<TreeEntryChanges> Modified
{
get { return modified; }
}
@@ -165,7 +175,7 @@ public IEnumerable<TreeEntryChanges> Modified
/// <summary>
/// The total number of lines added in this diff.
/// </summary>
- public int LinesAdded
+ public virtual int LinesAdded
{
get { return linesAdded; }
}
@@ -173,7 +183,7 @@ public int LinesAdded
/// <summary>
/// The total number of lines added in this diff.
/// </summary>
- public int LinesDeleted
+ public virtual int LinesDeleted
{
get { return linesDeleted; }
}
@@ -181,7 +191,7 @@ public int LinesDeleted
/// <summary>
/// The full patch file of this diff.
/// </summary>
- public string Patch
+ public virtual string Patch
{
get { return fullPatchBuilder.ToString(); }
}
View
16 LibGit2Sharp/TreeEntry.cs
@@ -19,6 +19,12 @@ public class TreeEntry : IEquatable<TreeEntry>
private static readonly LambdaEqualityHelper<TreeEntry> equalityHelper =
new LambdaEqualityHelper<TreeEntry>(new Func<TreeEntry, object>[] { x => x.Name, x => x.parentTreeId });
+ /// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected TreeEntry()
+ { }
+
internal TreeEntry(TreeEntrySafeHandle obj, ObjectId parentTreeId, Repository repo, FilePath parentPath)
{
this.parentTreeId = parentTreeId;
@@ -35,23 +41,23 @@ internal TreeEntry(TreeEntrySafeHandle obj, ObjectId parentTreeId, Repository re
/// <summary>
/// Gets the file mode.
/// </summary>
- public Mode Mode { get; private set; }
+ public virtual Mode Mode { get; private set; }
/// <summary>
/// Gets the filename.
/// </summary>
- public string Name { get; private set; }
+ public virtual string Name { get; private set; }
/// <summary>
/// Gets the path.
/// <para>The path is expressed in a relative form from the latest known <see cref="Tree"/>. Path segments are separated with a forward or backslash, depending on the OS the libray is being run on."/></para>
/// </summary>
- public string Path { get { return path.Value; } }
+ public virtual string Path { get { return path.Value; } }
/// <summary>
/// Gets the <see cref = "GitObject" /> being pointed at.
/// </summary>
- public GitObject Target
+ public virtual GitObject Target
{
get { return target.Value; }
}
@@ -64,7 +70,7 @@ internal ObjectId TargetId
/// <summary>
/// Gets the <see cref = "GitObjectType" /> of the <see cref = "Target" /> being pointed at.
/// </summary>
- public GitObjectType Type { get; private set; }
+ public virtual GitObjectType Type { get; private set; }
private GitObject RetrieveTreeEntryTarget()
{
View
7 LibGit2Sharp/TreeEntryDefinition.cs
@@ -7,14 +7,17 @@ namespace LibGit2Sharp
/// <summary>
/// Holds the meta data of a <see cref = "TreeEntry" />.
/// </summary>
- public class TreeEntryDefinition
+ public class TreeEntryDefinition : IEquatable<TreeEntryDefinition>
{
private Lazy<GitObject> target;
private static readonly LambdaEqualityHelper<TreeEntryDefinition> equalityHelper =
new LambdaEqualityHelper<TreeEntryDefinition>(new Func<TreeEntryDefinition, object>[] { x => x.Mode, x => x.Type, x => x.TargetId });
- internal TreeEntryDefinition()
+ /// <summary>
+ /// Needed for mocking purposes.
+ /// </summary>
+ protected TreeEntryDefinition()
{
}
Something went wrong with that request. Please try again.