Tests are automatically created when populating the available test data

This commit is contained in:
Daniel Cronqvist 2024-08-12 22:07:30 +02:00
parent da5bf73ca0
commit 46d5127c72
3 changed files with 54 additions and 83 deletions

View file

@ -27,4 +27,44 @@ public static partial class TestData
using var stringReader = new StreamReader(stream); using var stringReader = new StreamReader(stream);
return stringReader.ReadToEnd(); return stringReader.ReadToEnd();
} }
public static IEnumerable<object[]> MapsThatHaveTmxAndTmj =>
[
["Serialization.TestData.Map.default_map.default-map", TestData.DefaultMap(), Array.Empty<CustomTypeDefinition>()]
];
private static CustomTypeDefinition[] typedefs = [
new CustomClassDefinition
{
Name = "TestClass",
ID = 1,
UseAs = CustomClassUseAs.Property,
Members = [
new StringProperty
{
Name = "Name",
Value = ""
},
new FloatProperty
{
Name = "Amount",
Value = 0f
}
]
},
new CustomClassDefinition
{
Name = "Test",
ID = 2,
UseAs = CustomClassUseAs.All,
Members = [
new ClassProperty
{
Name = "Yep",
PropertyType = "TestClass",
Properties = []
}
]
}
];
} }

View file

@ -2,51 +2,16 @@ namespace DotTiled.Tests;
public partial class TmjMapReaderTests public partial class TmjMapReaderTests
{ {
public static IEnumerable<object[]> DeserializeMap_ValidTmjExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected_Data => public static IEnumerable<object[]> Maps => TestData.MapsThatHaveTmxAndTmj;
[
["Serialization.TestData.Map.default_map.default-map.tmj", TestData.DefaultMap()]
];
[Theory] [Theory]
[MemberData(nameof(DeserializeMap_ValidTmjExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected_Data))] [MemberData(nameof(Maps))]
public void TmxMapReaderReadMap_ValidTmjExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(string testDataFile, Map expectedMap) public void TmxMapReaderReadMap_ValidTmjExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(
string testDataFile,
Map expectedMap,
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
{ {
// Arrange // Arrange
CustomTypeDefinition[] customTypeDefinitions = [ testDataFile += ".tmj";
new CustomClassDefinition
{
Name = "TestClass",
ID = 1,
UseAs = CustomClassUseAs.Property,
Members = [
new StringProperty
{
Name = "Name",
Value = ""
},
new FloatProperty
{
Name = "Amount",
Value = 0f
}
]
},
new CustomClassDefinition
{
Name = "Test",
ID = 2,
UseAs = CustomClassUseAs.All,
Members = [
new ClassProperty
{
Name = "Yep",
PropertyType = "TestClass",
Properties = []
}
]
}
];
var json = TestData.GetRawStringFor(testDataFile); var json = TestData.GetRawStringFor(testDataFile);
Template ResolveTemplate(string source) Template ResolveTemplate(string source)
{ {

View file

@ -4,50 +4,16 @@ namespace DotTiled.Tests;
public partial class TmxMapReaderTests public partial class TmxMapReaderTests
{ {
public static IEnumerable<object[]> DeserializeMap_ValidXmlExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected_Data => public static IEnumerable<object[]> Maps => TestData.MapsThatHaveTmxAndTmj;
[
["Serialization.TestData.Map.default_map.default-map.tmx", TestData.DefaultMap()]
];
[Theory] [Theory]
[MemberData(nameof(DeserializeMap_ValidXmlExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected_Data))] [MemberData(nameof(Maps))]
public void TmxMapReaderReadMap_ValidXmlExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(string testDataFile, Map expectedMap) public void TmxMapReaderReadMap_ValidXmlExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(
string testDataFile,
Map expectedMap,
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
{ {
// Arrange // Arrange
CustomTypeDefinition[] customTypeDefinitions = [ testDataFile += ".tmx";
new CustomClassDefinition
{
Name = "TestClass",
ID = 1,
UseAs = CustomClassUseAs.Property,
Members = [
new StringProperty
{
Name = "Name",
Value = ""
},
new FloatProperty
{
Name = "Amount",
Value = 0f
}
]
},
new CustomClassDefinition
{
Name = "Test",
ID = 2,
UseAs = CustomClassUseAs.All,
Members = [
new ClassProperty
{
Name = "Yep",
PropertyType = "TestClass",
Properties = []
}
]
}
];
using var reader = TestData.GetXmlReaderFor(testDataFile); using var reader = TestData.GetXmlReaderFor(testDataFile);
Template ResolveTemplate(string source) Template ResolveTemplate(string source)
{ {