Skip to content

Commit 847ad24

Browse files
committed
Compile tests for netcoreapp1.0 as well
Most were small code changes. A few tests had to be moved into the new desktop folder of the unit test project so they would be excluded from netcoreapp1.0 build. At least for now.
1 parent 58a537f commit 847ad24

File tree

11 files changed

+93
-74
lines changed

11 files changed

+93
-74
lines changed

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
55

66
<CodeGenerationRoslynVersion>0.3.4</CodeGenerationRoslynVersion>
7+
<CodeGeneratorConfiguration Condition=" '$(CodeGeneratorConfiguration)' == '' ">Debug</CodeGeneratorConfiguration>
78
</PropertyGroup>
89

910
<ItemGroup>

LibGit2Sharp.Tests/ArchiveTarFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public void CanArchiveACommitWithDirectoryAsTar()
3030

3131
repo.ObjectDatabase.Archive(commit, archivePath);
3232

33-
using (var expectedStream = new StreamReader(Path.Combine(ResourcesDirectory.FullName, "expected_archives/commit_with_directory.tar")))
34-
using (var actualStream = new StreamReader(archivePath))
33+
using (var expectedStream = new StreamReader(File.OpenRead(Path.Combine(ResourcesDirectory.FullName, "expected_archives/commit_with_directory.tar"))))
34+
using (var actualStream = new StreamReader(File.OpenRead(archivePath)))
3535
{
3636
string expected = expectedStream.ReadToEnd();
3737
string actual = actualStream.ReadToEnd();

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net46</TargetFrameworks>
3+
<TargetFrameworks>net46;netcoreapp1.0</TargetFrameworks>
44
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
55
<DefineConstants Condition=" '$(TargetFramework)' == 'net46' ">$(DefineConstants);DESKTOP</DefineConstants>
66
<IsPackable>false</IsPackable>
@@ -12,17 +12,24 @@
1212
<Compile Include="..\LibGit2Sharp\Core\Platform.cs">
1313
<Link>TestHelpers\Platform.cs</Link>
1414
</Compile>
15+
<Compile Remove="desktop\**" Condition=" '$(TargetFramework)' != 'net46' " />
1516
</ItemGroup>
1617
<ItemGroup>
1718
<ProjectReference Include="..\LibGit2Sharp\LibGit2Sharp.csproj" />
19+
<ProjectReference Include="..\CodeGeneration\CodeGeneration.csproj">
20+
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
21+
<SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
22+
<UndefineProperties>TargetFramework</UndefineProperties>
23+
<Properties>Configuration=$(CodeGeneratorConfiguration);Platform=AnyCPU</Properties>
24+
</ProjectReference>
1825
</ItemGroup>
1926
<ItemGroup>
2027
<PackageReference Include="Moq" Version="4.7.8" />
2128
<PackageReference Include="xunit" Version="2.2.0" />
2229
<PackageReference Include="xunit.skippablefact" Version="1.3.1" />
2330
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
2431
<PackageReference Include="xunit.runner.console" Version="2.2.0" />
25-
<PackageReference Include="xunit.runner.msbuild" Version="2.2.0" />
32+
<PackageReference Include="xunit.runner.msbuild" Version="2.2.0" Condition=" '$(TargetFramework)' == 'net46' " />
2633
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
2734
</ItemGroup>
2835
<Import Project="..\LibGit2Sharp\ExtraDefine.targets" />

LibGit2Sharp.Tests/MetaFixture.cs

Lines changed: 29 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace LibGit2Sharp.Tests
1515
{
16-
public class MetaFixture
16+
public partial class MetaFixture
1717
{
1818
private static readonly HashSet<Type> explicitOnlyInterfaces = new HashSet<Type>
1919
{
@@ -28,8 +28,8 @@ public void PublicTestMethodsAreFactsOrTheories()
2828
"LibGit2Sharp.Tests.FilterBranchFixture.Dispose",
2929
};
3030

31-
var fixtures = from t in Assembly.GetAssembly(typeof(MetaFixture)).GetExportedTypes()
32-
where t.IsPublic && !t.IsNested
31+
var fixtures = from t in typeof(MetaFixture).GetTypeInfo().Assembly.GetExportedTypes()
32+
where t.GetTypeInfo().IsPublic && !t.IsNested
3333
where t.Namespace != typeof(BaseFixture).Namespace // Exclude helpers
3434
let methods = t.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public)
3535
from m in methods
@@ -49,12 +49,12 @@ public void TypesInLibGit2DecoratedWithDebuggerDisplayMustFollowTheStandardImplP
4949
{
5050
var typesWithDebuggerDisplayAndInvalidImplPattern = new List<Type>();
5151

52-
IEnumerable<Type> libGit2SharpTypes = Assembly.GetAssembly(typeof(IRepository)).GetExportedTypes()
53-
.Where(t => t.GetCustomAttributes(typeof(DebuggerDisplayAttribute), false).Any());
52+
IEnumerable<Type> libGit2SharpTypes = typeof(IRepository).GetTypeInfo().Assembly.GetExportedTypes()
53+
.Where(t => t.GetTypeInfo().GetCustomAttributes(typeof(DebuggerDisplayAttribute), false).Any());
5454

5555
foreach (Type type in libGit2SharpTypes)
5656
{
57-
var debuggerDisplayAttribute = (DebuggerDisplayAttribute)type.GetCustomAttributes(typeof(DebuggerDisplayAttribute), false).Single();
57+
var debuggerDisplayAttribute = (DebuggerDisplayAttribute)type.GetTypeInfo().GetCustomAttributes(typeof(DebuggerDisplayAttribute), false).Single();
5858

5959
if (debuggerDisplayAttribute.Value != "{DebuggerDisplay,nq}")
6060
{
@@ -89,12 +89,12 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
8989
{
9090
var nonTestableTypes = new Dictionary<Type, IEnumerable<string>>();
9191

92-
IEnumerable<Type> libGit2SharpTypes = Assembly.GetAssembly(typeof(IRepository)).GetExportedTypes()
92+
IEnumerable<Type> libGit2SharpTypes = typeof(IRepository).GetTypeInfo().Assembly.GetExportedTypes()
9393
.Where(t => MustBeMockable(t) && t.Namespace == typeof(IRepository).Namespace);
9494

9595
foreach (Type type in libGit2SharpTypes)
9696
{
97-
if (type.IsInterface || type.IsEnum || IsStatic(type))
97+
if (type.GetTypeInfo().IsInterface || type.GetTypeInfo().IsEnum || IsStatic(type))
9898
continue;
9999

100100
var nonVirtualMethodNamesForType = GetNonVirtualPublicMethodsNames(type).ToList();
@@ -109,14 +109,14 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
109109
nonTestableTypes.Add(type, new List<string>());
110110
}
111111

112-
if (type.IsAbstract)
112+
if (type.GetTypeInfo().IsAbstract)
113113
{
114114
continue;
115115
}
116116

117117
try
118118
{
119-
if (type.ContainsGenericParameters)
119+
if (type.GetTypeInfo().ContainsGenericParameters)
120120
{
121121
var constructType = type.MakeGenericType(Enumerable.Repeat(typeof(object), type.GetGenericArguments().Length).ToArray());
122122
Activator.CreateInstance(constructType, true);
@@ -140,62 +140,27 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
140140

141141
private static bool MustBeMockable(Type type)
142142
{
143-
if (type.IsSealed)
143+
if (type.GetTypeInfo().IsSealed)
144144
{
145145
return false;
146146
}
147147

148-
if (type.IsAbstract)
148+
if (type.GetTypeInfo().IsAbstract)
149149
{
150-
return !type.Assembly.GetExportedTypes()
151-
.Where(t => t.IsSubclassOf(type))
152-
.All(t => t.IsAbstract || t.IsSealed);
150+
return !type.GetTypeInfo().Assembly.GetExportedTypes()
151+
.Where(t => t.GetTypeInfo().IsSubclassOf(type))
152+
.All(t => t.GetTypeInfo().IsAbstract || t.GetTypeInfo().IsSealed);
153153
}
154154

155155
return true;
156156
}
157157

158-
[Fact]
159-
public void LibGit2SharpPublicInterfacesCoverAllPublicMembers()
160-
{
161-
var methodsMissingFromInterfaces =
162-
from t in Assembly.GetAssembly(typeof(IRepository)).GetExportedTypes()
163-
where !t.IsInterface
164-
where t.GetInterfaces().Any(i => i.IsPublic && i.Namespace == typeof(IRepository).Namespace && !explicitOnlyInterfaces.Contains(i))
165-
let interfaceTargetMethods = from i in t.GetInterfaces()
166-
from im in t.GetInterfaceMap(i).TargetMethods
167-
select im
168-
from tm in t.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance)
169-
where !interfaceTargetMethods.Contains(tm)
170-
select t.Name + " has extra method " + tm.Name;
171-
172-
Assert.Equal("", string.Join(Environment.NewLine,
173-
methodsMissingFromInterfaces.ToArray()));
174-
}
175-
176-
[Fact]
177-
public void LibGit2SharpExplicitOnlyInterfacesAreIndeedExplicitOnly()
178-
{
179-
var methodsMissingFromInterfaces =
180-
from t in Assembly.GetAssembly(typeof(IRepository)).GetExportedTypes()
181-
where t.GetInterfaces().Any(explicitOnlyInterfaces.Contains)
182-
let interfaceTargetMethods = from i in t.GetInterfaces()
183-
where explicitOnlyInterfaces.Contains(i)
184-
from im in t.GetInterfaceMap(i).TargetMethods
185-
select im
186-
from tm in t.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance)
187-
where interfaceTargetMethods.Contains(tm)
188-
select t.Name + " has public method " + tm.Name + " which should be explicitly implemented.";
189-
190-
Assert.Equal("", string.Join(Environment.NewLine,
191-
methodsMissingFromInterfaces.ToArray()));
192-
}
193158

194159
[Fact]
195160
public void EnumsWithFlagsHaveMutuallyExclusiveValues()
196161
{
197-
var flagsEnums = Assembly.GetAssembly(typeof(IRepository)).GetExportedTypes()
198-
.Where(t => t.IsEnum && t.GetCustomAttributes(typeof(FlagsAttribute), false).Any());
162+
var flagsEnums = typeof(IRepository).GetTypeInfo().Assembly.GetExportedTypes()
163+
.Where(t => t.GetTypeInfo().IsEnum && t.GetTypeInfo().GetCustomAttributes(typeof(FlagsAttribute), false).Any());
199164

200165
var overlaps = from t in flagsEnums
201166
from int x in Enum.GetValues(t)
@@ -259,19 +224,19 @@ private static bool HasEmptyPublicOrProtectedConstructor(Type type)
259224

260225
private static bool IsStatic(Type type)
261226
{
262-
return type.IsAbstract && type.IsSealed;
227+
return type.GetTypeInfo().IsAbstract && type.GetTypeInfo().IsSealed;
263228
}
264229

265230
// Related to https://github.com/libgit2/libgit2sharp/issues/644 and https://github.com/libgit2/libgit2sharp/issues/645
266231
[Fact]
267232
public void GetEnumeratorMethodsInLibGit2SharpMustBeVirtualForTestability()
268233
{
269-
var nonVirtualGetEnumeratorMethods = Assembly.GetAssembly(typeof(IRepository))
234+
var nonVirtualGetEnumeratorMethods = typeof(IRepository).GetTypeInfo().Assembly
270235
.GetExportedTypes()
271236
.Where(t =>
272237
t.Namespace == typeof(IRepository).Namespace &&
273-
!t.IsSealed &&
274-
!t.IsAbstract &&
238+
!t.GetTypeInfo().IsSealed &&
239+
!t.GetTypeInfo().IsAbstract &&
275240
t.GetInterfaces().Any(i => i.IsAssignableFrom(typeof(IEnumerable<>))))
276241
.Select(t => t.GetMethod("GetEnumerator"))
277242
.Where(m =>
@@ -298,7 +263,7 @@ public void NoPublicTypesUnderLibGit2SharpCoreNamespace()
298263
{
299264
const string coreNamespace = "LibGit2Sharp.Core";
300265

301-
var types = Assembly.GetAssembly(typeof(IRepository))
266+
var types = typeof(IRepository).GetTypeInfo().Assembly
302267
.GetExportedTypes()
303268
.Where(t => t.FullName.StartsWith(coreNamespace + "."))
304269

@@ -326,7 +291,7 @@ public void NoPublicTypesUnderLibGit2SharpCoreNamespace()
326291
public void NoOptionalParametersinMethods()
327292
{
328293
IEnumerable<string> mis =
329-
from t in Assembly.GetAssembly(typeof(IRepository))
294+
from t in typeof(IRepository).GetTypeInfo().Assembly
330295
.GetExportedTypes()
331296
from m in t.GetMethods()
332297
where !m.IsObsolete()
@@ -349,7 +314,7 @@ where p.IsOptional
349314
public void NoOptionalParametersinConstructors()
350315
{
351316
IEnumerable<string> mis =
352-
from t in Assembly.GetAssembly(typeof(IRepository))
317+
from t in typeof(IRepository).GetTypeInfo().Assembly
353318
.GetExportedTypes()
354319
from c in t.GetConstructors()
355320
from p in c.GetParameters()
@@ -389,12 +354,12 @@ from m in GetInvalidPublicExtensionMethods()
389354

390355
static IEnumerable<MethodInfo> GetInvalidPublicExtensionMethods()
391356
{
392-
var query = from type in (Assembly.GetAssembly(typeof(IRepository))).GetTypes()
393-
where type.IsSealed && !type.IsGenericType && !type.IsNested && type.IsPublic
357+
var query = from type in typeof(IRepository).GetTypeInfo().Assembly.GetTypes()
358+
where type.GetTypeInfo().IsSealed && !type.GetTypeInfo().IsGenericType && !type.IsNested && type.GetTypeInfo().IsPublic
394359
from method in type.GetMethods(BindingFlags.Static | BindingFlags.Public)
395360
where method.IsDefined(typeof(ExtensionAttribute), false)
396361
let parameterType = method.GetParameters()[0].ParameterType
397-
where parameterType != null && !parameterType.IsInterface && !parameterType.IsEnum
362+
where parameterType != null && !parameterType.GetTypeInfo().IsInterface && !parameterType.GetTypeInfo().IsEnum
398363
select method;
399364
return query;
400365
}
@@ -405,8 +370,8 @@ public void AllIDiffResultsAreInChangesBuilder()
405370
var diff = typeof(Diff).GetField("ChangesBuilders", BindingFlags.NonPublic | BindingFlags.Static);
406371
var changesBuilders = (System.Collections.IDictionary)diff.GetValue(null);
407372

408-
IEnumerable<Type> diffResults = typeof(Diff).Assembly.GetExportedTypes()
409-
.Where(type => type.GetInterface("IDiffResult") != null);
373+
IEnumerable<Type> diffResults = typeof(Diff).GetTypeInfo().Assembly.GetExportedTypes()
374+
.Where(type => type.GetTypeInfo().GetInterface("IDiffResult") != null);
410375

411376
var nonBuilderTypes = diffResults.Where(diffResult => !changesBuilders.Contains(diffResult));
412377
Assert.False(nonBuilderTypes.Any(), "Classes which implement IDiffResult but are not registered under ChangesBuilders in Diff:" + Environment.NewLine +

LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private static void SetUpTestEnvironment()
5959
{
6060
IsFileSystemCaseSensitive = IsFileSystemCaseSensitiveInternal();
6161

62-
string initialAssemblyParentFolder = Directory.GetParent(new Uri(typeof(BaseFixture).Assembly.EscapedCodeBase).LocalPath).FullName;
62+
string initialAssemblyParentFolder = Directory.GetParent(new Uri(typeof(BaseFixture).GetTypeInfo().Assembly.CodeBase).LocalPath).FullName;
6363

6464
const string sourceRelativePath = @"../../../../LibGit2Sharp.Tests/Resources";
6565
ResourcesDirectory = new DirectoryInfo(Path.Combine(initialAssemblyParentFolder, sourceRelativePath));

LibGit2Sharp.Tests/TestHelpers/Constants.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ private static string UnwrapUnixTempPath()
8787
{
8888
var type = Type.GetType("Mono.Unix.UnixPath, Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
8989

90-
return (string)type.InvokeMember("GetCompleteRealPath",
90+
return (string)type.GetMethod("GetCompleteRealPath",
9191
BindingFlags.Static | BindingFlags.FlattenHierarchy |
92-
BindingFlags.InvokeMethod | BindingFlags.Public,
93-
null, type, new object[] { Path.GetTempPath() });
92+
BindingFlags.InvokeMethod | BindingFlags.Public).Invoke(
93+
null, new object[] { Path.GetTempPath() });
9494
}
9595

9696
// To help with creating secure strings to test with.

LibGit2Sharp.Tests/TestHelpers/DirectoryHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.IO;
55
using System.Linq;
6+
using System.Reflection;
67
using System.Threading;
78

89
namespace LibGit2Sharp.Tests.TestHelpers
@@ -78,7 +79,7 @@ private static void DeleteDirectory(string directoryPath, int maxAttempts, int i
7879
{
7980
var caughtExceptionType = ex.GetType();
8081

81-
if (!whitelist.Any(knownExceptionType => knownExceptionType.IsAssignableFrom(caughtExceptionType)))
82+
if (!whitelist.Any(knownExceptionType => knownExceptionType.GetTypeInfo().IsAssignableFrom(caughtExceptionType)))
8283
{
8384
throw;
8485
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Linq;
3+
using System.Reflection;
4+
using Xunit;
5+
6+
namespace LibGit2Sharp.Tests
7+
{
8+
public partial class MetaFixture
9+
{
10+
[Fact]
11+
public void LibGit2SharpPublicInterfacesCoverAllPublicMembers()
12+
{
13+
var methodsMissingFromInterfaces =
14+
from t in typeof(IRepository).GetTypeInfo().Assembly.GetExportedTypes()
15+
where !t.GetTypeInfo().IsInterface
16+
where t.GetTypeInfo().GetInterfaces().Any(i => i.GetTypeInfo().IsPublic && i.Namespace == typeof(IRepository).Namespace && !explicitOnlyInterfaces.Contains(i))
17+
let interfaceTargetMethods = from i in t.GetTypeInfo().GetInterfaces()
18+
from im in t.GetInterfaceMap(i).TargetMethods
19+
select im
20+
from tm in t.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance)
21+
where !interfaceTargetMethods.Contains(tm)
22+
select t.Name + " has extra method " + tm.Name;
23+
24+
Assert.Equal("", string.Join(Environment.NewLine,
25+
methodsMissingFromInterfaces.ToArray()));
26+
}
27+
28+
[Fact]
29+
public void LibGit2SharpExplicitOnlyInterfacesAreIndeedExplicitOnly()
30+
{
31+
var methodsMissingFromInterfaces =
32+
from t in typeof(IRepository).GetTypeInfo().Assembly.GetExportedTypes()
33+
where t.GetInterfaces().Any(explicitOnlyInterfaces.Contains)
34+
let interfaceTargetMethods = from i in t.GetInterfaces()
35+
where explicitOnlyInterfaces.Contains(i)
36+
from im in t.GetTypeInfo().GetInterfaceMap(i).TargetMethods
37+
select im
38+
from tm in t.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance)
39+
where interfaceTargetMethods.Contains(tm)
40+
select t.Name + " has public method " + tm.Name + " which should be explicitly implemented.";
41+
42+
Assert.Equal("", string.Join(Environment.NewLine,
43+
methodsMissingFromInterfaces.ToArray()));
44+
}
45+
}
46+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)