Skip to content

Commit

Permalink
Add localization for "- Road Presets" to presets tree (#335)
Browse files Browse the repository at this point in the history
* add support for localization of unknown games
* added some tests
  • Loading branch information
FroggieFrog committed Jun 11, 2021
1 parent 118a9f2 commit 330ceba
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
11 changes: 9 additions & 2 deletions AnnoDesigner/ViewModels/PresetsTreeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,17 @@ public void LoadItems(BuildingPresets buildingPresets)
var groupedGames = filteredBuildingList.GroupBy(x => x.Header).OrderBy(x => x.Key);
foreach (var curGame in groupedGames)
{
var gameHeader = curGame.Key;
var gameVersion = GetGameVersion(curGame.Key);
if (gameVersion == CoreConstants.GameVersion.Unknown)
{
gameHeader = _localizationHelper.GetLocalization(curGame.Key);
}

var gameItem = new GameHeaderTreeItem
{
Header = curGame.Key,
GameVersion = GetGameVersion(curGame.Key),
Header = gameHeader,
GameVersion = gameVersion,
Id = ++itemId
};

Expand Down
66 changes: 66 additions & 0 deletions Tests/AnnoDesigner.Tests/PresetsTreeViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,72 @@ public void LoadItems_BuildingsHaveHeader_ShouldSetCorrectGameVersion(string hea
Assert.Equal(expectedGameVersion, (viewModel.Items[2] as GameHeaderTreeItem).GameVersion);
}

[Fact]
public void LoadItems_BuildingHeaderIsUnknownGameVersion_ShouldGetLocalizationForHeader()
{
// Arrange
var expectedLocalization = "localized dummy";

var mockedLocalizationHelper = new Mock<ILocalizationHelper>();
mockedLocalizationHelper.Setup(x => x.GetLocalization(It.IsAny<string>())).Returns<string>(x => expectedLocalization);
mockedLocalizationHelper.Setup(x => x.GetLocalization(It.IsAny<string>(), It.IsAny<string>())).Returns((string value, string langauge) => expectedLocalization);

var viewModel = new PresetsTreeViewModel(mockedLocalizationHelper.Object, _mockedCommons);

var buildings = new List<BuildingInfo>
{
new BuildingInfo
{
Header = "dummy"
}
};

var buildingPresets = new BuildingPresets();
buildingPresets.Buildings = buildings;

// Act
viewModel.LoadItems(buildingPresets);

// Assert
//first 2 items always the road items
Assert.Equal(expectedLocalization, (viewModel.Items[2] as GameHeaderTreeItem).Header);
}

[Theory]
[InlineData("(A4) Anno 1404")]
[InlineData("(A5) Anno 2070")]
[InlineData("(A6) Anno 2205")]
[InlineData("(A7) Anno 1800")]
public void LoadItems_BuildingHeaderIsKnownGameVersion_ShouldNotGetLocalizationForHeader(string headerToSet)
{
// Arrange
var mockedLocalizationHelper = new Mock<ILocalizationHelper>();
mockedLocalizationHelper.Setup(x => x.GetLocalization(headerToSet)).Returns<string>(x => x);
mockedLocalizationHelper.Setup(x => x.GetLocalization(headerToSet, It.IsAny<string>())).Returns((string value, string langauge) => value);

var viewModel = new PresetsTreeViewModel(mockedLocalizationHelper.Object, _mockedCommons);

var buildings = new List<BuildingInfo>
{
new BuildingInfo
{
Header = headerToSet
}
};

var buildingPresets = new BuildingPresets();
buildingPresets.Buildings = buildings;

// Act
viewModel.LoadItems(buildingPresets);

// Assert
//first 2 items always the road items
Assert.Equal(headerToSet, (viewModel.Items[2] as GameHeaderTreeItem).Header);
mockedLocalizationHelper.Verify(x => x.GetLocalization(headerToSet), Times.Never());
mockedLocalizationHelper.Verify(x => x.GetLocalization(headerToSet, It.IsAny<string>()), Times.Never());
}

[Theory]
[InlineData("Ark")]
[InlineData("Harbour")]
Expand Down

0 comments on commit 330ceba

Please sign in to comment.