mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-03-30 13:20:13 +00:00
add patch tests and run tests on build (so fail build if tests fail)
This commit is contained in:
parent
85eb03f3c8
commit
c44ea2cc54
41
QSBTests/PatchTests.cs
Normal file
41
QSBTests/PatchTests.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using QSB.Patches;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace QSBTests
|
||||
{
|
||||
[TestClass]
|
||||
public class PatchTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void CheckUnreferencedPatches()
|
||||
{
|
||||
var qsbAssembly = Assembly.Load("QSB");
|
||||
var allPatchTypes = qsbAssembly
|
||||
.GetTypes()
|
||||
.Where(x => typeof(QSBPatch).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract);
|
||||
|
||||
QSBPatchManager.Init();
|
||||
var patchInstances = (List<QSBPatch>)typeof(QSBPatchManager)
|
||||
.GetField("_patchList", BindingFlags.NonPublic | BindingFlags.Static)
|
||||
.GetValue(typeof(QSBPatchManager));
|
||||
|
||||
var failedTypes = new List<Type>();
|
||||
foreach (var type in allPatchTypes)
|
||||
{
|
||||
if (!patchInstances.Any(x => x.GetType() == type))
|
||||
{
|
||||
failedTypes.Add(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (failedTypes.Count > 0)
|
||||
{
|
||||
Assert.Fail(string.Join(", ", failedTypes.Select(x => x.Name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -50,6 +50,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="EventTests.cs" />
|
||||
<Compile Include="PatchTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="UtilityTests.cs" />
|
||||
</ItemGroup>
|
||||
@ -72,4 +73,7 @@
|
||||
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>dotnet test "$(SolutionDir)\QSBTests\$(OutDir)\QSBTests.dll"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user