Skip to content

Commit 0148eca

Browse files
committed
Remove the code we have just for mocking
We make the constructors internal but then make sure we cave constructors with zero arity so mocking them via e.g. Moq is easier. With this we're making out code harder to mock, but then add ways to add another layer of mocking easier. We enforce this constructors for mocking in the tests, without regard for whether they make sense or not. Often it would make a lot more sense to expose a public constructor for types so an application can return fake results.
1 parent 4f68818 commit 0148eca

84 files changed

Lines changed: 3 additions & 675 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

LibGit2Sharp.Tests/EqualityFixture.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,9 @@ public void EqualityHelperCanTestNullInHashCode()
3636

3737
private class ObjectWithEquality : GitObject
3838
{
39-
private readonly ObjectId id;
40-
4139
public ObjectWithEquality(ObjectId id = null)
40+
: base(null, id)
4241
{
43-
this.id = id;
44-
}
45-
46-
public override ObjectId Id
47-
{
48-
get { return id; }
4942
}
5043
}
5144
}

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
3636
</PropertyGroup>
3737
<ItemGroup>
38-
<Reference Include="Moq, Version=4.2.1507.118, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
39-
<HintPath>..\packages\Moq.4.2.1507.0118\lib\net40\Moq.dll</HintPath>
40-
</Reference>
4138
<Reference Include="System" />
4239
<Reference Include="System.Core" />
4340
<Reference Include="System.Xml" />
@@ -89,7 +86,6 @@
8986
<Compile Include="CleanFixture.cs" />
9087
<Compile Include="CurrentOperationFixture.cs" />
9188
<Compile Include="MetaFixture.cs" />
92-
<Compile Include="MockingFixture.cs" />
9389
<Compile Include="ConfigurationFixture.cs" />
9490
<Compile Include="AttributesFixture.cs" />
9591
<Compile Include="CommitAncestorFixture.cs" />

LibGit2Sharp.Tests/MetaFixture.cs

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using LibGit2Sharp.Tests.TestHelpers;
1010
using Xunit;
1111
using Xunit.Extensions;
12-
using Moq;
1312

1413
namespace LibGit2Sharp.Tests
1514
{
@@ -83,78 +82,6 @@ public void TypesInLibGit2DecoratedWithDebuggerDisplayMustFollowTheStandardImplP
8382
}
8483
}
8584

86-
// Related to https://github.com/libgit2/libgit2sharp/pull/185
87-
[Fact]
88-
public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
89-
{
90-
var nonTestableTypes = new Dictionary<Type, IEnumerable<string>>();
91-
92-
IEnumerable<Type> libGit2SharpTypes = Assembly.GetAssembly(typeof(IRepository)).GetExportedTypes()
93-
.Where(t => MustBeMockable(t) && t.Namespace == typeof(IRepository).Namespace);
94-
95-
foreach (Type type in libGit2SharpTypes)
96-
{
97-
if (type.IsInterface || type.IsEnum || IsStatic(type))
98-
continue;
99-
100-
var nonVirtualMethodNamesForType = GetNonVirtualPublicMethodsNames(type).ToList();
101-
if (nonVirtualMethodNamesForType.Any())
102-
{
103-
nonTestableTypes.Add(type, nonVirtualMethodNamesForType);
104-
continue;
105-
}
106-
107-
if (!HasEmptyPublicOrProtectedConstructor(type))
108-
{
109-
nonTestableTypes.Add(type, new List<string>());
110-
}
111-
112-
if (type.IsAbstract)
113-
{
114-
continue;
115-
}
116-
117-
try
118-
{
119-
if (type.ContainsGenericParameters)
120-
{
121-
var constructType = type.MakeGenericType(Enumerable.Repeat(typeof(object), type.GetGenericArguments().Length).ToArray());
122-
Activator.CreateInstance(constructType, true);
123-
}
124-
else
125-
{
126-
Activator.CreateInstance(type, true);
127-
}
128-
}
129-
catch
130-
{
131-
nonTestableTypes.Add(type, new List<string>());
132-
}
133-
}
134-
135-
if (nonTestableTypes.Any())
136-
{
137-
Assert.True(false, Environment.NewLine + BuildNonTestableTypesMessage(nonTestableTypes));
138-
}
139-
}
140-
141-
private static bool MustBeMockable(Type type)
142-
{
143-
if (type.IsSealed)
144-
{
145-
return false;
146-
}
147-
148-
if (type.IsAbstract)
149-
{
150-
return !type.Assembly.GetExportedTypes()
151-
.Where(t => t.IsSubclassOf(type))
152-
.All(t => t.IsAbstract || t.IsSealed);
153-
}
154-
155-
return true;
156-
}
157-
15885
[Fact]
15986
public void LibGit2SharpPublicInterfacesCoverAllPublicMembers()
16087
{

LibGit2Sharp.Tests/MockingFixture.cs

Lines changed: 0 additions & 110 deletions
This file was deleted.

LibGit2Sharp.Tests/packages.config

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Moq" version="4.2.1507.0118" targetFramework="net40" />
4-
<package id="xunit" version="1.9.2" targetFramework="net40" />
5-
<package id="xunit.extensions" version="1.9.2" targetFramework="net40" />
3+
<package id="xunit.abstractions" version="2.0.0" targetFramework="net40" />
64
<package id="xunit.runner.visualstudio" version="2.1.0" targetFramework="net40" />
75
</packages>

LibGit2Sharp/AfterRebaseStepInfo.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
/// </summary>
66
public class AfterRebaseStepInfo
77
{
8-
/// <summary>
9-
/// Needed for mocking.
10-
/// </summary>
11-
protected AfterRebaseStepInfo()
12-
{ }
13-
148
internal AfterRebaseStepInfo(RebaseStepInfo stepInfo, Commit commit, long completedStepIndex, long totalStepCount)
159
{
1610
StepInfo = stepInfo;

LibGit2Sharp/BeforeRebaseStepInfo.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ namespace LibGit2Sharp
1010
/// </summary>
1111
public class BeforeRebaseStepInfo
1212
{
13-
/// <summary>
14-
/// Needed for mocking.
15-
/// </summary>
16-
protected BeforeRebaseStepInfo()
17-
{ }
18-
1913
internal BeforeRebaseStepInfo(RebaseStepInfo stepInfo, long stepIndex, long totalStepCount)
2014
{
2115
StepInfo = stepInfo;

LibGit2Sharp/BlameHunk.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ internal BlameHunk(IRepository repository, GitBlameHunk rawHunk)
4747
}
4848
}
4949

50-
/// <summary>
51-
/// For easier mocking
52-
/// </summary>
53-
protected BlameHunk()
54-
{ }
55-
5650
/// <summary>
5751
/// Determine if this hunk contains a given line.
5852
/// </summary>

LibGit2Sharp/BlameHunkCollection.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ public class BlameHunkCollection : IEnumerable<BlameHunk>
1515
private readonly IRepository repo;
1616
private readonly List<BlameHunk> hunks = new List<BlameHunk>();
1717

18-
/// <summary>
19-
/// For easy mocking
20-
/// </summary>
21-
protected BlameHunkCollection() { }
22-
2318
internal BlameHunkCollection(Repository repo, RepositorySafeHandle repoHandle, string path, BlameOptions options)
2419
{
2520
this.repo = repo;

LibGit2Sharp/Blob.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ public class Blob : GitObject
1313
private readonly ILazy<Int64> lazySize;
1414
private readonly ILazy<bool> lazyIsBinary;
1515

16-
/// <summary>
17-
/// Needed for mocking purposes.
18-
/// </summary>
19-
protected Blob()
20-
{ }
21-
2216
internal Blob(Repository repo, ObjectId id)
2317
: base(repo, id)
2418
{

0 commit comments

Comments
 (0)