From d16c095475323668726213805bc04fb2ad5e8ad6 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 16 Jul 2024 22:48:54 +1000 Subject: [PATCH 01/20] use named class level parameters --- src/Verify.NUnit/Verifier.cs | 72 ++++++++++++++++++++++++++++++++---- src/Verify/Extensions.cs | 2 +- 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/src/Verify.NUnit/Verifier.cs b/src/Verify.NUnit/Verifier.cs index 9fc681c84c..26f9922ad6 100644 --- a/src/Verify.NUnit/Verifier.cs +++ b/src/Verify.NUnit/Verifier.cs @@ -31,25 +31,50 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b throw new("TestContext.CurrentContext.Test.Method is null. Verify can only be used from within a test method."); } - if (!settings.HasParameters && - adapter.Arguments.Length > 0) + var method = testMethod.MethodInfo; + var parameterNames = method.ParameterNames(); + var type = testMethod.TypeInfo.Type; + + if (!settings.HasParameters) { - settings.SetParameters(adapter.Arguments); + var test = GetTest(adapter); + var parent = test.Parent; + if (parent != null) + { + var argumentsLength = parent.Arguments.Length; + if (argumentsLength > 0) + { + var constructor = GetConstructorByParameterCount(type, argumentsLength); + var names = constructor + .GetParameters() + .Select(_ => _.Name!); + if (parameterNames == null) + { + parameterNames = names.ToList(); + } + else + { + parameterNames.InsertRange(0, names); + } + } + } + + if (adapter.Arguments.Length > 0) + { + settings.SetParameters(adapter.Arguments); + } } var customName = !adapter.FullName.StartsWith($"{testMethod.TypeInfo.FullName}.{testMethod.Name}"); if (customName) { - settings.typeName ??= adapter.GetTypeName(); settings.methodName ??= adapter.GetMethodName(); } - var type = testMethod.TypeInfo.Type; VerifierSettings.AssignTargetAssembly(type.Assembly); - var method = testMethod.MethodInfo; var pathInfo = GetPathInfo(sourceFile, type, method); return new( @@ -57,10 +82,39 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b settings, type.NameWithParent(), method.Name, - method.ParameterNames(), + parameterNames, pathInfo); } + static ConstructorInfo GetConstructorByParameterCount(Type type, int argumentsLength) + { + var constructors = type + .GetConstructors(BindingFlags.Instance | BindingFlags.Public) + .Where(_ => _.GetParameters() + .Length == argumentsLength) + .ToList(); + + if (constructors.Count == 0) + { + throw new($"Could not find constructor with {argumentsLength} parameters."); + } + + if (constructors.Count > 1) + { + throw new($"Found multiple constructor with {argumentsLength} parameters. Unable to derive names of parameters. Instead use UseParameters to pass in explicit parameter."); + } + + return constructors[0]; + } + + static Test GetTest(TestContext.TestAdapter adapter) + { + var field = adapter + .GetType() + .GetField("_test", BindingFlags.Instance | BindingFlags.NonPublic)!; + return (Test) field.GetValue(adapter)!; + } + static string GetMethodName(this TestContext.TestAdapter adapter) { var name = adapter.Name; @@ -86,7 +140,9 @@ static string GetTypeName(this TestContext.TestAdapter adapter) typeName = typeName[(typeInfo.Namespace.Length + 1)..]; } - return typeName.ToString().Replace("\"", "") + return typeName + .ToString() + .Replace("\"", "") .ReplaceInvalidFileNameChars(); } diff --git a/src/Verify/Extensions.cs b/src/Verify/Extensions.cs index 1cbcdd844a..284159ea3b 100644 --- a/src/Verify/Extensions.cs +++ b/src/Verify/Extensions.cs @@ -76,7 +76,7 @@ public static CharSpan AsSpan(this StringBuilder builder) => public static List Clone(this List original) => [..original]; - public static IReadOnlyList? ParameterNames(this MethodInfo method) + public static List? ParameterNames(this MethodInfo method) { var parameters = method.GetParameters(); if (parameters.Length == 0) From 6e062779221169ea3ee43bc1b6afd939799a3dad Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Jul 2024 20:23:26 +1000 Subject: [PATCH 02/20] Update Verifier.cs --- src/Verify.NUnit/Verifier.cs | 140 +++++++++++++++++------------------ 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/src/Verify.NUnit/Verifier.cs b/src/Verify.NUnit/Verifier.cs index 26f9922ad6..b320fd2666 100644 --- a/src/Verify.NUnit/Verifier.cs +++ b/src/Verify.NUnit/Verifier.cs @@ -32,50 +32,22 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b } var method = testMethod.MethodInfo; - var parameterNames = method.ParameterNames(); var type = testMethod.TypeInfo.Type; - if (!settings.HasParameters) + List? parameterNames; + if (settings.HasParameters) { - var test = GetTest(adapter); - var parent = test.Parent; - if (parent != null) - { - var argumentsLength = parent.Arguments.Length; - if (argumentsLength > 0) - { - var constructor = GetConstructorByParameterCount(type, argumentsLength); - var names = constructor - .GetParameters() - .Select(_ => _.Name!); - if (parameterNames == null) - { - parameterNames = names.ToList(); - } - else - { - parameterNames.InsertRange(0, names); - } - } - } - - if (adapter.Arguments.Length > 0) - { - settings.SetParameters(adapter.Arguments); - } + parameterNames = GetParameterNames(adapter); } - - var customName = !adapter.FullName.StartsWith($"{testMethod.TypeInfo.FullName}.{testMethod.Name}"); - if (customName) + else { - settings.typeName ??= adapter.GetTypeName(); - - settings.methodName ??= adapter.GetMethodName(); + var (names, values) = GetParameterInfo(adapter); + settings.SetParameters(values); + parameterNames = names; } VerifierSettings.AssignTargetAssembly(type.Assembly); - var pathInfo = GetPathInfo(sourceFile, type, method); return new( sourceFile, @@ -86,64 +58,92 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b pathInfo); } - static ConstructorInfo GetConstructorByParameterCount(Type type, int argumentsLength) + static (List? names, object?[] values) GetParameterInfo(TestContext.TestAdapter adapter) { - var constructors = type - .GetConstructors(BindingFlags.Instance | BindingFlags.Public) - .Where(_ => _.GetParameters() - .Length == argumentsLength) - .ToList(); + var method = adapter.Method!; + + var methodParameterNames = method.MethodInfo.ParameterNames(); + + var parent = GetParent(adapter); - if (constructors.Count == 0) + if (parent == null) { - throw new($"Could not find constructor with {argumentsLength} parameters."); + return (methodParameterNames, adapter.Arguments); } - if (constructors.Count > 1) + var argumentsLength = parent.Arguments.Length; + if (argumentsLength == 0) { - throw new($"Found multiple constructor with {argumentsLength} parameters. Unable to derive names of parameters. Instead use UseParameters to pass in explicit parameter."); + return (methodParameterNames, adapter.Arguments); } - return constructors[0]; + var names = GetConstructorParameterNames(method.TypeInfo.Type, argumentsLength); + if (methodParameterNames == null) + { + return (names.ToList(), adapter.Arguments); + } + + return ( + [.. names, .. methodParameterNames], + [.. parent.Arguments, .. adapter.Arguments]); } - static Test GetTest(TestContext.TestAdapter adapter) + static List? GetParameterNames(TestContext.TestAdapter adapter) + { + var method = adapter.Method!; + + var methodParameterNames = method.MethodInfo.ParameterNames(); + + var parent = GetParent(adapter); + + if (parent == null) + { + return methodParameterNames; + } + + var names = GetConstructorParameterNames(method.TypeInfo.Type, parent.Arguments.Length); + if (methodParameterNames == null) + { + return names.ToList(); + } + + return [.. names, .. methodParameterNames]; + } + + static ITest? GetParent(TestContext.TestAdapter adapter) { var field = adapter .GetType() .GetField("_test", BindingFlags.Instance | BindingFlags.NonPublic)!; - return (Test) field.GetValue(adapter)!; + var test = (Test) field.GetValue(adapter)!; + return test.Parent; } - static string GetMethodName(this TestContext.TestAdapter adapter) + static IEnumerable GetConstructorParameterNames(Type type, int argumentsLength) { - var name = adapter.Name; - var indexOf = name.IndexOf('('); - - if (indexOf != -1) + IEnumerable? names = null; + foreach (var constructor in type.GetConstructors(BindingFlags.Instance | BindingFlags.Public)) { - name = name[..indexOf]; - } + var parameters = constructor.GetParameters(); + if (parameters.Length != argumentsLength) + { + continue; + } - return name.ReplaceInvalidFileNameChars(); - } + if (names != null) + { + throw new($"Found multiple constructors with {argumentsLength} parameters. Unable to derive names of parameters. Instead use UseParameters to pass in explicit parameter."); + } - static string GetTypeName(this TestContext.TestAdapter adapter) - { - var fullName = adapter.FullName.AsSpan(); - var fullNameLength = fullName.Length - (adapter.Name.Length + 1); - var typeName = fullName[..fullNameLength]; - var typeInfo = adapter.Method!.TypeInfo; - // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract - if (typeInfo.Namespace is not null) + names = parameters.Select(_ => _.Name!); + } + + if (names == null) { - typeName = typeName[(typeInfo.Namespace.Length + 1)..]; + throw new($"Could not find constructor with {argumentsLength} parameters."); } - return typeName - .ToString() - .Replace("\"", "") - .ReplaceInvalidFileNameChars(); + return names; } static SettingsTask Verify( From fbbbb6e7f7ad2bb7ba7d85c4a4000d298b622f72 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Jul 2024 21:06:13 +1000 Subject: [PATCH 03/20] Update GlobalUsings.cs --- src/Verify.NUnit/GlobalUsings.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Verify.NUnit/GlobalUsings.cs b/src/Verify.NUnit/GlobalUsings.cs index b040a01fac..12e97d30bd 100644 --- a/src/Verify.NUnit/GlobalUsings.cs +++ b/src/Verify.NUnit/GlobalUsings.cs @@ -4,4 +4,6 @@ global using NUnit.Framework.Internal; global using NUnit.Framework.Interfaces; global using VerifyTests; -global using Argon; \ No newline at end of file +global using Argon; + +global using TestAdapter = NUnit.Framework.TestContext.TestAdapter; \ No newline at end of file From 17ac809f15e1edc837a0de3d9a46de923e506e7c Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Jul 2024 21:07:47 +1000 Subject: [PATCH 04/20] Update Verifier.cs --- src/Verify.NUnit/Verifier.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Verify.NUnit/Verifier.cs b/src/Verify.NUnit/Verifier.cs index b320fd2666..ac0f729f36 100644 --- a/src/Verify.NUnit/Verifier.cs +++ b/src/Verify.NUnit/Verifier.cs @@ -58,7 +58,7 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b pathInfo); } - static (List? names, object?[] values) GetParameterInfo(TestContext.TestAdapter adapter) + static (List? names, object?[] values) GetParameterInfo(TestAdapter adapter) { var method = adapter.Method!; @@ -88,7 +88,7 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b [.. parent.Arguments, .. adapter.Arguments]); } - static List? GetParameterNames(TestContext.TestAdapter adapter) + static List? GetParameterNames(TestAdapter adapter) { var method = adapter.Method!; @@ -110,7 +110,7 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b return [.. names, .. methodParameterNames]; } - static ITest? GetParent(TestContext.TestAdapter adapter) + static ITest? GetParent(TestAdapter adapter) { var field = adapter .GetType() From f7ee4d17c7411f70b3124688cb473356a234e97d Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Jul 2024 21:38:34 +1000 Subject: [PATCH 05/20] . --- .../ClassLevelParams(1).IgnoreParameters.verified.txt | 1 - .../Snippets/ClassLevelParams(1).Simple.verified.txt | 1 - .../ClassLevelParams(1).WithMethodLeve_arg2=3.verified.txt | 1 - .../ClassLevelParams(1).WithMethodLeve_arg2=4.verified.txt | 1 - .../ClassLevelParams(1).WithMethodLevel_arg2=3.verified.txt | 1 - .../ClassLevelParams(1).WithMethodLevel_arg2=4.verified.txt | 1 - .../ClassLevelParams(2).IgnoreParameters.verified.txt | 1 - .../Snippets/ClassLevelParams(2).Simple.verified.txt | 1 - .../ClassLevelParams(2).WithMethodLeve_arg2=3.verified.txt | 1 - .../ClassLevelParams(2).WithMethodLeve_arg2=4.verified.txt | 1 - .../ClassLevelParams(2).WithMethodLevel_arg2=3.verified.txt | 1 - .../ClassLevelParams(2).WithMethodLevel_arg2=4.verified.txt | 1 - src/Verify.NUnit.Tests/Snippets/ClassLevelParams.cs | 4 ++-- src/Verify.NUnit/Verifier.cs | 3 ++- 14 files changed, 4 insertions(+), 15 deletions(-) delete mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).IgnoreParameters.verified.txt delete mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).Simple.verified.txt delete mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).WithMethodLeve_arg2=3.verified.txt delete mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).WithMethodLeve_arg2=4.verified.txt delete mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).WithMethodLevel_arg2=3.verified.txt delete mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).WithMethodLevel_arg2=4.verified.txt delete mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).IgnoreParameters.verified.txt delete mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).Simple.verified.txt delete mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).WithMethodLeve_arg2=3.verified.txt delete mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).WithMethodLeve_arg2=4.verified.txt delete mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).WithMethodLevel_arg2=3.verified.txt delete mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).WithMethodLevel_arg2=4.verified.txt diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).IgnoreParameters.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).IgnoreParameters.verified.txt deleted file mode 100644 index 3ee291f7bd..0000000000 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).IgnoreParameters.verified.txt +++ /dev/null @@ -1 +0,0 @@ -Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).Simple.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).Simple.verified.txt deleted file mode 100644 index 3ee291f7bd..0000000000 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).Simple.verified.txt +++ /dev/null @@ -1 +0,0 @@ -Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).WithMethodLeve_arg2=3.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).WithMethodLeve_arg2=3.verified.txt deleted file mode 100644 index 3ee291f7bd..0000000000 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).WithMethodLeve_arg2=3.verified.txt +++ /dev/null @@ -1 +0,0 @@ -Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).WithMethodLeve_arg2=4.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).WithMethodLeve_arg2=4.verified.txt deleted file mode 100644 index 3ee291f7bd..0000000000 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).WithMethodLeve_arg2=4.verified.txt +++ /dev/null @@ -1 +0,0 @@ -Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).WithMethodLevel_arg2=3.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).WithMethodLevel_arg2=3.verified.txt deleted file mode 100644 index 3ee291f7bd..0000000000 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).WithMethodLevel_arg2=3.verified.txt +++ /dev/null @@ -1 +0,0 @@ -Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).WithMethodLevel_arg2=4.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).WithMethodLevel_arg2=4.verified.txt deleted file mode 100644 index 3ee291f7bd..0000000000 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(1).WithMethodLevel_arg2=4.verified.txt +++ /dev/null @@ -1 +0,0 @@ -Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).IgnoreParameters.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).IgnoreParameters.verified.txt deleted file mode 100644 index 3ee291f7bd..0000000000 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).IgnoreParameters.verified.txt +++ /dev/null @@ -1 +0,0 @@ -Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).Simple.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).Simple.verified.txt deleted file mode 100644 index 3ee291f7bd..0000000000 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).Simple.verified.txt +++ /dev/null @@ -1 +0,0 @@ -Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).WithMethodLeve_arg2=3.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).WithMethodLeve_arg2=3.verified.txt deleted file mode 100644 index 3ee291f7bd..0000000000 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).WithMethodLeve_arg2=3.verified.txt +++ /dev/null @@ -1 +0,0 @@ -Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).WithMethodLeve_arg2=4.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).WithMethodLeve_arg2=4.verified.txt deleted file mode 100644 index 3ee291f7bd..0000000000 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).WithMethodLeve_arg2=4.verified.txt +++ /dev/null @@ -1 +0,0 @@ -Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).WithMethodLevel_arg2=3.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).WithMethodLevel_arg2=3.verified.txt deleted file mode 100644 index 3ee291f7bd..0000000000 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).WithMethodLevel_arg2=3.verified.txt +++ /dev/null @@ -1 +0,0 @@ -Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).WithMethodLevel_arg2=4.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).WithMethodLevel_arg2=4.verified.txt deleted file mode 100644 index 3ee291f7bd..0000000000 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams(2).WithMethodLevel_arg2=4.verified.txt +++ /dev/null @@ -1 +0,0 @@ -Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.cs b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.cs index 7f79350db5..6afdeccff2 100644 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.cs +++ b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.cs @@ -1,13 +1,13 @@ #pragma warning disable CS9113 // Parameter is unread. [TestFixture("1")] -[TestFixture("2")] +//[TestFixture("2")] public class ClassLevelParams(string arg1) { [Test] public Task Simple() => Verify("Value"); [TestCase("3")] - [TestCase("4")] + //[TestCase("4")] public Task WithMethodLevel(string arg2) => Verify("Value"); [TestCase("3")] diff --git a/src/Verify.NUnit/Verifier.cs b/src/Verify.NUnit/Verifier.cs index ac0f729f36..2d7f256adf 100644 --- a/src/Verify.NUnit/Verifier.cs +++ b/src/Verify.NUnit/Verifier.cs @@ -80,7 +80,7 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b var names = GetConstructorParameterNames(method.TypeInfo.Type, argumentsLength); if (methodParameterNames == null) { - return (names.ToList(), adapter.Arguments); + return (names.ToList(), parent.Arguments); } return ( @@ -117,6 +117,7 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b .GetField("_test", BindingFlags.Instance | BindingFlags.NonPublic)!; var test = (Test) field.GetValue(adapter)!; return test.Parent; + //ParameterizedMethodSuite } static IEnumerable GetConstructorParameterNames(Type type, int argumentsLength) From 9ec21fa0a75e8b71f3fb2cfab884768061aac762 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Jul 2024 22:03:13 +1000 Subject: [PATCH 06/20] . --- .../Snippets/ClassLevelParams.cs | 2 +- src/Verify.NUnit/Verifier.cs | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.cs b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.cs index 6afdeccff2..b1f6b0cfd9 100644 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.cs +++ b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.cs @@ -7,7 +7,7 @@ public class ClassLevelParams(string arg1) public Task Simple() => Verify("Value"); [TestCase("3")] - //[TestCase("4")] + [TestCase("4")] public Task WithMethodLevel(string arg2) => Verify("Value"); [TestCase("3")] diff --git a/src/Verify.NUnit/Verifier.cs b/src/Verify.NUnit/Verifier.cs index 2d7f256adf..53719b9ca0 100644 --- a/src/Verify.NUnit/Verifier.cs +++ b/src/Verify.NUnit/Verifier.cs @@ -111,13 +111,24 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b } static ITest? GetParent(TestAdapter adapter) + { + var test = GetTest(adapter); + var parent = test.Parent; + if (parent is ParameterizedMethodSuite methodSuite) + { + return methodSuite.Parent; + } + + return parent; + //ParameterizedMethodSuite + } + + static Test GetTest(TestAdapter adapter) { var field = adapter .GetType() .GetField("_test", BindingFlags.Instance | BindingFlags.NonPublic)!; - var test = (Test) field.GetValue(adapter)!; - return test.Parent; - //ParameterizedMethodSuite + return (Test) field.GetValue(adapter)!; } static IEnumerable GetConstructorParameterNames(Type type, int argumentsLength) From 2d2b8336d529de1ed3776177caf2b0f8fdc6e512 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Jul 2024 22:06:58 +1000 Subject: [PATCH 07/20] Update Verifier.cs --- src/Verify.NUnit/Verifier.cs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Verify.NUnit/Verifier.cs b/src/Verify.NUnit/Verifier.cs index 53719b9ca0..6d41d9d475 100644 --- a/src/Verify.NUnit/Verifier.cs +++ b/src/Verify.NUnit/Verifier.cs @@ -46,6 +46,14 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b parameterNames = names; } + var customName = !adapter.FullName.StartsWith($"{testMethod.TypeInfo.FullName}.{testMethod.Name}"); + if (customName) + { + settings.typeName ??= adapter.GetTypeName(); + + settings.methodName ??= adapter.GetMethodName(); + } + VerifierSettings.AssignTargetAssembly(type.Assembly); var pathInfo = GetPathInfo(sourceFile, type, method); @@ -158,6 +166,34 @@ static IEnumerable GetConstructorParameterNames(Type type, int arguments return names; } + static string GetMethodName(this TestAdapter adapter) + { + var name = adapter.Name; + var indexOf = name.IndexOf('('); + + if (indexOf != -1) + { + name = name[..indexOf]; + } + + return name.ReplaceInvalidFileNameChars(); + } + + static string GetTypeName(this TestAdapter adapter) + { + var fullName = adapter.FullName.AsSpan(); + var fullNameLength = fullName.Length - (adapter.Name.Length + 1); + var typeName = fullName[..fullNameLength]; + var typeInfo = adapter.Method!.TypeInfo; + // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract + if (typeInfo.Namespace is not null) + { + typeName = typeName[(typeInfo.Namespace.Length + 1)..]; + } + + return typeName.ToString().Replace("\"", "") + .ReplaceInvalidFileNameChars(); + } static SettingsTask Verify( VerifySettings? settings, string sourceFile, From d246b361e91328d2c861d333f2f0ada6d4c1d216 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Jul 2024 22:23:12 +1000 Subject: [PATCH 08/20] . --- ...eWithNamespace(Value1,1).Test.verified.txt | 0 ...lassLevelParams.Simple_arg1=1.verified.txt | 1 + ...rsSample.Double(1.1d)_arg=1.1.verified.txt | 1 + ...ersSample.Float(1.1f)_arg=1.1.verified.txt | 1 + ...e2,2).Test_arg3=FromTestCase2.verified.txt | 5 --- ...sage.Test_arg1=Value1_arg2=1.verified.txt} | 0 ...Usage.Test_arg1=Value2_arg2=2.verified.txt | 1 + ...eWithNamespace(Value2,2).Test.verified.txt | 4 -- ...pace.Test_arg1=Value1_arg2=1.verified.txt} | 0 ...pace.Test_arg1=Value2_arg2=2.verified.txt} | 0 src/Verify.NUnit/Verifier.cs | 41 +++---------------- 11 files changed, 9 insertions(+), 45 deletions(-) delete mode 100644 src/Verify.NUnit.Tests/MyNamespace.TestFixtureSourceUsageWithNamespace(Value1,1).Test.verified.txt create mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams.Simple_arg1=1.verified.txt create mode 100644 src/Verify.NUnit.Tests/Snippets/ParametersSample.Double(1.1d)_arg=1.1.verified.txt create mode 100644 src/Verify.NUnit.Tests/Snippets/ParametersSample.Float(1.1f)_arg=1.1.verified.txt delete mode 100644 src/Verify.NUnit.Tests/TestFixtureSourceAndTestCaseUsage(Value2,2).Test_arg3=FromTestCase2.verified.txt rename src/Verify.NUnit.Tests/{TestFixtureSourceUsage(Value1,1).Test.verified.txt => TestFixtureSourceUsage.Test_arg1=Value1_arg2=1.verified.txt} (100%) create mode 100644 src/Verify.NUnit.Tests/TestFixtureSourceUsage.Test_arg1=Value2_arg2=2.verified.txt delete mode 100644 src/Verify.NUnit.Tests/TestFixtureSourceUsageWithNamespace(Value2,2).Test.verified.txt rename src/Verify.NUnit.Tests/{TestFixtureSourceUsageWithNamespace(Value1,1).Test.verified.txt => TestFixtureSourceUsageWithNamespace.Test_arg1=Value1_arg2=1.verified.txt} (100%) rename src/Verify.NUnit.Tests/{TestFixtureSourceUsage(Value2,2).Test.verified.txt => TestFixtureSourceUsageWithNamespace.Test_arg1=Value2_arg2=2.verified.txt} (100%) diff --git a/src/Verify.NUnit.Tests/MyNamespace.TestFixtureSourceUsageWithNamespace(Value1,1).Test.verified.txt b/src/Verify.NUnit.Tests/MyNamespace.TestFixtureSourceUsageWithNamespace(Value1,1).Test.verified.txt deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.Simple_arg1=1.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.Simple_arg1=1.verified.txt new file mode 100644 index 0000000000..3ee291f7bd --- /dev/null +++ b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.Simple_arg1=1.verified.txt @@ -0,0 +1 @@ +Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ParametersSample.Double(1.1d)_arg=1.1.verified.txt b/src/Verify.NUnit.Tests/Snippets/ParametersSample.Double(1.1d)_arg=1.1.verified.txt new file mode 100644 index 0000000000..8ab02375ee --- /dev/null +++ b/src/Verify.NUnit.Tests/Snippets/ParametersSample.Double(1.1d)_arg=1.1.verified.txt @@ -0,0 +1 @@ +1.1 \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ParametersSample.Float(1.1f)_arg=1.1.verified.txt b/src/Verify.NUnit.Tests/Snippets/ParametersSample.Float(1.1f)_arg=1.1.verified.txt new file mode 100644 index 0000000000..8ab02375ee --- /dev/null +++ b/src/Verify.NUnit.Tests/Snippets/ParametersSample.Float(1.1f)_arg=1.1.verified.txt @@ -0,0 +1 @@ +1.1 \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/TestFixtureSourceAndTestCaseUsage(Value2,2).Test_arg3=FromTestCase2.verified.txt b/src/Verify.NUnit.Tests/TestFixtureSourceAndTestCaseUsage(Value2,2).Test_arg3=FromTestCase2.verified.txt deleted file mode 100644 index f515c9e064..0000000000 --- a/src/Verify.NUnit.Tests/TestFixtureSourceAndTestCaseUsage(Value2,2).Test_arg3=FromTestCase2.verified.txt +++ /dev/null @@ -1,5 +0,0 @@ -{ - arg1: Value2, - arg2: 2, - arg3: FromTestCase2 -} \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/TestFixtureSourceUsage(Value1,1).Test.verified.txt b/src/Verify.NUnit.Tests/TestFixtureSourceUsage.Test_arg1=Value1_arg2=1.verified.txt similarity index 100% rename from src/Verify.NUnit.Tests/TestFixtureSourceUsage(Value1,1).Test.verified.txt rename to src/Verify.NUnit.Tests/TestFixtureSourceUsage.Test_arg1=Value1_arg2=1.verified.txt diff --git a/src/Verify.NUnit.Tests/TestFixtureSourceUsage.Test_arg1=Value2_arg2=2.verified.txt b/src/Verify.NUnit.Tests/TestFixtureSourceUsage.Test_arg1=Value2_arg2=2.verified.txt new file mode 100644 index 0000000000..5f282702bb --- /dev/null +++ b/src/Verify.NUnit.Tests/TestFixtureSourceUsage.Test_arg1=Value2_arg2=2.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/TestFixtureSourceUsageWithNamespace(Value2,2).Test.verified.txt b/src/Verify.NUnit.Tests/TestFixtureSourceUsageWithNamespace(Value2,2).Test.verified.txt deleted file mode 100644 index d900f55e08..0000000000 --- a/src/Verify.NUnit.Tests/TestFixtureSourceUsageWithNamespace(Value2,2).Test.verified.txt +++ /dev/null @@ -1,4 +0,0 @@ -{ - arg1: Value2, - arg2: 2 -} \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/TestFixtureSourceUsageWithNamespace(Value1,1).Test.verified.txt b/src/Verify.NUnit.Tests/TestFixtureSourceUsageWithNamespace.Test_arg1=Value1_arg2=1.verified.txt similarity index 100% rename from src/Verify.NUnit.Tests/TestFixtureSourceUsageWithNamespace(Value1,1).Test.verified.txt rename to src/Verify.NUnit.Tests/TestFixtureSourceUsageWithNamespace.Test_arg1=Value1_arg2=1.verified.txt diff --git a/src/Verify.NUnit.Tests/TestFixtureSourceUsage(Value2,2).Test.verified.txt b/src/Verify.NUnit.Tests/TestFixtureSourceUsageWithNamespace.Test_arg1=Value2_arg2=2.verified.txt similarity index 100% rename from src/Verify.NUnit.Tests/TestFixtureSourceUsage(Value2,2).Test.verified.txt rename to src/Verify.NUnit.Tests/TestFixtureSourceUsageWithNamespace.Test_arg1=Value2_arg2=2.verified.txt diff --git a/src/Verify.NUnit/Verifier.cs b/src/Verify.NUnit/Verifier.cs index 6d41d9d475..ba3b872aa7 100644 --- a/src/Verify.NUnit/Verifier.cs +++ b/src/Verify.NUnit/Verifier.cs @@ -46,22 +46,19 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b parameterNames = names; } - var customName = !adapter.FullName.StartsWith($"{testMethod.TypeInfo.FullName}.{testMethod.Name}"); - if (customName) - { - settings.typeName ??= adapter.GetTypeName(); + VerifierSettings.AssignTargetAssembly(type.Assembly); - settings.methodName ??= adapter.GetMethodName(); + if (adapter.Name != method.Name) + { + settings.methodName ??= adapter.Name; } - VerifierSettings.AssignTargetAssembly(type.Assembly); - var pathInfo = GetPathInfo(sourceFile, type, method); return new( sourceFile, settings, type.NameWithParent(), - method.Name, + adapter.Name, parameterNames, pathInfo); } @@ -166,34 +163,6 @@ static IEnumerable GetConstructorParameterNames(Type type, int arguments return names; } - static string GetMethodName(this TestAdapter adapter) - { - var name = adapter.Name; - var indexOf = name.IndexOf('('); - - if (indexOf != -1) - { - name = name[..indexOf]; - } - - return name.ReplaceInvalidFileNameChars(); - } - - static string GetTypeName(this TestAdapter adapter) - { - var fullName = adapter.FullName.AsSpan(); - var fullNameLength = fullName.Length - (adapter.Name.Length + 1); - var typeName = fullName[..fullNameLength]; - var typeInfo = adapter.Method!.TypeInfo; - // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract - if (typeInfo.Namespace is not null) - { - typeName = typeName[(typeInfo.Namespace.Length + 1)..]; - } - - return typeName.ToString().Replace("\"", "") - .ReplaceInvalidFileNameChars(); - } static SettingsTask Verify( VerifySettings? settings, string sourceFile, From b933683787af58bebf77eaee6a608d812d80d78c Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Jul 2024 22:24:31 +1000 Subject: [PATCH 09/20] Update TestFixtureSourceUsage.Test_arg1=Value2_arg2=2.verified.txt --- ...stFixtureSourceUsage.Test_arg1=Value2_arg2=2.verified.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Verify.NUnit.Tests/TestFixtureSourceUsage.Test_arg1=Value2_arg2=2.verified.txt b/src/Verify.NUnit.Tests/TestFixtureSourceUsage.Test_arg1=Value2_arg2=2.verified.txt index 5f282702bb..d900f55e08 100644 --- a/src/Verify.NUnit.Tests/TestFixtureSourceUsage.Test_arg1=Value2_arg2=2.verified.txt +++ b/src/Verify.NUnit.Tests/TestFixtureSourceUsage.Test_arg1=Value2_arg2=2.verified.txt @@ -1 +1,4 @@ - \ No newline at end of file +{ + arg1: Value2, + arg2: 2 +} \ No newline at end of file From ede8f1c33812d22cc965bc08cbf80b78f9ce4128 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Jul 2024 22:25:14 +1000 Subject: [PATCH 10/20] Update ClassLevelParams.cs --- src/Verify.NUnit.Tests/Snippets/ClassLevelParams.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.cs b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.cs index b1f6b0cfd9..7f79350db5 100644 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.cs +++ b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.cs @@ -1,6 +1,6 @@ #pragma warning disable CS9113 // Parameter is unread. [TestFixture("1")] -//[TestFixture("2")] +[TestFixture("2")] public class ClassLevelParams(string arg1) { [Test] From 51a036a626b796d2bf1b7d9194eeef2030aba169 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Jul 2024 22:45:09 +1000 Subject: [PATCH 11/20] Create ClassLevelParams.Simple_arg1=2.verified.txt --- .../Snippets/ClassLevelParams.Simple_arg1=2.verified.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams.Simple_arg1=2.verified.txt diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.Simple_arg1=2.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.Simple_arg1=2.verified.txt new file mode 100644 index 0000000000..3ee291f7bd --- /dev/null +++ b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.Simple_arg1=2.verified.txt @@ -0,0 +1 @@ +Value \ No newline at end of file From d72d311a46f9cac0bc383bdac64eda2193d47231 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Jul 2024 22:48:54 +1000 Subject: [PATCH 12/20] Update Extensions.cs --- src/Verify/Extensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Verify/Extensions.cs b/src/Verify/Extensions.cs index 284159ea3b..1cbcdd844a 100644 --- a/src/Verify/Extensions.cs +++ b/src/Verify/Extensions.cs @@ -76,7 +76,7 @@ public static CharSpan AsSpan(this StringBuilder builder) => public static List Clone(this List original) => [..original]; - public static List? ParameterNames(this MethodInfo method) + public static IReadOnlyList? ParameterNames(this MethodInfo method) { var parameters = method.GetParameters(); if (parameters.Length == 0) From a7563b47fd8e8c4660d559f79fb7a2490a2f1e83 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Jul 2024 22:50:29 +1000 Subject: [PATCH 13/20] Update Verifier.cs --- src/Verify.NUnit/Verifier.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Verify.NUnit/Verifier.cs b/src/Verify.NUnit/Verifier.cs index ba3b872aa7..39ad026f55 100644 --- a/src/Verify.NUnit/Verifier.cs +++ b/src/Verify.NUnit/Verifier.cs @@ -34,7 +34,7 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b var method = testMethod.MethodInfo; var type = testMethod.TypeInfo.Type; - List? parameterNames; + IReadOnlyList? parameterNames; if (settings.HasParameters) { parameterNames = GetParameterNames(adapter); @@ -63,7 +63,7 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b pathInfo); } - static (List? names, object?[] values) GetParameterInfo(TestAdapter adapter) + static (IReadOnlyList? names, object?[] values) GetParameterInfo(TestAdapter adapter) { var method = adapter.Method!; @@ -93,7 +93,7 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b [.. parent.Arguments, .. adapter.Arguments]); } - static List? GetParameterNames(TestAdapter adapter) + static IReadOnlyList? GetParameterNames(TestAdapter adapter) { var method = adapter.Method!; From 0fb8cffc2d0536bf6ef97fea9fe6a7c007df4cf0 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Jul 2024 23:16:20 +1000 Subject: [PATCH 14/20] . --- docs/mdsource/parameterised.source.md | 5 ++++- docs/parameterised.md | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/mdsource/parameterised.source.md b/docs/mdsource/parameterised.source.md index d639dfa4f4..e1c284cd2b 100644 --- a/docs/mdsource/parameterised.source.md +++ b/docs/mdsource/parameterised.source.md @@ -47,7 +47,10 @@ When using a [TestFixtureSource](https://docs.nunit.org/articles/nunit/writing-t snippet: TestFixtureSourceUsage.cs -Produces `TestFixtureSourceUsage(Value1,1).Test.verified.txt` and `TestFixtureSourceUsage(Value2,2).Test.verified.txt`. +Produces: + + * `TestFixtureSourceUsage.Test_arg1=Value1_arg2=1.verified.txt` + * `TestFixtureSourceUsage.Test_arg1=Value2_arg2=2.verified.txt` ## xUnit diff --git a/docs/parameterised.md b/docs/parameterised.md index 3f6a78c772..d5367558ce 100644 --- a/docs/parameterised.md +++ b/docs/parameterised.md @@ -121,7 +121,10 @@ public class TestFixtureSourceUsage(string arg1, int arg2) snippet source | anchor -Produces `TestFixtureSourceUsage(Value1,1).Test.verified.txt` and `TestFixtureSourceUsage(Value2,2).Test.verified.txt`. +Produces: + + * `TestFixtureSourceUsage.Test_arg1=Value1_arg2=1.verified.txt` + * `TestFixtureSourceUsage.Test_arg1=Value2_arg2=2.verified.txt` ## xUnit From b56ee1532b024b7ee72c39954cfe40b83b7c4258 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Jul 2024 23:30:33 +1000 Subject: [PATCH 15/20] Update Verifier.cs --- src/Verify.NUnit/Verifier.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Verify.NUnit/Verifier.cs b/src/Verify.NUnit/Verifier.cs index 39ad026f55..dbb9cffe4f 100644 --- a/src/Verify.NUnit/Verifier.cs +++ b/src/Verify.NUnit/Verifier.cs @@ -125,7 +125,6 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b } return parent; - //ParameterizedMethodSuite } static Test GetTest(TestAdapter adapter) From 1d9a11a76daeb50eee4a28a07f1512d3740b1cdf Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Jul 2024 23:54:33 +1000 Subject: [PATCH 16/20] . --- .../ClassLevelParams.IgnoreParameters.verified.txt | 1 + ...sLevelParams.WithMethodLevel_arg1=1_arg2=3.verified.txt | 1 + ...sLevelParams.WithMethodLevel_arg1=1_arg2=4.verified.txt | 1 + ...sLevelParams.WithMethodLevel_arg1=2_arg2=3.verified.txt | 1 + ...sLevelParams.WithMethodLevel_arg1=2_arg2=4.verified.txt | 1 + ...Test_arg1=Value2_arg2=2_arg3=FromTestCase2.verified.txt | 5 +++++ ...seWithNameAndInvalidChars_TextForParameter.verified.txt | 1 + .../Tests.TestCaseWithName_TextForParameter.verified.txt | 1 + src/Verify.NUnit/Verifier.cs | 7 +------ 9 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams.IgnoreParameters.verified.txt create mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=1_arg2=3.verified.txt create mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=1_arg2=4.verified.txt create mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=2_arg2=3.verified.txt create mode 100644 src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=2_arg2=4.verified.txt create mode 100644 src/Verify.NUnit.Tests/TestFixtureSourceAndTestCaseUsage.Test_arg1=Value2_arg2=2_arg3=FromTestCase2.verified.txt create mode 100644 src/Verify.NUnit.Tests/Tests.TestCaseWithNameAndInvalidChars_TextForParameter.verified.txt create mode 100644 src/Verify.NUnit.Tests/Tests.TestCaseWithName_TextForParameter.verified.txt diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.IgnoreParameters.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.IgnoreParameters.verified.txt new file mode 100644 index 0000000000..3ee291f7bd --- /dev/null +++ b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.IgnoreParameters.verified.txt @@ -0,0 +1 @@ +Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=1_arg2=3.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=1_arg2=3.verified.txt new file mode 100644 index 0000000000..3ee291f7bd --- /dev/null +++ b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=1_arg2=3.verified.txt @@ -0,0 +1 @@ +Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=1_arg2=4.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=1_arg2=4.verified.txt new file mode 100644 index 0000000000..3ee291f7bd --- /dev/null +++ b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=1_arg2=4.verified.txt @@ -0,0 +1 @@ +Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=2_arg2=3.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=2_arg2=3.verified.txt new file mode 100644 index 0000000000..3ee291f7bd --- /dev/null +++ b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=2_arg2=3.verified.txt @@ -0,0 +1 @@ +Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=2_arg2=4.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=2_arg2=4.verified.txt new file mode 100644 index 0000000000..3ee291f7bd --- /dev/null +++ b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=2_arg2=4.verified.txt @@ -0,0 +1 @@ +Value \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/TestFixtureSourceAndTestCaseUsage.Test_arg1=Value2_arg2=2_arg3=FromTestCase2.verified.txt b/src/Verify.NUnit.Tests/TestFixtureSourceAndTestCaseUsage.Test_arg1=Value2_arg2=2_arg3=FromTestCase2.verified.txt new file mode 100644 index 0000000000..f515c9e064 --- /dev/null +++ b/src/Verify.NUnit.Tests/TestFixtureSourceAndTestCaseUsage.Test_arg1=Value2_arg2=2_arg3=FromTestCase2.verified.txt @@ -0,0 +1,5 @@ +{ + arg1: Value2, + arg2: 2, + arg3: FromTestCase2 +} \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Tests.TestCaseWithNameAndInvalidChars_TextForParameter.verified.txt b/src/Verify.NUnit.Tests/Tests.TestCaseWithNameAndInvalidChars_TextForParameter.verified.txt new file mode 100644 index 0000000000..5f282702bb --- /dev/null +++ b/src/Verify.NUnit.Tests/Tests.TestCaseWithNameAndInvalidChars_TextForParameter.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Tests.TestCaseWithName_TextForParameter.verified.txt b/src/Verify.NUnit.Tests/Tests.TestCaseWithName_TextForParameter.verified.txt new file mode 100644 index 0000000000..5f282702bb --- /dev/null +++ b/src/Verify.NUnit.Tests/Tests.TestCaseWithName_TextForParameter.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Verify.NUnit/Verifier.cs b/src/Verify.NUnit/Verifier.cs index dbb9cffe4f..1dca4e29e0 100644 --- a/src/Verify.NUnit/Verifier.cs +++ b/src/Verify.NUnit/Verifier.cs @@ -48,17 +48,12 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b VerifierSettings.AssignTargetAssembly(type.Assembly); - if (adapter.Name != method.Name) - { - settings.methodName ??= adapter.Name; - } - var pathInfo = GetPathInfo(sourceFile, type, method); return new( sourceFile, settings, type.NameWithParent(), - adapter.Name, + method.Name, parameterNames, pathInfo); } From a3f5a4408a28247bc145257b0d0ab8df09965ddf Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 17 Jul 2024 23:59:26 +1000 Subject: [PATCH 17/20] . --- .../Tests.Custom-Name_TextForParameter.verified.txt | 1 - .../Tests.CustomName_TextForParameter.verified.txt | 1 - ...estCaseWithNameAndInvalidChars_TextForParameter.verified.txt | 2 +- .../Tests.TestCaseWithName_TextForParameter.verified.txt | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) delete mode 100644 src/Verify.NUnit.Tests/Tests.Custom-Name_TextForParameter.verified.txt delete mode 100644 src/Verify.NUnit.Tests/Tests.CustomName_TextForParameter.verified.txt diff --git a/src/Verify.NUnit.Tests/Tests.Custom-Name_TextForParameter.verified.txt b/src/Verify.NUnit.Tests/Tests.Custom-Name_TextForParameter.verified.txt deleted file mode 100644 index 39d0344b5c..0000000000 --- a/src/Verify.NUnit.Tests/Tests.Custom-Name_TextForParameter.verified.txt +++ /dev/null @@ -1 +0,0 @@ -Value1 \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Tests.CustomName_TextForParameter.verified.txt b/src/Verify.NUnit.Tests/Tests.CustomName_TextForParameter.verified.txt deleted file mode 100644 index 39d0344b5c..0000000000 --- a/src/Verify.NUnit.Tests/Tests.CustomName_TextForParameter.verified.txt +++ /dev/null @@ -1 +0,0 @@ -Value1 \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Tests.TestCaseWithNameAndInvalidChars_TextForParameter.verified.txt b/src/Verify.NUnit.Tests/Tests.TestCaseWithNameAndInvalidChars_TextForParameter.verified.txt index 5f282702bb..39d0344b5c 100644 --- a/src/Verify.NUnit.Tests/Tests.TestCaseWithNameAndInvalidChars_TextForParameter.verified.txt +++ b/src/Verify.NUnit.Tests/Tests.TestCaseWithNameAndInvalidChars_TextForParameter.verified.txt @@ -1 +1 @@ - \ No newline at end of file +Value1 \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Tests.TestCaseWithName_TextForParameter.verified.txt b/src/Verify.NUnit.Tests/Tests.TestCaseWithName_TextForParameter.verified.txt index 5f282702bb..39d0344b5c 100644 --- a/src/Verify.NUnit.Tests/Tests.TestCaseWithName_TextForParameter.verified.txt +++ b/src/Verify.NUnit.Tests/Tests.TestCaseWithName_TextForParameter.verified.txt @@ -1 +1 @@ - \ No newline at end of file +Value1 \ No newline at end of file From f17e6c86f2b9f7374b888b4ef2f854fa01adb4e9 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 19 Jul 2024 10:49:41 +1000 Subject: [PATCH 18/20] Update FileNameCleaner.cs --- src/Verify/FileNameCleaner.cs | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/src/Verify/FileNameCleaner.cs b/src/Verify/FileNameCleaner.cs index 69a3173ae3..67b304635b 100644 --- a/src/Verify/FileNameCleaner.cs +++ b/src/Verify/FileNameCleaner.cs @@ -49,33 +49,6 @@ static SearchValues invalidFileNameSearchValues = SearchValues.Create(invalidFileNameChars); #endif - public static string ReplaceInvalidFileNameChars(this string value) - { - var span = value.AsSpan(); - - var index = IndexOfInvalidChar(span); - - if (index == -1) - { - return value; - } - - Span target = stackalloc char[value.Length]; - span.CopyTo(target); - - target[index] = '-'; - index++; - for (; index < target.Length; index++) - { - if (IsInvalid(target[index])) - { - target[index] = '-'; - } - } - - return target.ToString(); - } - static int IndexOfInvalidChar(CharSpan span) => #if NET8_0_OR_GREATER span.IndexOfAny(invalidFileNameSearchValues); From 370f5827f977554bd3606a9adac40da416ab5e8f Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 19 Jul 2024 11:18:08 +1000 Subject: [PATCH 19/20] . --- .../Snippets/ClassLevelParams.Simple_arg1=2.verified.txt | 2 +- .../ClassLevelParams.WithMethodLevel_arg1=2_arg2=3.verified.txt | 2 +- .../ClassLevelParams.WithMethodLevel_arg1=2_arg2=4.verified.txt | 2 +- ...ests.TestCaseWithNameAndInvalidChars_arg=Value1.verified.txt | 1 + .../Tests.TestCaseWithName_arg=Value1.verified.txt | 1 + 5 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 src/Verify.NUnit.Tests/Tests.TestCaseWithNameAndInvalidChars_arg=Value1.verified.txt create mode 100644 src/Verify.NUnit.Tests/Tests.TestCaseWithName_arg=Value1.verified.txt diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.Simple_arg1=2.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.Simple_arg1=2.verified.txt index 3ee291f7bd..5f282702bb 100644 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.Simple_arg1=2.verified.txt +++ b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.Simple_arg1=2.verified.txt @@ -1 +1 @@ -Value \ No newline at end of file + \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=2_arg2=3.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=2_arg2=3.verified.txt index 3ee291f7bd..5f282702bb 100644 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=2_arg2=3.verified.txt +++ b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=2_arg2=3.verified.txt @@ -1 +1 @@ -Value \ No newline at end of file + \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=2_arg2=4.verified.txt b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=2_arg2=4.verified.txt index 3ee291f7bd..5f282702bb 100644 --- a/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=2_arg2=4.verified.txt +++ b/src/Verify.NUnit.Tests/Snippets/ClassLevelParams.WithMethodLevel_arg1=2_arg2=4.verified.txt @@ -1 +1 @@ -Value \ No newline at end of file + \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Tests.TestCaseWithNameAndInvalidChars_arg=Value1.verified.txt b/src/Verify.NUnit.Tests/Tests.TestCaseWithNameAndInvalidChars_arg=Value1.verified.txt new file mode 100644 index 0000000000..5f282702bb --- /dev/null +++ b/src/Verify.NUnit.Tests/Tests.TestCaseWithNameAndInvalidChars_arg=Value1.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Verify.NUnit.Tests/Tests.TestCaseWithName_arg=Value1.verified.txt b/src/Verify.NUnit.Tests/Tests.TestCaseWithName_arg=Value1.verified.txt new file mode 100644 index 0000000000..5f282702bb --- /dev/null +++ b/src/Verify.NUnit.Tests/Tests.TestCaseWithName_arg=Value1.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file From 618875756ea89407fd350a28b3a9206e5a8bd967 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 19 Jul 2024 12:05:22 +1000 Subject: [PATCH 20/20] . --- src/Benchmarks/FileNameCleanerBenchmarks.cs | 10 ---------- ...marksTests.ReplaceInvalidFileNameChars.verified.txt | 1 - src/Verify.Tests/FileNameCleanerBenchmarksTests.cs | 6 ------ 3 files changed, 17 deletions(-) delete mode 100644 src/Benchmarks/FileNameCleanerBenchmarks.cs delete mode 100644 src/Verify.Tests/FileNameCleanerBenchmarksTests.ReplaceInvalidFileNameChars.verified.txt delete mode 100644 src/Verify.Tests/FileNameCleanerBenchmarksTests.cs diff --git a/src/Benchmarks/FileNameCleanerBenchmarks.cs b/src/Benchmarks/FileNameCleanerBenchmarks.cs deleted file mode 100644 index 0b88434e24..0000000000 --- a/src/Benchmarks/FileNameCleanerBenchmarks.cs +++ /dev/null @@ -1,10 +0,0 @@ -[MemoryDiagnoser(false)] -public class FileNameCleanerBenchmarks -{ - [Benchmark] - public void ReplaceInvalidFileNameChars() - { - "Ant apple | The Bear Fox > Theater".ReplaceInvalidFileNameChars(); - "Ant apple The Bear Fox Theater".ReplaceInvalidFileNameChars(); - } -} \ No newline at end of file diff --git a/src/Verify.Tests/FileNameCleanerBenchmarksTests.ReplaceInvalidFileNameChars.verified.txt b/src/Verify.Tests/FileNameCleanerBenchmarksTests.ReplaceInvalidFileNameChars.verified.txt deleted file mode 100644 index 6bc7ce878a..0000000000 --- a/src/Verify.Tests/FileNameCleanerBenchmarksTests.ReplaceInvalidFileNameChars.verified.txt +++ /dev/null @@ -1 +0,0 @@ -Ant apple - The Bear Fox - Theater \ No newline at end of file diff --git a/src/Verify.Tests/FileNameCleanerBenchmarksTests.cs b/src/Verify.Tests/FileNameCleanerBenchmarksTests.cs deleted file mode 100644 index 77db096977..0000000000 --- a/src/Verify.Tests/FileNameCleanerBenchmarksTests.cs +++ /dev/null @@ -1,6 +0,0 @@ -public class FileNameCleanerBenchmarksTests -{ - [Fact] - public Task ReplaceInvalidFileNameChars() => - Verify("Ant apple | The Bear Fox > Theater".ReplaceInvalidFileNameChars()); -} \ No newline at end of file