diff --git a/src/DotTiled.Tests/Properties/CustomTypes/CustomClassDefinitionTests.cs b/src/DotTiled.Tests/Properties/CustomTypes/CustomClassDefinitionTests.cs index af944f0..87fecbd 100644 --- a/src/DotTiled.Tests/Properties/CustomTypes/CustomClassDefinitionTests.cs +++ b/src/DotTiled.Tests/Properties/CustomTypes/CustomClassDefinitionTests.cs @@ -2,16 +2,6 @@ namespace DotTiled.Tests; public class CustomClassDefinitionTests { - [Fact] - public void FromClassType_WhenTypeIsNotCustomClass_ThrowsArgumentException() - { - // Arrange - var type = typeof(string); - - // Act & Assert - Assert.Throws(() => CustomClassDefinition.FromClassType(type)); - } - private sealed class TestClass1 { public string Name { get; set; } = "John Doe"; @@ -101,12 +91,42 @@ public class CustomClassDefinitionTests GetCustomClassDefinitionTestData().Select(data => new object[] { data.Item1, data.Item2 }); [Theory] [MemberData(nameof(CustomClassDefinitionTestData))] - public void FromClassType_WhenTypeIsCustomClass_ReturnsCustomClassDefinition(Type type, CustomClassDefinition expected) + public void FromClass_Type_WhenTypeIsCustomClass_ReturnsCustomClassDefinition(Type type, CustomClassDefinition expected) { // Arrange & Act - var result = CustomClassDefinition.FromClassType(type); + var result = CustomClassDefinition.FromClass(type); // Assert AssertCustomClassDefinitionEqual(expected, result); } + + [Fact] + public void FromClass_Type_WhenTypeIsNull_ThrowsArgumentNullException() + { + // Arrange + Type type = null; + + // Act & Assert + Assert.Throws(() => CustomClassDefinition.FromClass(type)); + } + + [Fact] + public void FromClass_Type_WhenTypeIsString_ThrowsArgumentException() + { + // Arrange + Type type = typeof(string); + + // Act & Assert + Assert.Throws(() => CustomClassDefinition.FromClass(type)); + } + + [Fact] + public void FromClass_Type_WhenTypeIsNotClass_ThrowsArgumentException() + { + // Arrange + Type type = typeof(int); + + // Act & Assert + Assert.Throws(() => CustomClassDefinition.FromClass(type)); + } } diff --git a/src/DotTiled/Properties/CustomTypes/CustomClassDefinition.cs b/src/DotTiled/Properties/CustomTypes/CustomClassDefinition.cs index 2c3be71..3e65094 100644 --- a/src/DotTiled/Properties/CustomTypes/CustomClassDefinition.cs +++ b/src/DotTiled/Properties/CustomTypes/CustomClassDefinition.cs @@ -104,25 +104,16 @@ public class CustomClassDefinition : HasPropertiesBase, ICustomTypeDefinition /// The type of the class to create a custom class definition from. /// A new instance. /// Thrown when the specified type is not a class. - public static CustomClassDefinition FromClassType(Type type) + public static CustomClassDefinition FromClass(Type type) { + ArgumentNullException.ThrowIfNull(type, nameof(type)); + if (type == typeof(string) || !type.IsClass) throw new ArgumentException("Type must be a class.", nameof(type)); return FromClass(() => Activator.CreateInstance(type)); } - /// - /// Creates a new from the specified instance of a class. - /// - /// The instance of the class to create a custom class definition from. - /// A new instance. - public static CustomClassDefinition FromClassInstance(dynamic instance) - { - ArgumentNullException.ThrowIfNull(instance); - return FromClass(() => instance); - } - /// /// Creates a new from the specified constructible class type. ///