Move test data and current tests into UnitTests
|
@ -26,12 +26,12 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<!-- Test data -->
|
<!-- Test data -->
|
||||||
<EmbeddedResource Include="Serialization/TestData/**/*.tmx" />
|
<EmbeddedResource Include="TestData/**/*.tmx" />
|
||||||
<EmbeddedResource Include="Serialization/TestData/**/*.tmj" />
|
<EmbeddedResource Include="TestData/**/*.tmj" />
|
||||||
<EmbeddedResource Include="Serialization/TestData/**/*.tsx" />
|
<EmbeddedResource Include="TestData/**/*.tsx" />
|
||||||
<EmbeddedResource Include="Serialization/TestData/**/*.tsj" />
|
<EmbeddedResource Include="TestData/**/*.tsj" />
|
||||||
<EmbeddedResource Include="Serialization/TestData/**/*.tx" />
|
<EmbeddedResource Include="TestData/**/*.tx" />
|
||||||
<EmbeddedResource Include="Serialization/TestData/**/*.tj" />
|
<EmbeddedResource Include="TestData/**/*.tj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
using System.Xml;
|
|
||||||
|
|
||||||
namespace DotTiled.Tests;
|
|
||||||
|
|
||||||
public static partial class TestData
|
|
||||||
{
|
|
||||||
public static XmlReader GetXmlReaderFor(string testDataFile)
|
|
||||||
{
|
|
||||||
var fullyQualifiedTestDataFile = $"DotTiled.Tests.{ConvertPathToAssemblyResourcePath(testDataFile)}";
|
|
||||||
using var stream = typeof(TestData).Assembly.GetManifestResourceStream(fullyQualifiedTestDataFile)
|
|
||||||
?? throw new ArgumentException($"Test data file '{fullyQualifiedTestDataFile}' not found");
|
|
||||||
|
|
||||||
using var stringReader = new StreamReader(stream);
|
|
||||||
var xml = stringReader.ReadToEnd();
|
|
||||||
var xmlStringReader = new StringReader(xml);
|
|
||||||
return XmlReader.Create(xmlStringReader);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetRawStringFor(string testDataFile)
|
|
||||||
{
|
|
||||||
var fullyQualifiedTestDataFile = $"DotTiled.Tests.{ConvertPathToAssemblyResourcePath(testDataFile)}";
|
|
||||||
using var stream = typeof(TestData).Assembly.GetManifestResourceStream(fullyQualifiedTestDataFile)
|
|
||||||
?? throw new ArgumentException($"Test data file '{fullyQualifiedTestDataFile}' not found");
|
|
||||||
|
|
||||||
using var stringReader = new StreamReader(stream);
|
|
||||||
return stringReader.ReadToEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string ConvertPathToAssemblyResourcePath(string path) =>
|
|
||||||
path.Replace("/", ".").Replace("\\", ".").Replace(" ", "_");
|
|
||||||
|
|
||||||
public static IEnumerable<object[]> MapTests =>
|
|
||||||
[
|
|
||||||
["Serialization/TestData/Map/default_map/default-map", (string f) => DefaultMap(), Array.Empty<ICustomTypeDefinition>()],
|
|
||||||
["Serialization/TestData/Map/map_with_common_props/map-with-common-props", (string f) => MapWithCommonProps(), Array.Empty<ICustomTypeDefinition>()],
|
|
||||||
["Serialization/TestData/Map/map_with_custom_type_props/map-with-custom-type-props", (string f) => MapWithCustomTypeProps(), MapWithCustomTypePropsCustomTypeDefinitions()],
|
|
||||||
["Serialization/TestData/Map/map_with_embedded_tileset/map-with-embedded-tileset", (string f) => MapWithEmbeddedTileset(), Array.Empty<ICustomTypeDefinition>()],
|
|
||||||
["Serialization/TestData/Map/map_with_external_tileset/map-with-external-tileset", (string f) => MapWithExternalTileset(f), Array.Empty<ICustomTypeDefinition>()],
|
|
||||||
["Serialization/TestData/Map/map_with_flippingflags/map-with-flippingflags", (string f) => MapWithFlippingFlags(f), Array.Empty<ICustomTypeDefinition>()],
|
|
||||||
["Serialization/TestData/Map/map_external_tileset_multi/map-external-tileset-multi", (string f) => MapExternalTilesetMulti(f), Array.Empty<ICustomTypeDefinition>()],
|
|
||||||
["Serialization/TestData/Map/map_external_tileset_wangset/map-external-tileset-wangset", (string f) => MapExternalTilesetWangset(f), Array.Empty<ICustomTypeDefinition>()],
|
|
||||||
["Serialization/TestData/Map/map_with_many_layers/map-with-many-layers", (string f) => MapWithManyLayers(f), Array.Empty<ICustomTypeDefinition>()],
|
|
||||||
["Serialization/TestData/Map/map_with_deep_props/map-with-deep-props", (string f) => MapWithDeepProps(), MapWithDeepPropsCustomTypeDefinitions()],
|
|
||||||
["Serialization/TestData/Map/map_with_class/map-with-class", (string f) => MapWithClass(), MapWithClassCustomTypeDefinitions()],
|
|
||||||
["Serialization/TestData/Map/map_with_class_and_props/map-with-class-and-props", (string f) => MapWithClassAndProps(), MapWithClassAndPropsCustomTypeDefinitions()],
|
|
||||||
];
|
|
||||||
}
|
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
@ -1,5 +1,4 @@
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using DotTiled.Serialization;
|
using DotTiled.Serialization;
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
|
|
||||||
|
@ -245,15 +244,4 @@ public class LoaderTests
|
||||||
// Assert
|
// Assert
|
||||||
resourceReader.DidNotReceive().Read("template.tx");
|
resourceReader.DidNotReceive().Read("template.tx");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string WhereAmI([CallerFilePath] string callerFilePath = "") => callerFilePath;
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Test1()
|
|
||||||
{
|
|
||||||
var basePath = Path.GetDirectoryName(WhereAmI())!;
|
|
||||||
var mapPath = Path.Combine(basePath, "TestData/Map/map-with-external-tileset/map-with-external-tileset.tmx");
|
|
||||||
var loader = Loader.Default();
|
|
||||||
loader.LoadMap(mapPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
49
src/DotTiled.Tests/UnitTests/Serialization/TestData.cs
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
|
namespace DotTiled.Tests;
|
||||||
|
|
||||||
|
public static partial class TestData
|
||||||
|
{
|
||||||
|
public static XmlReader GetXmlReaderFor(string testDataFile)
|
||||||
|
{
|
||||||
|
var fullyQualifiedTestDataFile = $"DotTiled.Tests.{ConvertPathToAssemblyResourcePath(testDataFile)}";
|
||||||
|
using var stream = typeof(TestData).Assembly.GetManifestResourceStream(fullyQualifiedTestDataFile)
|
||||||
|
?? throw new ArgumentException($"Test data file '{fullyQualifiedTestDataFile}' not found");
|
||||||
|
|
||||||
|
using var stringReader = new StreamReader(stream);
|
||||||
|
var xml = stringReader.ReadToEnd();
|
||||||
|
var xmlStringReader = new StringReader(xml);
|
||||||
|
return XmlReader.Create(xmlStringReader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetRawStringFor(string testDataFile)
|
||||||
|
{
|
||||||
|
var fullyQualifiedTestDataFile = $"DotTiled.Tests.{ConvertPathToAssemblyResourcePath(testDataFile)}";
|
||||||
|
using var stream = typeof(TestData).Assembly.GetManifestResourceStream(fullyQualifiedTestDataFile)
|
||||||
|
?? throw new ArgumentException($"Test data file '{fullyQualifiedTestDataFile}' not found");
|
||||||
|
|
||||||
|
using var stringReader = new StreamReader(stream);
|
||||||
|
return stringReader.ReadToEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string ConvertPathToAssemblyResourcePath(string path) =>
|
||||||
|
path.Replace("/", ".").Replace("\\", ".").Replace(" ", "_");
|
||||||
|
|
||||||
|
private static string GetMapPath(string mapName) => $"TestData/Maps/{mapName.Replace('-', '_')}/{mapName}";
|
||||||
|
|
||||||
|
public static IEnumerable<object[]> MapTests =>
|
||||||
|
[
|
||||||
|
[GetMapPath("default-map"), (string f) => DefaultMap(), Array.Empty<ICustomTypeDefinition>()],
|
||||||
|
[GetMapPath("map-with-common-props"), (string f) => MapWithCommonProps(), Array.Empty<ICustomTypeDefinition>()],
|
||||||
|
[GetMapPath("map-with-custom-type-props"), (string f) => MapWithCustomTypeProps(), MapWithCustomTypePropsCustomTypeDefinitions()],
|
||||||
|
[GetMapPath("map-with-embedded-tileset"), (string f) => MapWithEmbeddedTileset(), Array.Empty<ICustomTypeDefinition>()],
|
||||||
|
[GetMapPath("map-with-external-tileset"), (string f) => MapWithExternalTileset(f), Array.Empty<ICustomTypeDefinition>()],
|
||||||
|
[GetMapPath("map-with-flippingflags"), (string f) => MapWithFlippingFlags(f), Array.Empty<ICustomTypeDefinition>()],
|
||||||
|
[GetMapPath("map-external-tileset-multi"), (string f) => MapExternalTilesetMulti(f), Array.Empty<ICustomTypeDefinition>()],
|
||||||
|
[GetMapPath("map-external-tileset-wangset"), (string f) => MapExternalTilesetWangset(f), Array.Empty<ICustomTypeDefinition>()],
|
||||||
|
[GetMapPath("map-with-many-layers"), (string f) => MapWithManyLayers(f), Array.Empty<ICustomTypeDefinition>()],
|
||||||
|
[GetMapPath("map-with-deep-props"), (string f) => MapWithDeepProps(), MapWithDeepPropsCustomTypeDefinitions()],
|
||||||
|
[GetMapPath("map-with-class"), (string f) => MapWithClass(), MapWithClassCustomTypeDefinitions()],
|
||||||
|
[GetMapPath("map-with-class-and-props"), (string f) => MapWithClassAndProps(), MapWithClassAndPropsCustomTypeDefinitions()],
|
||||||
|
];
|
||||||
|
}
|