diff --git a/src/Verify.Tests/PluginConventionTests.cs b/src/Verify.Tests/PluginConventionTests.cs index 543c5a221d..05b65cf40e 100644 --- a/src/Verify.Tests/PluginConventionTests.cs +++ b/src/Verify.Tests/PluginConventionTests.cs @@ -1,4 +1,4 @@ - + #pragma warning disable CS0618 public class PluginConventionTests { @@ -17,6 +17,12 @@ public void TryGetType() Assert.Same(typeof(VerifySamplePlugin), type); } + [Theory] + [InlineData("VerifySamplePlugin", "VerifyTests.VerifySamplePlugin")] + [InlineData("Verify.ICSharpCode.Decompiler", "VerifyTests.VerifyICSharpCodeDecompiler")] + public void GetTypeName(string assemblyName, string expectedTypeName) => + Assert.Equal(expectedTypeName, VerifierSettings.GetTypeName(assemblyName)); + [Fact] public void InvokeInitialize() { diff --git a/src/Verify/VerifierSettings_PluginConvention.cs b/src/Verify/VerifierSettings_PluginConvention.cs index 81f1ffbf9b..dd3218730c 100644 --- a/src/Verify/VerifierSettings_PluginConvention.cs +++ b/src/Verify/VerifierSettings_PluginConvention.cs @@ -1,4 +1,4 @@ -namespace VerifyTests; +namespace VerifyTests; public static partial class VerifierSettings { @@ -38,20 +38,23 @@ static void ProcessFile(string file) internal static bool TryGetType(string file, [NotNullWhen(true)] out Type? type) { - var name = Path.GetFileNameWithoutExtension(file); - if (!name.StartsWith("Verify.")) + var assemblyName = Path.GetFileNameWithoutExtension(file); + if (!assemblyName.StartsWith("Verify.")) { type = null; return false; } #pragma warning disable CS0618 - var assembly = Assembly.LoadWithPartialName(name)!; + var assembly = Assembly.LoadWithPartialName(assemblyName)!; #pragma warning restore CS0618 - var typeName = name.Replace("Verify.", "VerifyTests.Verify"); + var typeName = GetTypeName(assemblyName); type = assembly.GetType(typeName); return type != null; } + internal static string GetTypeName(string assemblyName) => + $"VerifyTests.{assemblyName.Replace(".", "")}"; + internal static void InvokeInitialize(Type type) { var method = type.GetMethods(BindingFlags.Static | BindingFlags.Public)