-
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.
Add some tests to simplify testing changes to MEWT and SEWT. They must be run one at a time, but it's better than the manual I was doing before.
- Loading branch information
1 parent
bcfa519
commit fe4973f
Showing
8 changed files
with
190 additions
and
4 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
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,104 @@ | ||
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 | ||
{ | ||
[TestFixture] | ||
[RequiresThread] | ||
[NonParallelizable] | ||
public abstract class IntegrationBase | ||
{ | ||
#region Base Setup | ||
protected readonly string _parameterPrefix = "SE"; | ||
protected string[] _extraArguments = new string[0]; | ||
|
||
public IntegrationBase() | ||
{ | ||
if (this.GetType().Namespace.EndsWith("ME")) | ||
_parameterPrefix = "ME"; | ||
} | ||
|
||
protected int LaunchMain(string[] args) | ||
{ | ||
if (_parameterPrefix == "SE") | ||
{ | ||
return SEWorkshopTool.Program.Main(args); | ||
} | ||
else | ||
{ | ||
// ME calls GetEntryAssembly, which is null when called from NUnit | ||
SetEntryAssembly(typeof(MEWorkshopTool.Program).Assembly); | ||
return MEWorkshopTool.Program.Main(args); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Allows setting the Entry Assembly when needed. | ||
/// Use AssemblyUtilities.SetEntryAssembly() as first line in XNA ad hoc tests | ||
/// </summary> | ||
/// <param name="assembly">Assembly to set as entry assembly</param> | ||
public static void SetEntryAssembly(Assembly assembly) | ||
{ | ||
AppDomainManager manager = new AppDomainManager(); | ||
FieldInfo entryAssemblyfield = manager.GetType().GetField("m_entryAssembly", BindingFlags.Instance | BindingFlags.NonPublic); | ||
entryAssemblyfield.SetValue(manager, assembly); | ||
|
||
AppDomain domain = AppDomain.CurrentDomain; | ||
FieldInfo domainManagerField = domain.GetType().GetField("_domainManager", BindingFlags.Instance | BindingFlags.NonPublic); | ||
domainManagerField.SetValue(domain, manager); | ||
} | ||
|
||
[OneTimeSetUp] | ||
public virtual void OneTimeSetup() | ||
{ | ||
Environment.CurrentDirectory = TestContext.Parameters[$"{_parameterPrefix}.Install"]; | ||
|
||
if (TestContext.Parameters.Exists($"{_parameterPrefix}.AppData")) | ||
{ | ||
_extraArguments = new[] { "--appdata", TestContext.Parameters[$"{_parameterPrefix}.AppData"] }; | ||
} | ||
|
||
} | ||
#endregion Base Setup | ||
|
||
#region Common Tests | ||
[Test] | ||
[Explicit] | ||
public void DownloadMod() | ||
{ | ||
var args = new List<string>(new[] { "--download", "--mods", TestContext.Parameters[$"{_parameterPrefix}.ModIDToDownload"], "--extract" }); | ||
args.AddRange(_extraArguments); | ||
|
||
var exitCode = LaunchMain(args.ToArray()); | ||
Assert.That(exitCode, Is.EqualTo(0)); | ||
} | ||
|
||
[Test] | ||
[Explicit] | ||
public void UploadMod() | ||
{ | ||
var args = new List<string>(new[] { "--upload", "--mods", TestContext.Parameters[$"{_parameterPrefix}.ModNameToUpload"], "--tags", "Mod" }); | ||
args.AddRange(_extraArguments); | ||
|
||
var exitCode = LaunchMain(args.ToArray()); | ||
Assert.That(exitCode, Is.EqualTo(0)); | ||
} | ||
|
||
[Test] | ||
[Explicit] | ||
public void UpdateTags() | ||
{ | ||
var args = new List<string>(new[] { "--update-only", "--mods", TestContext.Parameters[$"{_parameterPrefix}.ModNameToUpload"], "--tags", "Mod,Other" }); | ||
args.AddRange(_extraArguments); | ||
|
||
var exitCode = LaunchMain(args.ToArray()); | ||
Assert.That(exitCode, Is.EqualTo(0)); | ||
} | ||
#endregion Common Tests | ||
} | ||
} |
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,10 @@ | ||
using NUnit.Framework; | ||
using System.Collections.Generic; | ||
|
||
namespace Phoenix.WorkshopTool.Tests.ME | ||
{ | ||
// Medieval Engineers MEWT Integration tests | ||
public class Integration : IntegrationBase | ||
{ | ||
} | ||
} |
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,10 @@ | ||
using NUnit.Framework; | ||
using System.Collections.Generic; | ||
|
||
namespace Phoenix.WorkshopTool.Tests.SE | ||
{ | ||
// Space Engineers SEWT Integration tests | ||
public class Integration : IntegrationBase | ||
{ | ||
} | ||
} |
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,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net461</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
|
||
<AssemblyName>Phoenix.WorkshopTool.Tests</AssemblyName> | ||
|
||
<RootNamespace>Phoenix.WorkshopTool.Tests</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<PlatformTarget>x64</PlatformTarget> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="nunit" Version="3.10.1" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\MEWorkshopTool\MEWorkshopTool.csproj" /> | ||
<ProjectReference Include="..\SEWorkshopTool\SEWorkshopTool.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RunSettings> | ||
<!-- Configurations that affect the Test Framework --> | ||
<RunConfiguration> | ||
<!-- Path relative to solution directory --> | ||
<ResultsDirectory>.\TestResults</ResultsDirectory> | ||
<TargetPlatform>x64</TargetPlatform> | ||
<TargetFrameworkVersion>Framework45</TargetFrameworkVersion> | ||
</RunConfiguration> | ||
|
||
<!-- Parameters used by tests at runtime --> | ||
<TestRunParameters> | ||
<Parameter name="SE.Install" value="D:\Program Files\Steam\SteamApps\common\SpaceEngineers" /> | ||
<Parameter name="SE.ModIDToDownload" value="637504549" /> | ||
<Parameter name="SE.ModNameToUpload" value="test-dev" /> | ||
<!-- <Parameter name="SE.AppData" value="" /> --> | ||
|
||
<Parameter name="ME.Install" value="D:\Program Files\Steam\SteamApps\common\MedievalEngineers" /> | ||
<Parameter name="ME.ModIDToDownload" value="1342545091" /> | ||
<Parameter name="ME.ModNameToUpload" value="PickaxeMod_mewt" /> | ||
<!-- <Parameter name="ME.AppData" value="" /> --> | ||
</TestRunParameters> | ||
|
||
<!-- Adapter Specific sections --> | ||
</RunSettings> |
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