Skip to content

Commit 0a28992

Browse files
authored
Merge pull request #5 from anno-mods/devel/v0.4-fixes
v0.4 fixes
2 parents a5fe869 + d49afc9 commit 0a28992

23 files changed

+1494
-246
lines changed

AnnoMapEditor.Tests/AnnoMapEditor.Tests.csproj

+11-5
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,25 @@
2828
</ItemGroup>
2929

3030
<ItemGroup>
31-
<None Update="TestMaps\campaign_chapter03_colony01.xml">
31+
<None Update="TestData\assets.xml">
3232
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3333
</None>
34-
<None Update="TestMaps\colony02_01.xml">
34+
<None Update="TestData\campaign_chapter03_colony01.xml">
3535
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3636
</None>
37-
<None Update="TestMaps\moderate_c_01.xml">
37+
<None Update="TestData\colony02_01.xml">
3838
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3939
</None>
40-
<None Update="TestMaps\moderate_islandarc_ss_01.xml">
40+
<None Update="TestData\moderate_c_01.xml">
4141
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4242
</None>
43-
<None Update="TestMaps\scenario_02_colony_01.xml">
43+
<None Update="TestData\moderate_islandarc_ss_01.xml">
44+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
45+
</None>
46+
<None Update="TestData\scenario_02_colony_01.xml">
47+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
48+
</None>
49+
<None Update="Utils\xmltest.exe">
4450
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4551
</None>
4652
</ItemGroup>

AnnoMapEditor.Tests/Assets.cs

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using AnnoMapEditor.MapTemplates;
2+
using AnnoMapEditor.MapTemplates.Serializing;
3+
using AnnoMapEditor.Mods;
4+
using AnnoMapEditor.Tests.Utils;
5+
using System.Text;
6+
using System.Xml.Linq;
7+
8+
namespace AnnoMapEditor.Tests
9+
{
10+
static class CollectionExtensions
11+
{
12+
public static bool HasNoDuplicates<TSource, TResult>(this IEnumerable<TSource> that, Func<TSource, TResult> selector)
13+
{
14+
var asList = that.Select(selector);
15+
var asSet = new HashSet<TResult>(asList);
16+
return asList.ToArray().SequenceEqual(asSet.ToArray());
17+
}
18+
}
19+
20+
public class PatchedAssetsFixture : IDisposable
21+
{
22+
public readonly Dictionary<MapType, XDocument> Data;
23+
24+
public PatchedAssetsFixture()
25+
{
26+
using Stream assetsXml = File.OpenRead("./TestData/assets.xml");
27+
Data = new(MapType.GetAllTypes().Select(x =>
28+
{
29+
Stream patch = new MemoryStream(Encoding.Unicode.GetBytes(Mods.Mod.CreateAssetsModOps(MapType.Archipelago, "mods/[Map] test/test.a7t")));
30+
return new KeyValuePair<MapType, XDocument>(x, XDocument.Load(XmlTest.Patch(assetsXml, patch)!));
31+
}));
32+
}
33+
34+
public void Dispose()
35+
{
36+
}
37+
}
38+
39+
public class MapTypeData : IEnumerable<object[]>
40+
{
41+
public IEnumerator<object[]> GetEnumerator()
42+
{
43+
var types = MapType.GetAllTypes();
44+
foreach (var type in types)
45+
yield return new object[] { type };
46+
}
47+
48+
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();
49+
}
50+
51+
public class Assets : IClassFixture<PatchedAssetsFixture>
52+
{
53+
PatchedAssetsFixture assetsFixture;
54+
55+
public Assets(PatchedAssetsFixture fixture)
56+
{
57+
assetsFixture = fixture;
58+
}
59+
60+
[Theory]
61+
[ClassData(typeof(MapTypeData))]
62+
public void NotEmpty(MapType mapType)
63+
{
64+
var xml = assetsFixture.Data[mapType];
65+
var assets = xml.Descendants("Asset");
66+
Assert.NotEmpty(assets);
67+
}
68+
69+
[Theory]
70+
[ClassData(typeof(MapTypeData))]
71+
public void IsPatched(MapType mapType)
72+
{
73+
var xml = assetsFixture.Data[mapType];
74+
var assets = xml.Descendants("Asset");
75+
Assert.NotEmpty(assets.Where(x => x.GetValueFromPath("Values/MapTemplate/TemplateFilename")?.StartsWith("mods/[Map]") ?? false));
76+
}
77+
78+
[Theory]
79+
[ClassData(typeof(MapTypeData))]
80+
public void NoDuplicateName(MapType mapType)
81+
{
82+
var xml = assetsFixture.Data[mapType];
83+
var assets = xml.Descendants("Asset");
84+
Assert.True(assets.HasNoDuplicates(x => x.GetValueFromPath("Values/Standard/Name") ?? ""));
85+
}
86+
87+
[Theory]
88+
[ClassData(typeof(MapTypeData))]
89+
public void NoDuplicateTemplateFilename(MapType mapType)
90+
{
91+
var xml = assetsFixture.Data[mapType];
92+
var assets = xml.Descendants("Asset");
93+
Assert.True(assets.HasNoDuplicates(x => x.GetValueFromPath("Values/MapTemplate/TemplateFilename") ?? ""));
94+
}
95+
}
96+
}

AnnoMapEditor.Tests/RoundTrip.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ namespace AnnoMapEditor.Tests
77
public class RoundTrip
88
{
99
[Theory]
10-
[InlineData("./TestMaps/moderate_c_01.xml")]
11-
[InlineData("./TestMaps/campaign_chapter03_colony01.xml")]
12-
[InlineData("./TestMaps/moderate_islandarc_ss_01.xml")]
13-
[InlineData("./TestMaps/colony02_01.xml")]
14-
[InlineData("./TestMaps/scenario_02_colony_01.xml")]
10+
[InlineData("./TestData/moderate_c_01.xml")]
11+
[InlineData("./TestData/campaign_chapter03_colony01.xml")]
12+
[InlineData("./TestData/moderate_islandarc_ss_01.xml")]
13+
[InlineData("./TestData/colony02_01.xml")]
14+
[InlineData("./TestData/scenario_02_colony_01.xml")]
1515
public async Task XmlToA7tinfoToXml(string filePath)
1616
{
1717
using Stream inputXml = File.OpenRead(filePath);

0 commit comments

Comments
 (0)