Skip to content

Commit ba523ac

Browse files
committed
Test project and new versioning system.
1 parent 53af757 commit ba523ac

12 files changed

Lines changed: 346 additions & 30 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<ProjectGuid>{59A47A68-8B18-4942-B082-BCB52ED6D66D}</ProjectGuid>
6+
<OutputType>Library</OutputType>
7+
<AppDesignerFolder>Properties</AppDesignerFolder>
8+
<RootNamespace>Essentials.Tests</RootNamespace>
9+
<AssemblyName>Essentials.Tests</AssemblyName>
10+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
11+
<FileAlignment>512</FileAlignment>
12+
<TargetFrameworkProfile />
13+
<NuGetPackageImportStamp>
14+
</NuGetPackageImportStamp>
15+
<NoWarn>1591,0649</NoWarn>
16+
</PropertyGroup>
17+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
18+
<DebugSymbols>true</DebugSymbols>
19+
<OutputPath>$(SolutionDir)\bin-test\x64\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<DebugType>full</DebugType>
22+
<PlatformTarget>x64</PlatformTarget>
23+
<ErrorReport>prompt</ErrorReport>
24+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
25+
</PropertyGroup>
26+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
27+
<OutputPath>$(SolutionDir)\bin-test\x64\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<Optimize>true</Optimize>
30+
<DebugType>pdbonly</DebugType>
31+
<PlatformTarget>x64</PlatformTarget>
32+
<ErrorReport>prompt</ErrorReport>
33+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
34+
<DocumentationFile>$(SolutionDir)\bin-test\x64\Release\Essentials.Tests.xml</DocumentationFile>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
38+
<HintPath>..\packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath>
39+
<Private>True</Private>
40+
</Reference>
41+
<Reference Include="System" />
42+
<Reference Include="System.Core" />
43+
<Reference Include="System.Xml.Linq" />
44+
<Reference Include="System.Data.DataSetExtensions" />
45+
<Reference Include="Microsoft.CSharp" />
46+
<Reference Include="System.Data" />
47+
<Reference Include="System.Net.Http" />
48+
<Reference Include="System.Xml" />
49+
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
50+
<HintPath>..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
51+
</Reference>
52+
<Reference Include="xunit.assert, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
53+
<HintPath>..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll</HintPath>
54+
</Reference>
55+
<Reference Include="xunit.core, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
56+
<HintPath>..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll</HintPath>
57+
</Reference>
58+
<Reference Include="xunit.execution.desktop, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
59+
<HintPath>..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll</HintPath>
60+
</Reference>
61+
<Reference Include="Torch">
62+
<HintPath>$(SolutionDir)\TorchBinaries\Torch.dll</HintPath>
63+
<Private>True</Private>
64+
</Reference>
65+
<Reference Include="Torch.API">
66+
<HintPath>$(SolutionDir)\TorchBinaries\Torch.API.dll</HintPath>
67+
<Private>True</Private>
68+
</Reference>
69+
</ItemGroup>
70+
<ItemGroup>
71+
<Compile Include="..\Versioning\AssemblyVersion.cs">
72+
<Link>Properties\AssemblyVersion.cs</Link>
73+
</Compile>
74+
<Compile Include="Properties\AssemblyInfo.cs" />
75+
<Compile Include="ReflectionTestManager.cs" />
76+
<Compile Include="TestUtils.cs" />
77+
<Compile Include="TorchReflectionTest.cs" />
78+
</ItemGroup>
79+
<ItemGroup>
80+
<ProjectReference Include="..\Essentials\Essentials.csproj">
81+
<Project>{A4C5FC37-5848-4A75-8CDC-4A1ADB2E01A2}</Project>
82+
<Name>Essentials</Name>
83+
<Private>True</Private>
84+
</ProjectReference>
85+
</ItemGroup>
86+
<ItemGroup>
87+
<None Include="packages.config" />
88+
</ItemGroup>
89+
<ItemGroup>
90+
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
91+
</ItemGroup>
92+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
93+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
[assembly: AssemblyTitle("Torch Tests")]
5+
[assembly: AssemblyDescription("")]
6+
[assembly: AssemblyCompany("")]
7+
[assembly: AssemblyProduct("Torch")]
8+
[assembly: AssemblyCopyright("Copyright © Torch API 2017")]
9+
[assembly: AssemblyTrademark("")]
10+
[assembly: AssemblyCulture("")]
11+
[assembly: ComVisible(false)]
12+
13+
#if DEBUG
14+
[assembly: AssemblyConfiguration("Debug")]
15+
#else
16+
[assembly: AssemblyConfiguration("Release")]
17+
#endif
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
using Torch.Utils;
5+
6+
namespace Torch.Tests
7+
{
8+
public class ReflectionTestManager
9+
{
10+
#region FieldProvider
11+
public struct FieldRef
12+
{
13+
public FieldInfo Field;
14+
15+
public FieldRef(FieldInfo f)
16+
{
17+
Field = f;
18+
}
19+
20+
public override string ToString()
21+
{
22+
if (Field == null)
23+
return "Ignored";
24+
return Field.DeclaringType?.FullName + "." + Field.Name;
25+
}
26+
}
27+
28+
private readonly HashSet<object[]> _getters = new HashSet<object[]>();
29+
private readonly HashSet<object[]> _setters = new HashSet<object[]>();
30+
private readonly HashSet<object[]> _invokers = new HashSet<object[]>();
31+
32+
public ReflectionTestManager()
33+
{
34+
_getters.Add(new object[] { new FieldRef(null) });
35+
_setters.Add(new object[] { new FieldRef(null) });
36+
_invokers.Add(new object[] { new FieldRef(null) });
37+
}
38+
39+
public ReflectionTestManager Init(Assembly asm)
40+
{
41+
foreach (Type type in asm.GetTypes())
42+
Init(type);
43+
return this;
44+
}
45+
46+
public ReflectionTestManager Init(Type type)
47+
{
48+
foreach (FieldInfo field in type.GetFields(BindingFlags.Static |
49+
BindingFlags.Instance |
50+
BindingFlags.Public |
51+
BindingFlags.NonPublic))
52+
{
53+
if (field.GetCustomAttribute<ReflectedMethodAttribute>() != null)
54+
_invokers.Add(new object[] { new FieldRef(field) });
55+
if (field.GetCustomAttribute<ReflectedGetterAttribute>() != null)
56+
_getters.Add(new object[] { new FieldRef(field) });
57+
if (field.GetCustomAttribute<ReflectedSetterAttribute>() != null)
58+
_setters.Add(new object[] { new FieldRef(field) });
59+
}
60+
return this;
61+
}
62+
63+
public IEnumerable<object[]> Getters => _getters;
64+
65+
public IEnumerable<object[]> Setters => _setters;
66+
67+
public IEnumerable<object[]> Invokers => _invokers;
68+
69+
#endregion
70+
71+
}
72+
}

‎Essentials.Tests/TestUtils.cs‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Torch.Utils;
8+
9+
namespace Torch.Tests
10+
{
11+
public sealed class TestUtils
12+
{
13+
public static void Init()
14+
{
15+
if (_torchResolver == null)
16+
_torchResolver = new TorchAssemblyResolver(GetGameBinaries());
17+
}
18+
19+
private static string GetGameBinaries()
20+
{
21+
string dir = Environment.CurrentDirectory;
22+
while (!string.IsNullOrWhiteSpace(dir))
23+
{
24+
string gameBin = Path.Combine(dir, "GameBinaries");
25+
if (Directory.Exists(gameBin))
26+
return gameBin;
27+
28+
dir = Path.GetDirectoryName(dir);
29+
}
30+
throw new Exception("GetGameBinaries failed to find a folder named GameBinaries in the directory tree");
31+
}
32+
33+
private static TorchAssemblyResolver _torchResolver;
34+
}
35+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
8+
using Torch.Tests;
9+
using Torch.Utils;
10+
using Xunit;
11+
12+
namespace Essentials.Tests
13+
{
14+
public class TorchReflectionTest
15+
{
16+
static TorchReflectionTest()
17+
{
18+
TestUtils.Init();
19+
}
20+
21+
private static ReflectionTestManager _manager;
22+
23+
private static ReflectionTestManager Manager()
24+
{
25+
TestUtils.Init();
26+
if (_manager != null)
27+
return _manager;
28+
return _manager = new ReflectionTestManager().Init(typeof(EssentialsPlugin).Assembly);
29+
}
30+
31+
public static IEnumerable<object[]> Getters => Manager().Getters;
32+
33+
public static IEnumerable<object[]> Setters => Manager().Setters;
34+
35+
public static IEnumerable<object[]> Invokers => Manager().Invokers;
36+
37+
#region Binding
38+
[Theory]
39+
[MemberData(nameof(Getters))]
40+
public void TestBindingGetter(ReflectionTestManager.FieldRef field)
41+
{
42+
if (field.Field == null)
43+
return;
44+
Assert.True(ReflectedManager.Process(field.Field));
45+
if (field.Field.IsStatic)
46+
Assert.NotNull(field.Field.GetValue(null));
47+
}
48+
49+
[Theory]
50+
[MemberData(nameof(Setters))]
51+
public void TestBindingSetter(ReflectionTestManager.FieldRef field)
52+
{
53+
if (field.Field == null)
54+
return;
55+
Assert.True(ReflectedManager.Process(field.Field));
56+
if (field.Field.IsStatic)
57+
Assert.NotNull(field.Field.GetValue(null));
58+
}
59+
60+
[Theory]
61+
[MemberData(nameof(Invokers))]
62+
public void TestBindingInvoker(ReflectionTestManager.FieldRef field)
63+
{
64+
if (field.Field == null)
65+
return;
66+
Assert.True(ReflectedManager.Process(field.Field));
67+
if (field.Field.IsStatic)
68+
Assert.NotNull(field.Field.GetValue(null));
69+
}
70+
#endregion
71+
}
72+
}

‎Essentials.Tests/packages.config‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Mono.TextTransform" version="1.0.0" targetFramework="net461" />
4+
<package id="NLog" version="4.4.12" targetFramework="net461" />
5+
<package id="xunit" version="2.2.0" targetFramework="net461" />
6+
<package id="xunit.abstractions" version="2.0.1" targetFramework="net461" />
7+
<package id="xunit.assert" version="2.2.0" targetFramework="net461" />
8+
<package id="xunit.core" version="2.2.0" targetFramework="net461" />
9+
<package id="xunit.extensibility.core" version="2.2.0" targetFramework="net461" />
10+
<package id="xunit.extensibility.execution" version="2.2.0" targetFramework="net461" />
11+
<package id="xunit.runner.console" version="2.2.0" targetFramework="net461" developmentDependency="true" />
12+
</packages>

‎Essentials.sln‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.26730.8
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Essentials", "Essentials\Essentials.csproj", "{A4C5FC37-5848-4A75-8CDC-4A1ADB2E01A2}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Essentials.Tests", "Essentials.Tests\Essentials.Tests.csproj", "{59A47A68-8B18-4942-B082-BCB52ED6D66D}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|x64 = Debug|x64
@@ -15,6 +17,10 @@ Global
1517
{A4C5FC37-5848-4A75-8CDC-4A1ADB2E01A2}.Debug|x64.Build.0 = Debug|x64
1618
{A4C5FC37-5848-4A75-8CDC-4A1ADB2E01A2}.Release|x64.ActiveCfg = Release|x64
1719
{A4C5FC37-5848-4A75-8CDC-4A1ADB2E01A2}.Release|x64.Build.0 = Release|x64
20+
{59A47A68-8B18-4942-B082-BCB52ED6D66D}.Debug|x64.ActiveCfg = Debug|x64
21+
{59A47A68-8B18-4942-B082-BCB52ED6D66D}.Debug|x64.Build.0 = Debug|x64
22+
{59A47A68-8B18-4942-B082-BCB52ED6D66D}.Release|x64.ActiveCfg = Release|x64
23+
{59A47A68-8B18-4942-B082-BCB52ED6D66D}.Release|x64.Build.0 = Release|x64
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

‎Essentials/Essentials.csproj‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@
136136
<Reference Include="WindowsBase" />
137137
</ItemGroup>
138138
<ItemGroup>
139+
<Compile Include="..\Versioning\AssemblyVersion.cs">
140+
<Link>Properties\AssemblyVersion.cs</Link>
141+
</Compile>
139142
<Compile Include="AutoCommand.cs" />
140143
<Compile Include="Commands\BlocksModule.cs" />
141144
<Compile Include="Commands\CleanupModule.cs" />
Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,17 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
43

5-
// General Information about an assembly is controlled through the following
6-
// set of attributes. Change these attribute values to modify the information
7-
// associated with an assembly.
84
[assembly: AssemblyTitle("Essentials")]
95
[assembly: AssemblyDescription("")]
10-
[assembly: AssemblyConfiguration("")]
116
[assembly: AssemblyCompany("")]
12-
[assembly: AssemblyProduct("Essentials")]
13-
[assembly: AssemblyCopyright("Copyright © 2017")]
7+
[assembly: AssemblyProduct("Torch")]
8+
[assembly: AssemblyCopyright("Copyright © Torch API 2017")]
149
[assembly: AssemblyTrademark("")]
1510
[assembly: AssemblyCulture("")]
16-
17-
// Setting ComVisible to false makes the types in this assembly not visible
18-
// to COM components. If you need to access a type in this assembly from
19-
// COM, set the ComVisible attribute to true on that type.
2011
[assembly: ComVisible(false)]
2112

22-
// The following GUID is for the ID of the typelib if this project is exposed to COM
23-
[assembly: Guid("a4c5fc37-5848-4a75-8cdc-4a1adb2e01a2")]
24-
25-
// Version information for an assembly consists of the following four values:
26-
//
27-
// Major Version
28-
// Minor Version
29-
// Build Number
30-
// Revision
31-
//
32-
// You can specify all the values or you can default the Build and Revision Numbers
33-
// by using the '*' as shown below:
34-
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
13+
#if DEBUG
14+
[assembly: AssemblyConfiguration("Debug")]
15+
#else
16+
[assembly: AssemblyConfiguration("Release")]
17+
#endif

0 commit comments

Comments
 (0)