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);
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 static IEnumerable<object[]> DeserializeMap_ValidTmjExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected_Data =>
[
["Serialization.TestData.Map.default_map.default-map.tmj", TestData.DefaultMap()]
];
public static IEnumerable<object[]> Maps => TestData.MapsThatHaveTmxAndTmj;
[Theory]
[MemberData(nameof(DeserializeMap_ValidTmjExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected_Data))]
public void TmxMapReaderReadMap_ValidTmjExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(string testDataFile, Map expectedMap)
[MemberData(nameof(Maps))]
public void TmxMapReaderReadMap_ValidTmjExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(
string testDataFile,
Map expectedMap,
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
{
// Arrange
CustomTypeDefinition[] customTypeDefinitions = [
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 = []
}
]
}
];
testDataFile += ".tmj";
var json = TestData.GetRawStringFor(testDataFile);
Template ResolveTemplate(string source)
{

View file

@ -4,50 +4,16 @@ namespace DotTiled.Tests;
public partial class TmxMapReaderTests
{
public static IEnumerable<object[]> DeserializeMap_ValidXmlExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected_Data =>
[
["Serialization.TestData.Map.default_map.default-map.tmx", TestData.DefaultMap()]
];
public static IEnumerable<object[]> Maps => TestData.MapsThatHaveTmxAndTmj;
[Theory]
[MemberData(nameof(DeserializeMap_ValidXmlExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected_Data))]
public void TmxMapReaderReadMap_ValidXmlExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(string testDataFile, Map expectedMap)
[MemberData(nameof(Maps))]
public void TmxMapReaderReadMap_ValidXmlExternalTilesetsAndTemplates_ReturnsMapThatEqualsExpected(
string testDataFile,
Map expectedMap,
IReadOnlyCollection<CustomTypeDefinition> customTypeDefinitions)
{
// Arrange
CustomTypeDefinition[] customTypeDefinitions = [
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 = []
}
]
}
];
testDataFile += ".tmx";
using var reader = TestData.GetXmlReaderFor(testDataFile);
Template ResolveTemplate(string source)
{