|
| 1 | +using commonItems; |
1 | 2 | using commonItems.Exceptions; |
2 | 3 | using commonItems.Mods; |
3 | 4 | using System; |
|
8 | 9 | namespace ImperatorToCK3.UnitTests; |
9 | 10 |
|
10 | 11 | public class ConfigurationTests { |
| 12 | + [Fact] |
| 13 | + public void TrailingSlashesAreTrimmedFromProvidedPaths() { |
| 14 | + const string configurationPath = "configuration.txt"; |
| 15 | + var tempRoot = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); |
| 16 | + var imperatorPath = Path.Combine(tempRoot, "imperator"); |
| 17 | + var imperatorDocPath = Path.Combine(tempRoot, "imperator_docs"); |
| 18 | + var ck3Path = Path.Combine(tempRoot, "ck3"); |
| 19 | + var ck3ModsPath = Path.Combine(tempRoot, "Paradox Interactive", "Crusader Kings III", "mod"); |
| 20 | + |
| 21 | + Directory.CreateDirectory(Path.Combine(imperatorPath, "binaries")); |
| 22 | + Directory.CreateDirectory(Path.Combine(imperatorPath, "launcher")); |
| 23 | + Directory.CreateDirectory(Path.Combine(imperatorDocPath, "mod")); |
| 24 | + Directory.CreateDirectory(Path.Combine(ck3Path, "binaries")); |
| 25 | + Directory.CreateDirectory(Path.Combine(ck3Path, "launcher")); |
| 26 | + Directory.CreateDirectory(ck3ModsPath); |
| 27 | + |
| 28 | + var imperatorExeName = OperatingSystem.IsWindows() ? "imperator.exe" : "imperator"; |
| 29 | + var ck3ExeName = OperatingSystem.IsWindows() ? "ck3.exe" : "ck3"; |
| 30 | + File.WriteAllText(Path.Combine(imperatorPath, "binaries", imperatorExeName), ""); |
| 31 | + File.WriteAllText(Path.Combine(ck3Path, "binaries", ck3ExeName), ""); |
| 32 | + File.WriteAllText(Path.Combine(imperatorPath, "launcher", "launcher-settings.json"), "{\"version\":\"2.0.4\"}"); |
| 33 | + File.WriteAllText(Path.Combine(ck3Path, "launcher", "launcher-settings.json"), "{\"version\":\"1.15.0\"}"); |
| 34 | + |
| 35 | + var imperatorPathForConfig = imperatorPath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); |
| 36 | + var imperatorDocPathForConfig = imperatorDocPath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); |
| 37 | + var ck3PathForConfig = ck3Path.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); |
| 38 | + var ck3ModsPathForConfig = ck3ModsPath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); |
| 39 | + |
| 40 | + var imperatorPathWithTrailingSlash = imperatorPathForConfig + Path.AltDirectorySeparatorChar; |
| 41 | + var imperatorDocPathWithTrailingSlash = imperatorDocPathForConfig + Path.AltDirectorySeparatorChar; |
| 42 | + var ck3PathWithTrailingSlash = ck3PathForConfig + Path.AltDirectorySeparatorChar; |
| 43 | + var ck3ModsPathWithTrailingSlash = ck3ModsPathForConfig + Path.AltDirectorySeparatorChar; |
| 44 | + |
| 45 | + try { |
| 46 | + string content = |
| 47 | + $"ImperatorDirectory = \"{imperatorPathWithTrailingSlash}\"{Environment.NewLine}" + |
| 48 | + $"ImperatorDocDirectory = \"{imperatorDocPathWithTrailingSlash}\"{Environment.NewLine}" + |
| 49 | + $"CK3directory = \"{ck3PathWithTrailingSlash}\"{Environment.NewLine}" + |
| 50 | + $"targetGameModPath = \"{ck3ModsPathWithTrailingSlash}\"{Environment.NewLine}"; |
| 51 | + |
| 52 | + File.WriteAllText(configurationPath, content); |
| 53 | + var config = new Configuration(new ConverterVersion()); |
| 54 | + |
| 55 | + Assert.Equal(imperatorPathForConfig, config.ImperatorPath); |
| 56 | + Assert.Equal(imperatorDocPathForConfig, config.ImperatorDocPath); |
| 57 | + Assert.Equal(ck3PathForConfig, config.CK3Path); |
| 58 | + Assert.Equal(ck3ModsPathForConfig, config.CK3ModsPath); |
| 59 | + } |
| 60 | + finally { |
| 61 | + File.Delete(configurationPath); |
| 62 | + Directory.Delete(tempRoot, recursive: true); |
| 63 | + } |
| 64 | + } |
| 65 | + |
11 | 66 | [Fact] |
12 | 67 | public void DetectSpecificCK3ModsThrowsExceptionForUnsupportedModCombinations() { |
13 | 68 | const string tfeName = "The Fallen Eagle"; |
|
0 commit comments