From 1236ccf6ecad947fd02577de787ceafb67a27cc9 Mon Sep 17 00:00:00 2001 From: dadhi Date: Thu, 26 Dec 2024 23:19:47 +0100 Subject: [PATCH] adding failed test for #672 --- b.bat | 5 +- ..._with_both_MefAttributedModel_and_MS_DI.cs | 1 - ...ng_decorator_parameter_with_custom_args.cs | 54 +++++++++++++++++++ test/DryIoc.TestRunner/Program.cs | 8 +-- 4 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 test/DryIoc.IssuesTests/GHIssue672_Wrong_decorator_parameter_with_custom_args.cs diff --git a/b.bat b/b.bat index 74a86919..b2ae947b 100644 --- a/b.bat +++ b/b.bat @@ -12,10 +12,11 @@ echo: echo:# Build and Run TestRunners for %LatestSupportedNet% and .NET FRAMEWORK 4.7.2 echo: echo:## %LatestSupportedNet% -dotnet run -v:minimal -f:net8.0 -c:Release -p:GeneratePackageOnBuild=false --project test/DryIoc.TestRunner/DryIoc.TestRunner.csproj +dotnet run -v:minimal -c:Release -f:net9.0 -p:LatestSupportedNet=net9.0 --project test/DryIoc.TestRunner/DryIoc.TestRunner.csproj + echo: echo:## .NET FRAMEWORK 4.7.2 -dotnet run -v:minimal -c:Release -p:GeneratePackageOnBuild=false --project test/DryIoc.TestRunner.net472/DryIoc.TestRunner.net472.csproj +dotnet run -v:minimal -c:Release --project test/DryIoc.TestRunner.net472/DryIoc.TestRunner.net472.csproj if %ERRORLEVEL% neq 0 goto :error diff --git a/test/DryIoc.IssuesTests/GHIssue669_Unable_to_resolve_type_with_optional_arguments_with_both_MefAttributedModel_and_MS_DI.cs b/test/DryIoc.IssuesTests/GHIssue669_Unable_to_resolve_type_with_optional_arguments_with_both_MefAttributedModel_and_MS_DI.cs index 89ee37c1..b8bd28fb 100644 --- a/test/DryIoc.IssuesTests/GHIssue669_Unable_to_resolve_type_with_optional_arguments_with_both_MefAttributedModel_and_MS_DI.cs +++ b/test/DryIoc.IssuesTests/GHIssue669_Unable_to_resolve_type_with_optional_arguments_with_both_MefAttributedModel_and_MS_DI.cs @@ -1,5 +1,4 @@ using NUnit.Framework; -using DryIoc.ImTools; using DryIoc.MefAttributedModel; using DryIoc.Microsoft.DependencyInjection; diff --git a/test/DryIoc.IssuesTests/GHIssue672_Wrong_decorator_parameter_with_custom_args.cs b/test/DryIoc.IssuesTests/GHIssue672_Wrong_decorator_parameter_with_custom_args.cs new file mode 100644 index 00000000..dfffe35f --- /dev/null +++ b/test/DryIoc.IssuesTests/GHIssue672_Wrong_decorator_parameter_with_custom_args.cs @@ -0,0 +1,54 @@ +using NUnit.Framework; +using System; + +namespace DryIoc.IssuesTests; + +[TestFixture] +public class GHIssue672_Wrong_decorator_parameter_with_custom_args : ITest +{ + public int Run() + { + // Original_case(); + Case_without_args(); + return 2; + } + + public abstract class A { } + public class B : A { } + + private static object DecoratorA(object t) => t; + + [Test] + public void Original_case() + { + var now = DateTime.Now; + + var container = new Container(); + + container.Register(serviceKey: "xyz"); + + var decorateMethod = typeof(GHIssue672_Wrong_decorator_parameter_with_custom_args).SingleMethod(nameof(DecoratorA), true); + + container.Register(made: Made.Of(_ => decorateMethod), setup: Setup.DecoratorOf()); + + var res = container.Resolve("xyz", args: new object[] { now }); + + // Assert.IsInstanceOf(res); // todo: @fixme + } + + [Test] + public void Case_without_args() + { + var container = new Container(); + + container.Register(serviceKey: "xyz"); + + var decorateMethod = typeof(GHIssue672_Wrong_decorator_parameter_with_custom_args).SingleMethod(nameof(DecoratorA), true); + + container.Register(made: Made.Of(_ => decorateMethod), setup: Setup.DecoratorOf()); + + var res = container.Resolve("xyz"); + + Assert.IsInstanceOf(res); + } +} diff --git a/test/DryIoc.TestRunner/Program.cs b/test/DryIoc.TestRunner/Program.cs index bbb1b3ba..d645b880 100644 --- a/test/DryIoc.TestRunner/Program.cs +++ b/test/DryIoc.TestRunner/Program.cs @@ -9,10 +9,12 @@ public class Program { public static void Main() { - Rules.UnsafeResetDefaultRulesToUseCompilationOnly(); - new GHIssue623_Scoped_service_decorator().Run(); + new GHIssue672_Wrong_decorator_parameter_with_custom_args().Run(); + + // Rules.UnsafeResetDefaultRulesToUseCompilationOnly(); + // new GHIssue623_Scoped_service_decorator().Run(); - new GHIssue503_Compile_time_container().Run(); + // new GHIssue503_Compile_time_container().Run(); // new GHIssue667_Resolve_with_serviceKey_does_not_invoke_factory_selector().Run(); RunAllTests();