Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions LibGit2Sharp.Tests/MetaFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ namespace LibGit2Sharp.Tests
{
public class MetaFixture
{
private static readonly Type[] excludedTypes = new[] { typeof(Repository) };
private static readonly Type[] excludedTypes = new[]
{
typeof(Credentials),
typeof(Filter),
typeof(ObjectId),
typeof(Repository),
typeof(RepositoryOptions),
typeof(Signature),
};

// Related to https://github.com/libgit2/libgit2sharp/pull/251
[Fact]
Expand Down Expand Up @@ -59,27 +67,21 @@ 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);
.Where(t => !excludedTypes.Contains(t) && t.Namespace == typeof(Repository).Namespace && !t.IsSubclassOf(typeof(Delegate)));

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))
if (!HasEmptyPublicOrProtectedConstructor(type))
{
nonTestableTypes.Add(type, new List<string>());
}
Expand Down Expand Up @@ -131,11 +133,11 @@ private static IEnumerable<string> GetNonVirtualPublicMethodsNames(Type type)
return from mi in publicMethods where !mi.IsVirtual && !mi.IsStatic select mi.ToString();
}

private static bool HasEmptyProtectedConstructor(Type type)
private static bool HasEmptyPublicOrProtectedConstructor(Type type)
{
ConstructorInfo[] nonPublicConstructors = type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance);
return nonPublicConstructors.Any(ci => !ci.IsPrivate && !ci.IsAssembly && !ci.IsFinal && !ci.GetParameters().Any());
ConstructorInfo[] constructors = type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

return constructors.Any(ci => ci.GetParameters().Length == 0 && (ci.IsPublic || ci.IsFamily || ci.IsFamilyOrAssembly));
}

private static bool IsStatic(Type type)
Expand Down
10 changes: 5 additions & 5 deletions LibGit2Sharp/IndexEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,30 @@ public class IndexEntry : IEquatable<IndexEntry>
/// compared against the <see cref = "Blob" /> known from the <see cref = "Repository.Head" /> and the file in the working directory.
/// </summary>
[Obsolete("This method will be removed in the next release. Please use Repository.Index.RetrieveStatus(filePath) overload instead.")]
public FileStatus State
public virtual FileStatus State
{
get { return state(); }
}

/// <summary>
/// Gets the relative path to the file within the working directory.
/// </summary>
public string Path { get; private set; }
public virtual string Path { get; private set; }

/// <summary>
/// Gets the file mode.
/// </summary>
public Mode Mode { get; private set; }
public virtual Mode Mode { get; private set; }

/// <summary>
/// Gets the stage number.
/// </summary>
public StageLevel StageLevel { get; private set; }
public virtual StageLevel StageLevel { get; private set; }

/// <summary>
/// Gets the id of the <see cref = "Blob" /> pointed at by this index entry.
/// </summary>
public ObjectId Id { get; private set; }
public virtual ObjectId Id { get; private set; }

internal static IndexEntry BuildFromPtr(Repository repo, IndexEntrySafeHandle handle)
{
Expand Down
12 changes: 6 additions & 6 deletions LibGit2Sharp/TreeDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void AddEntry(string targetTreeEntryName, TreeEntryDefinition treeEntryD
/// </summary>
/// <param name="treeEntryPath">The path within this <see cref="TreeDefinition"/>.</param>
/// <returns>The current <see cref="TreeDefinition"/>.</returns>
public TreeDefinition Remove(string treeEntryPath)
public virtual TreeDefinition Remove(string treeEntryPath)
{
Ensure.ArgumentNotNullOrEmptyString(treeEntryPath, "treeEntryPath");

Expand Down Expand Up @@ -92,7 +92,7 @@ public TreeDefinition Remove(string treeEntryPath)
/// <param name="targetTreeEntryPath">The path within this <see cref="TreeDefinition"/>.</param>
/// <param name="treeEntryDefinition">The <see cref="TreeEntryDefinition"/> to be stored at the described location.</param>
/// <returns>The current <see cref="TreeDefinition"/>.</returns>
public TreeDefinition Add(string targetTreeEntryPath, TreeEntryDefinition treeEntryDefinition)
public virtual TreeDefinition Add(string targetTreeEntryPath, TreeEntryDefinition treeEntryDefinition)
{
Ensure.ArgumentNotNullOrEmptyString(targetTreeEntryPath, "targetTreeEntryPath");
Ensure.ArgumentNotNull(treeEntryDefinition, "treeEntryDefinition");
Expand Down Expand Up @@ -132,7 +132,7 @@ public TreeDefinition Add(string targetTreeEntryPath, TreeEntryDefinition treeEn
/// <param name="blob">The <see cref="Blob"/> to be stored at the described location.</param>
/// <param name="mode">The file related <see cref="Mode"/> attributes.</param>
/// <returns>The current <see cref="TreeDefinition"/>.</returns>
public TreeDefinition Add(string targetTreeEntryPath, Blob blob, Mode mode)
public virtual TreeDefinition Add(string targetTreeEntryPath, Blob blob, Mode mode)
{
Ensure.ArgumentNotNull(blob, "blob");
Ensure.ArgumentConformsTo(mode,
Expand All @@ -151,7 +151,7 @@ public TreeDefinition Add(string targetTreeEntryPath, Blob blob, Mode mode)
/// <see cref="Repository" /> is a standard, non-bare, repository. The path will then be considered as a path relative to the root of the working directory.</param>
/// <param name="mode">The file related <see cref="Mode"/> attributes.</param>
/// <returns>The current <see cref="TreeDefinition"/>.</returns>
public TreeDefinition Add(string targetTreeEntryPath, string filePath, Mode mode)
public virtual TreeDefinition Add(string targetTreeEntryPath, string filePath, Mode mode)
{
Ensure.ArgumentNotNullOrEmptyString(filePath, "filePath");

Expand All @@ -166,7 +166,7 @@ public TreeDefinition Add(string targetTreeEntryPath, string filePath, Mode mode
/// <param name="targetTreeEntryPath">The path within this <see cref="TreeDefinition"/>.</param>
/// <param name="tree">The <see cref="Tree"/> to be stored at the described location.</param>
/// <returns>The current <see cref="TreeDefinition"/>.</returns>
public TreeDefinition Add(string targetTreeEntryPath, Tree tree)
public virtual TreeDefinition Add(string targetTreeEntryPath, Tree tree)
{
Ensure.ArgumentNotNull(tree, "tree");

Expand Down Expand Up @@ -281,7 +281,7 @@ private void WrapTree(string entryName, TreeEntryDefinition treeEntryDefinition)
/// </summary>
/// <param name="treeEntryPath">The path within this <see cref="TreeDefinition"/>.</param>
/// <returns>The found <see cref="TreeEntryDefinition"/> if any; null otherwise.</returns>
public TreeEntryDefinition this[string treeEntryPath]
public virtual TreeEntryDefinition this[string treeEntryPath]
{
get
{
Expand Down