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
+ }
0 commit comments