-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from tolik518/refactorings
refactorings
- Loading branch information
Showing
22 changed files
with
1,917 additions
and
1,546 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,142 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using Xunit; | ||
|
||
namespace SoG_SGreader.Test | ||
{ | ||
public class IntegrationTests | ||
{ | ||
private static string GetExePath() | ||
{ | ||
string projectDirectory = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.Parent.FullName; | ||
|
||
// Exception for GitHub Actions Test Runner | ||
if (Environment.GetEnvironmentVariable("GITHUB_WORKSPACE") != null) { | ||
projectDirectory = Environment.GetEnvironmentVariable("GITHUB_WORKSPACE"); | ||
return Path.Combine(projectDirectory, "SoG_SGreader", "bin", "Release", "SoG_SGreader.exe"); | ||
} | ||
|
||
return Path.Combine(projectDirectory, "SoG_SGreader", "bin", "Debug", "SoG_SGreader.exe"); | ||
} | ||
|
||
private static string GetSaveGamePath(string saveGameNumber) | ||
{ | ||
string projectDirectory = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.Parent.FullName; | ||
|
||
// Exception for GitHub Actions Test Runner | ||
if (Environment.GetEnvironmentVariable("GITHUB_WORKSPACE") != null) { | ||
projectDirectory = Environment.GetEnvironmentVariable("GITHUB_WORKSPACE"); | ||
} | ||
|
||
return Path.Combine(projectDirectory, "SoG_SGreader.Test", "SaveGames", saveGameNumber + ".cha"); | ||
} | ||
|
||
[Fact] | ||
public void TestBadPath() | ||
{ | ||
string arguments = "-t " + GetSaveGamePath("doesntexist"); | ||
|
||
// Start the process | ||
using var process = new Process | ||
{ | ||
StartInfo = new ProcessStartInfo | ||
{ | ||
FileName = GetExePath(), | ||
Arguments = arguments, | ||
RedirectStandardOutput = true, | ||
UseShellExecute = false, | ||
CreateNoWindow = true, | ||
} | ||
}; | ||
|
||
process.Start(); | ||
string output = process.StandardOutput.ReadToEnd(); | ||
process.WaitForExit(); | ||
|
||
Assert.Contains("Could not find file", output); | ||
Assert.Contains(Path.Combine("SaveGames", "doesntexist.cha"), output); | ||
} | ||
|
||
[Fact] | ||
public void TestTextOutput() | ||
{ | ||
string arguments = "-t " + GetSaveGamePath("1"); | ||
|
||
// Start the process | ||
using var process = new Process | ||
{ | ||
StartInfo = new ProcessStartInfo | ||
{ | ||
FileName = GetExePath(), | ||
Arguments = arguments, | ||
RedirectStandardOutput = true, | ||
UseShellExecute = false, | ||
CreateNoWindow = true, | ||
} | ||
}; | ||
|
||
process.Start(); | ||
string output = process.StandardOutput.ReadToEnd(); | ||
process.WaitForExit(); | ||
|
||
Assert.Contains("Filesize: 4494", output); | ||
Assert.Contains("Birthday: 24.6.1081", output); | ||
Assert.Contains("ItemsMetCount: 124", output); | ||
Assert.Contains("KilledEnemiesCount: 58", output); | ||
} | ||
|
||
[Fact] | ||
public void TestJsonOutput() | ||
{ | ||
string arguments = "-j " + GetSaveGamePath("1"); | ||
|
||
// Start the process | ||
using var process = new Process | ||
{ | ||
StartInfo = new ProcessStartInfo | ||
{ | ||
FileName = GetExePath(), | ||
Arguments = arguments, | ||
RedirectStandardOutput = true, | ||
UseShellExecute = false, | ||
CreateNoWindow = true, | ||
} | ||
}; | ||
|
||
process.Start(); | ||
string output = process.StandardOutput.ReadToEnd(); | ||
process.WaitForExit(); | ||
|
||
Assert.Contains("\"MagicByte\": 116", output); | ||
Assert.Contains("\"PlayTimeTotal\": 1645950", output); | ||
Assert.Contains("\"UniquePlayerId\": 451873", output); | ||
Assert.Contains("\"Cash\": 6873538", output); | ||
} | ||
|
||
[Fact] | ||
public void TestPatchOutput() | ||
{ | ||
string arguments = "--patch"; | ||
|
||
// Start the process | ||
using var process = new Process | ||
{ | ||
StartInfo = new ProcessStartInfo | ||
{ | ||
FileName = GetExePath(), | ||
Arguments = arguments, | ||
RedirectStandardOutput = true, | ||
UseShellExecute = false, | ||
CreateNoWindow = true, | ||
} | ||
}; | ||
|
||
process.Start(); | ||
string output = process.StandardOutput.ReadToEnd(); | ||
process.WaitForExit(); | ||
|
||
Assert.Contains(FrmMain.CurrentPatch, output); | ||
} | ||
} | ||
} |
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,22 @@ | ||
using CommandLine; | ||
|
||
namespace SoG_SGreader | ||
{ | ||
class ComandLineOptions | ||
{ | ||
[Value(0, MetaName = "savegame path", Required = false, HelpText = "Path to the savegame")] | ||
public string SavegamePath { get; set; } | ||
|
||
[Option('t', "text", HelpText = "Show a short summary of the savegame")] | ||
public bool ShowText { get; set; } | ||
|
||
[Option('j', "json", HelpText = "Print json of the savegame to console")] | ||
public bool ShowJson { get; set; } | ||
|
||
[Option('h', "help", HelpText = "Show help")] | ||
public bool ShowHelp { get; set; } | ||
|
||
[Option('p', "patch", HelpText = "Show the current supported patch version")] | ||
public bool ShowPatch { get; set; } | ||
} | ||
} |
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.