|
| 1 | +using Civ2engine; |
| 2 | +using Civ2engine.Enums; |
| 3 | +using Civ2engine.Events; |
| 4 | +using Civ2engine.IO; |
| 5 | +using Civ2engine.MapObjects; |
| 6 | +using Civ2engine.SaveLoad; |
| 7 | +using Civ2engine.SaveLoad.SavFile; |
| 8 | +using Civ2engine.Units; |
| 9 | +using Engine.Tests.TestFiles; |
| 10 | +using Model; |
| 11 | +using Model.Core; |
| 12 | +using Model.InterfaceActions; |
| 13 | + |
| 14 | +namespace Engine.Tests; |
| 15 | + |
| 16 | +public class GameLoaderTests |
| 17 | +{ |
| 18 | + [Fact] |
| 19 | + public void TestLoadGameHandlesScenarioFile() |
| 20 | + { |
| 21 | + // Arrange |
| 22 | + var path = TestFileUtils.GetTestFilePath("test_scenario.scn"); |
| 23 | + var savDirectory = TestFileUtils.GetTestFileDirectory(); |
| 24 | + var rules = new Rules(); |
| 25 | + var activeRuleSet = new Ruleset( |
| 26 | + "mock", |
| 27 | + new Dictionary<string, string>(), |
| 28 | + [savDirectory]); |
| 29 | + var savFile = new MockSavFile(); |
| 30 | + var gameLoader = new GameLoader(path, savDirectory, rules, activeRuleSet, savFile); |
| 31 | + var game = new MockGame(); |
| 32 | + var activeInterface = new MockInterface(); |
| 33 | + |
| 34 | + // Act |
| 35 | + var result = gameLoader.LoadGame(game, activeInterface); |
| 36 | + |
| 37 | + // Assert |
| 38 | + Assert.NotNull(result); |
| 39 | + Assert.IsAssignableFrom<IInterfaceAction>(result); |
| 40 | + } |
| 41 | + |
| 42 | + [Fact] |
| 43 | + public void TestLoadGameHandlesNormalFile() |
| 44 | + { |
| 45 | + // Arrange |
| 46 | + var path = TestFileUtils.GetTestFilePath("test_game.sav"); |
| 47 | + var savDirectory = TestFileUtils.GetTestFileDirectory(); |
| 48 | + var rules = new Rules(); |
| 49 | + var activeRuleSet = new Ruleset( |
| 50 | + "mock", |
| 51 | + new Dictionary<string, string>(), |
| 52 | + [savDirectory]); |
| 53 | + var savFile = new MockSavFile(); |
| 54 | + var gameLoader = new GameLoader(path, savDirectory, rules, activeRuleSet, savFile); |
| 55 | + var game = new MockGame(); |
| 56 | + var activeInterface = new MockInterface(); |
| 57 | + |
| 58 | + // Act |
| 59 | + var result = gameLoader.LoadGame(game, activeInterface); |
| 60 | + |
| 61 | + // Assert |
| 62 | + Assert.NotNull(result); |
| 63 | + Assert.IsAssignableFrom<IInterfaceAction>(result); |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +internal class MockSavFile : SavFileBase |
| 68 | +{ |
| 69 | + public override IGame LoadGame(byte[] fileData, Ruleset activeRuleSet, Rules rules) |
| 70 | + { |
| 71 | + return new MockGame(); |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +internal class MockGame : IGame |
| 76 | +{ |
| 77 | + public FastRandom Random => throw new NotImplementedException(); |
| 78 | + public Civilization GetPlayerCiv => throw new NotImplementedException(); |
| 79 | + public IDictionary<int, TerrainImprovement> TerrainImprovements => throw new NotImplementedException(); |
| 80 | + public Rules Rules => throw new NotImplementedException(); |
| 81 | + public Civilization GetActiveCiv => throw new NotImplementedException(); |
| 82 | + public Options Options => throw new NotImplementedException(); |
| 83 | + public Scenario ScenarioData => throw new NotImplementedException(); |
| 84 | + public IPlayer ActivePlayer => throw new NotImplementedException(); |
| 85 | + public IScriptEngine Script => throw new NotImplementedException(); |
| 86 | + public IList<Map> Maps => throw new NotImplementedException(); |
| 87 | + public IHistory History => throw new NotImplementedException(); |
| 88 | + public Dictionary<string, List<string>?> CityNames => throw new NotImplementedException(); |
| 89 | + |
| 90 | + public event EventHandler<PlayerEventArgs> OnPlayerEvent; |
| 91 | + public event EventHandler<UnitEventArgs> OnUnitEvent; |
| 92 | + |
| 93 | + public void ConnectPlayer(IPlayer player) => throw new NotImplementedException(); |
| 94 | + public string Order2String(int unitOrder) => throw new NotImplementedException(); |
| 95 | + public void ChooseNextUnit() => throw new NotImplementedException(); |
| 96 | + public bool ProcessEndOfTurn() => throw new NotImplementedException(); |
| 97 | + public void ChoseNextCiv() => throw new NotImplementedException(); |
| 98 | + public void TriggerMapEvent(MapEventType updateMap, List<Tile> tiles) => throw new NotImplementedException(); |
| 99 | + public double MaxDistance => throw new NotImplementedException(); |
| 100 | + public int DifficultyLevel { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } |
| 101 | + public IGameDate Date => throw new NotImplementedException(); |
| 102 | + public int TurnNumber => throw new NotImplementedException(); |
| 103 | + public List<City> AllCities => throw new NotImplementedException(); |
| 104 | + public IPlayer[] Players => throw new NotImplementedException(); |
| 105 | + public int PollutionSkulls => throw new NotImplementedException(); |
| 106 | + public int GlobalTempRiseOccured => throw new NotImplementedException(); |
| 107 | + public int NoOfTurnsOfPeace => throw new NotImplementedException(); |
| 108 | + public int BarbarianActivity => throw new NotImplementedException(); |
| 109 | + public int NoMaps => throw new NotImplementedException(); |
| 110 | + public List<Civilization> AllCivilizations => throw new NotImplementedException(); |
| 111 | + public void TriggerUnitEvent(UnitEventType eventType, IUnit triggerUnit, BlockedReason reason = BlockedReason.NotBlocked) => throw new NotImplementedException(); |
| 112 | + public void TriggerUnitEvent(UnitEventArgs combatEventArgs) => throw new NotImplementedException(); |
| 113 | + public void SetHumanPlayer(int playerCivId) => throw new NotImplementedException(); |
| 114 | + public void StartPlayerTurn(IPlayer activePlayer) => throw new NotImplementedException(); |
| 115 | + public void StartNextTurn() => throw new NotImplementedException(); |
| 116 | +} |
0 commit comments