diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/BasePEVerifyTestCase.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/BasePEVerifyTestCase.cs index aaa5655b3..1e2fc1ab4 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/BasePEVerifyTestCase.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/BasePEVerifyTestCase.cs @@ -19,6 +19,7 @@ namespace Castle.DynamicProxy.Tests using System.IO; using NUnit.Framework; + using NUnit.Framework.Internal; public class FindPeVerify { @@ -117,7 +118,10 @@ public bool IsVerificationDisabled [TearDown] public virtual void TearDown() { - if (IsVerificationPossible && !IsVerificationDisabled) + var currentTest = TestExecutionContext.CurrentContext.CurrentTest; + bool shouldSkipVerificationForCurrentTest = currentTest.Method.IsDefined(false); + + if (IsVerificationPossible && !IsVerificationDisabled && !shouldSkipVerificationForCurrentTest) { // Note: only supports one generated assembly at the moment var path = ((PersistentProxyBuilder)builder).SaveAssembly(); diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/ParameterDefaultValuesTestCase.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/ParameterDefaultValuesTestCase.cs index 3010ebf67..b66090aa8 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/ParameterDefaultValuesTestCase.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/ParameterDefaultValuesTestCase.cs @@ -1,4 +1,4 @@ -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ +// Copyright 2004-2026 Castle Project - http://www.castleproject.org/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -74,6 +74,7 @@ public void Fully_supported_Not_optional() Assert.IsAssignableFrom(coreLibDBNullType, proxiedParameter.DefaultValue); } + [SkipPEVerify(Reason = "no need to verify `HasDefaultValues` proxy type multiple times, it already gets verified in another test")] [TestCase(nameof(HasDefaultValues.Bool_default))] [TestCase(nameof(HasDefaultValues.Bool_non_default))] [TestCase(nameof(HasDefaultValues.Bool_nullable_null))] @@ -200,6 +201,7 @@ public void Not_supported_on_the_CLR_Generics(Type parameterType) } [Platform(Exclude = "Net,NetCore", Reason = "ParameterBuilder.SetConstant does not accept a null default value for value type parameters. See https://github.com/dotnet/corefx/issues/26164.")] + [SkipPEVerify(Reason = "no need to verify `HasDefaultValues` proxy type multiple times, it already gets verified in another test")] [TestCase(nameof(HasDefaultValues.DateTime_default))] [TestCase(nameof(HasDefaultValues.UserDefinedStruct_default))] public void Not_supported_on_the_CLR_Struct_default(string methodName) @@ -208,6 +210,7 @@ public void Not_supported_on_the_CLR_Struct_default(string methodName) } [Platform(Exclude = "Net,NetCore", Reason = "ParameterBuilder.SetConstant does not accept non-null default values for nullable enum parameters. See https://github.com/dotnet/coreclr/issues/17893.")] + [SkipPEVerify(Reason = "no need to verify `HasDefaultValues` proxy type multiple times, it already gets verified in another test")] [TestCase(nameof(HasDefaultValues.UserDefinedEnum_nullable_default))] [TestCase(nameof(HasDefaultValues.UserDefinedEnum_nullable_default_from_attribute))] [TestCase(nameof(HasDefaultValues.UserDefinedEnum_nullable_non_default))] @@ -218,6 +221,7 @@ public void Not_supported_on_the_CLR_UserDefinedEnum_nullable_non_null(string me } [Platform(Exclude = "Mono", Reason = "ParameterInfo.DefaultValue does not report the correct default value for non-null optional parameters of type `DateTime?` and `decimal?`. See https://github.com/mono/mono/issues/11303.")] + [SkipPEVerify(Reason = "no need to verify `HasDefaultValues` proxy type multiple times, it already gets verified in another test")] [TestCase(nameof(HasDefaultValues.DateTime_nullable_default_from_attribute))] [TestCase(nameof(HasDefaultValues.DateTime_nullable_non_default_from_attribute))] [TestCase(nameof(HasDefaultValues.Decimal_nullable_default))] diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/SkipPEVerifyAttribute.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/SkipPEVerifyAttribute.cs new file mode 100644 index 000000000..f4574ec7a --- /dev/null +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/SkipPEVerifyAttribute.cs @@ -0,0 +1,26 @@ +// Copyright 2004-2026 Castle Project - http://www.castleproject.org/ +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#nullable enable + +namespace Castle.DynamicProxy.Tests +{ + using System; + + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] + public sealed class SkipPEVerifyAttribute : Attribute + { + public string? Reason { get; set; } + } +}