-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from anno-mods/devel/v0.4-fixes
v0.4 fixes
- Loading branch information
Showing
23 changed files
with
1,494 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using AnnoMapEditor.MapTemplates; | ||
using AnnoMapEditor.MapTemplates.Serializing; | ||
using AnnoMapEditor.Mods; | ||
using AnnoMapEditor.Tests.Utils; | ||
using System.Text; | ||
using System.Xml.Linq; | ||
|
||
namespace AnnoMapEditor.Tests | ||
{ | ||
static class CollectionExtensions | ||
{ | ||
public static bool HasNoDuplicates<TSource, TResult>(this IEnumerable<TSource> that, Func<TSource, TResult> selector) | ||
{ | ||
var asList = that.Select(selector); | ||
var asSet = new HashSet<TResult>(asList); | ||
return asList.ToArray().SequenceEqual(asSet.ToArray()); | ||
} | ||
} | ||
|
||
public class PatchedAssetsFixture : IDisposable | ||
{ | ||
public readonly Dictionary<MapType, XDocument> Data; | ||
|
||
public PatchedAssetsFixture() | ||
{ | ||
using Stream assetsXml = File.OpenRead("./TestData/assets.xml"); | ||
Data = new(MapType.GetAllTypes().Select(x => | ||
{ | ||
Stream patch = new MemoryStream(Encoding.Unicode.GetBytes(Mods.Mod.CreateAssetsModOps(MapType.Archipelago, "mods/[Map] test/test.a7t"))); | ||
return new KeyValuePair<MapType, XDocument>(x, XDocument.Load(XmlTest.Patch(assetsXml, patch)!)); | ||
})); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
} | ||
|
||
public class MapTypeData : IEnumerable<object[]> | ||
{ | ||
public IEnumerator<object[]> GetEnumerator() | ||
{ | ||
var types = MapType.GetAllTypes(); | ||
foreach (var type in types) | ||
yield return new object[] { type }; | ||
} | ||
|
||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); | ||
} | ||
|
||
public class Assets : IClassFixture<PatchedAssetsFixture> | ||
{ | ||
PatchedAssetsFixture assetsFixture; | ||
|
||
public Assets(PatchedAssetsFixture fixture) | ||
{ | ||
assetsFixture = fixture; | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(MapTypeData))] | ||
public void NotEmpty(MapType mapType) | ||
{ | ||
var xml = assetsFixture.Data[mapType]; | ||
var assets = xml.Descendants("Asset"); | ||
Assert.NotEmpty(assets); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(MapTypeData))] | ||
public void IsPatched(MapType mapType) | ||
{ | ||
var xml = assetsFixture.Data[mapType]; | ||
var assets = xml.Descendants("Asset"); | ||
Assert.NotEmpty(assets.Where(x => x.GetValueFromPath("Values/MapTemplate/TemplateFilename")?.StartsWith("mods/[Map]") ?? false)); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(MapTypeData))] | ||
public void NoDuplicateName(MapType mapType) | ||
{ | ||
var xml = assetsFixture.Data[mapType]; | ||
var assets = xml.Descendants("Asset"); | ||
Assert.True(assets.HasNoDuplicates(x => x.GetValueFromPath("Values/Standard/Name") ?? "")); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(MapTypeData))] | ||
public void NoDuplicateTemplateFilename(MapType mapType) | ||
{ | ||
var xml = assetsFixture.Data[mapType]; | ||
var assets = xml.Descendants("Asset"); | ||
Assert.True(assets.HasNoDuplicates(x => x.GetValueFromPath("Values/MapTemplate/TemplateFilename") ?? "")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.