-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize reflection code and add tests.
Reflection tests require each test fixture to run in its own AppDomain, so each game's assemblies don't interfere. It would be better to split this into two test assemblies now.
- Loading branch information
1 parent
902c864
commit b00f8ea
Showing
13 changed files
with
580 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
extern alias me; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using M = me::Phoenix.WorkshopTool; | ||
|
||
namespace Phoenix.WorkshopTool.Tests.Common | ||
{ | ||
[TestFixture] | ||
[RunInApplicationDomain] | ||
[Category("NoSteam")] | ||
public abstract class ReflectionTests : GameTestBase | ||
{ | ||
[Test] | ||
public void PublishItemBlockingTest() | ||
{ | ||
MethodInfo method; | ||
|
||
if(ParameterPrefix == "SE") | ||
method = typeof(WorkshopHelper).GetMethod("ReflectPublishItemBlocking", BindingFlags.Static | BindingFlags.NonPublic); | ||
else | ||
method = typeof(M.WorkshopHelper).GetMethod("ReflectPublishItemBlocking", BindingFlags.Static | BindingFlags.NonPublic); | ||
|
||
Assert.NotNull(method); | ||
|
||
var result = method.Invoke(null, new object[] { }); | ||
Assert.NotNull(result); | ||
} | ||
|
||
[Test] | ||
public void LoadScriptsTest() | ||
{ | ||
MethodInfo method; | ||
|
||
if (ParameterPrefix == "SE") | ||
method = typeof(WorkshopHelper).GetMethod("ReflectLoadScripts", BindingFlags.Static | BindingFlags.NonPublic); | ||
else | ||
method = typeof(M.WorkshopHelper).GetMethod("ReflectLoadScripts", BindingFlags.Static | BindingFlags.NonPublic); | ||
|
||
Assert.NotNull(method); | ||
|
||
var result = method.Invoke(null, new object[] { }); | ||
Assert.NotNull(result); | ||
} | ||
|
||
[TestCase(new object[] { typeof(string), typeof(string) })] | ||
[TestCase(new object[] { typeof(string), typeof(string), typeof(Predicate<string>) })] | ||
public void CopyAllTest(object[] types) | ||
{ | ||
MethodInfo method; | ||
|
||
if (ParameterPrefix == "SE") | ||
method = ReflectionHelper.ReflectFileCopy(types.Cast<Type>().ToArray()); | ||
else | ||
method = M.ReflectionHelper.ReflectFileCopy(types.Cast<Type>().ToArray()); | ||
|
||
Assert.IsNotNull(method); | ||
} | ||
|
||
[Test] | ||
public void UpdatePublishedItemTest() | ||
{ | ||
MethodInfo method; | ||
|
||
if (ParameterPrefix == "SE") | ||
method = WorkshopHelper.ReflectSteamWorkshopItemPublisherMethod("UpdatePublishedItem", BindingFlags.Instance | BindingFlags.NonPublic); | ||
else | ||
method = M.WorkshopHelper.ReflectSteamWorkshopItemPublisherMethod("UpdatePublishedItem", BindingFlags.Instance | BindingFlags.Public); | ||
|
||
Assert.IsNotNull(method); | ||
} | ||
|
||
[TestCase("SubmitItemUpdateResult")] | ||
public void ItemPublisherMethodTest(string name) | ||
{ | ||
MethodInfo method; | ||
|
||
if (ParameterPrefix == "SE") | ||
method = WorkshopHelper.ReflectSteamWorkshopItemPublisherMethod(name); | ||
else | ||
method = M.WorkshopHelper.ReflectSteamWorkshopItemPublisherMethod(name); | ||
|
||
Assert.IsNotNull(method); | ||
} | ||
|
||
[TestCase("m_steamService")] | ||
[TestCase("m_submitItemUpdateResult")] | ||
public void ItemPublisherFieldTest(string name) | ||
{ | ||
FieldInfo method; | ||
|
||
if (ParameterPrefix == "SE") | ||
method = WorkshopHelper.ReflectSteamWorkshopItemPublisherField(name); | ||
else | ||
method = M.WorkshopHelper.ReflectSteamWorkshopItemPublisherField(name); | ||
|
||
Assert.IsNotNull(method); | ||
} | ||
|
||
[TestCase("SteamUGC")] | ||
public void ItemPublisherPropertyTest(string name) | ||
{ | ||
PropertyInfo method; | ||
|
||
if (ParameterPrefix == "SE") | ||
method = WorkshopHelper.ReflectSteamWorkshopItemPublisherProperty(name); | ||
else | ||
method = M.WorkshopHelper.ReflectSteamWorkshopItemPublisherProperty(name); | ||
|
||
Assert.IsNotNull(method); | ||
} | ||
|
||
[Test] | ||
public void SteamAppRunningTest() | ||
{ | ||
MethodInfo method; | ||
|
||
if (ParameterPrefix == "SE") | ||
method = ReflectionHelper.ReflectSteamRestartApp(); | ||
else | ||
method = M.ReflectionHelper.ReflectSteamRestartApp(); | ||
|
||
Assert.IsNotNull(method); | ||
} | ||
|
||
[Test] | ||
public void InitSteamWorkshopTest() | ||
{ | ||
MethodInfo method; | ||
|
||
if (ParameterPrefix == "SE") | ||
method = WorkshopHelper.ReflectInitSteamWorkshop(); | ||
else | ||
method = M.WorkshopHelper.ReflectInitSteamWorkshop(); | ||
|
||
Assert.IsNotNull(method); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
extern alias me; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Phoenix.WorkshopTool.Tests | ||
{ | ||
/// <summary> | ||
/// Represents a test fixture that requires the game assemblies. | ||
/// </summary> | ||
[TestFixture] | ||
public abstract class GameTestBase | ||
{ | ||
#region Base Setup | ||
protected string _previousDirectory; | ||
|
||
public GameTestBase() | ||
{ | ||
} | ||
|
||
internal abstract string ParameterPrefix { get; } | ||
|
||
[OneTimeSetUp] | ||
public virtual void OneTimeSetup() | ||
{ | ||
if (AppDomainRunner.IsNotInTestAppDomain) | ||
{ | ||
_previousDirectory = Environment.CurrentDirectory; | ||
Environment.CurrentDirectory = TestContext.Parameters[$"{ParameterPrefix}.Install"]; | ||
} | ||
else | ||
{ | ||
if (ParameterPrefix == "ME") | ||
AppDomain.CurrentDomain.AssemblyResolve += me::Phoenix.WorkshopTool.GameBase.CurrentDomain_AssemblyResolve; | ||
else | ||
AppDomain.CurrentDomain.AssemblyResolve += GameBase.CurrentDomain_AssemblyResolve; | ||
} | ||
} | ||
|
||
[OneTimeTearDown] | ||
public virtual void OneTimeTearDown() | ||
{ | ||
if (AppDomainRunner.IsNotInTestAppDomain) | ||
{ | ||
Environment.CurrentDirectory = _previousDirectory; | ||
} | ||
else | ||
{ | ||
if (ParameterPrefix == "ME") | ||
AppDomain.CurrentDomain.AssemblyResolve -= me::Phoenix.WorkshopTool.GameBase.CurrentDomain_AssemblyResolve; | ||
else | ||
AppDomain.CurrentDomain.AssemblyResolve -= GameBase.CurrentDomain_AssemblyResolve; | ||
} | ||
} | ||
#endregion Base Setup | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
extern alias me; | ||
|
||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using M = me::Phoenix.WorkshopTool; | ||
|
||
|
||
namespace Phoenix.WorkshopTool.Tests.ME | ||
{ | ||
[TestFixture] | ||
[RunInApplicationDomain] | ||
[Category("NoSteam")] | ||
public class ReflectionTests : Common.ReflectionTests | ||
{ | ||
internal override string ParameterPrefix => "ME"; | ||
|
||
[Test] | ||
public void PublishSuccessTest() | ||
{ | ||
dynamic method = typeof(M.WorkshopHelper).GetMethod("ReflectPublishSuccess", BindingFlags.Static | BindingFlags.NonPublic); | ||
|
||
Assert.NotNull(method); | ||
|
||
var result = method.Invoke(null, new object[] { }); | ||
Assert.NotNull(result); | ||
} | ||
|
||
[Test] | ||
public void CompileMessagesTest() | ||
{ | ||
var method = typeof(M.WorkshopHelper).GetMethod("ReflectCompileMessages", BindingFlags.Static | BindingFlags.NonPublic); | ||
|
||
Assert.NotNull(method); | ||
|
||
var result = method.Invoke(null, new object[] { }); | ||
Assert.NotNull(result); | ||
} | ||
|
||
[TestCase("LoadSystems")] | ||
[TestCase("InitSystems")] | ||
[TestCase("LoadMetadata")] | ||
public void VRageCoreMethodTest(string name) | ||
{ | ||
var method = M.ReflectionHelper.ReflectVRageCoreMethod(name); | ||
|
||
Assert.NotNull(method); | ||
} | ||
|
||
[TestCase("m_state")] | ||
public void VRageCoreFieldTest(string name) | ||
{ | ||
var field = M.ReflectionHelper.ReflectVRageCoreField(name); | ||
|
||
Assert.NotNull(field); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Phoenix.WorkshopTool.Tests.SE | ||
{ | ||
[TestFixture] | ||
[RunInApplicationDomain] | ||
[Category("NoSteam")] | ||
public class ReflectionTests : Common.ReflectionTests | ||
{ | ||
internal override string ParameterPrefix => "SE"; | ||
|
||
[Test] | ||
public void ToServiceTest() | ||
{ | ||
var method = WorkshopHelper.ReflectToService(); | ||
Assert.IsNotNull(method); | ||
} | ||
|
||
[Test] | ||
public void ToSteamTest() | ||
{ | ||
var method = WorkshopHelper.ReflectToSteam(); | ||
Assert.IsNotNull(method); | ||
} | ||
|
||
[Test] | ||
public void ModIoCreateRequestTest() | ||
{ | ||
var method = WorkshopHelper.ReflectCreateRequest(); | ||
Assert.IsNotNull(method); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.