Skip to content

Commit 9ab3805

Browse files
dahlbyknulltoken
authored andcommitted
Attempt to create mockable instances
1 parent 1cba9e4 commit 9ab3805

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

LibGit2Sharp.Tests/MetaFixture.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using LibGit2Sharp.Tests.TestHelpers;
1010
using Xunit;
1111
using Xunit.Extensions;
12+
using Moq;
1213

1314
namespace LibGit2Sharp.Tests
1415
{
@@ -107,6 +108,28 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
107108
{
108109
nonTestableTypes.Add(type, new List<string>());
109110
}
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 (Exception ex)
130+
{
131+
nonTestableTypes.Add(type, new List<string>());
132+
}
110133
}
111134

112135
if (nonTestableTypes.Any())
@@ -246,7 +269,7 @@ public void GetEnumeratorMethodsInLibGit2SharpMustBeVirtualForTestability()
246269
var nonVirtualGetEnumeratorMethods = Assembly.GetAssembly(typeof(IRepository))
247270
.GetExportedTypes()
248271
.Where(t =>
249-
t.Namespace == typeof (IRepository).Namespace &&
272+
t.Namespace == typeof(IRepository).Namespace &&
250273
!t.IsSealed &&
251274
!t.IsAbstract &&
252275
t.GetInterfaces().Any(i => i.IsAssignableFrom(typeof(IEnumerable<>))))

0 commit comments

Comments
 (0)