Skip to content

Commit

Permalink
added failing test for #667
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Nov 14, 2024
1 parent a07c730 commit 4d2a5d3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using NUnit.Framework;

using System;
using System.Text;
using DryIoc.FastExpressionCompiler.LightExpression;
using System.Linq;
using System.Diagnostics;
using DryIoc.ImTools;

namespace DryIoc.IssuesTests;

[TestFixture]
public class GHIssue667_Resolve_with_serviceKey_does_not_invoke_factory_selector : ITest
{
public int Run()
{
// Original_case(); //todo: @fixme @wip
return 1;
}

public interface IFoo { }
public class Foo : IFoo { }

[Test]
public void Original_case()
{
var count = 0;
var container = new Container(rules =>
rules.WithFactorySelector(
(request, single, many) =>
{
++count;
return single
?? many.FindFirst(request.ServiceKey, static (sk, f) => f.Key.Equals(sk))?.Value;
}));

container.Register<IFoo, Foo>(); // Default
container.Register<IFoo, Foo>(serviceKey: "my"); // Keyed
_ = container.Resolve<IFoo>(); // Custom factory selector invoked
Assert.AreEqual(1, count);

_ = container.Resolve<IFoo>("my"); // Custom factory selector NOT invoked
Assert.AreEqual(2, count);
}
}
3 changes: 2 additions & 1 deletion test/DryIoc.TestRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class Program
{
public static void Main()
{
new GHIssue503_Compile_time_container().Run();
new GHIssue667_Resolve_with_serviceKey_does_not_invoke_factory_selector().Run();
// new GHIssue503_Compile_time_container().Run();
// new GHIssue659_Can_I_inspect_a_scope_for_all_the_dependencies_resolved_in_the_scope().Run();
// new GHIssue191_Optional_IResolverContext_argument_in_Func_of_service().Run();
// new GHIssue619_FaultySingletonDependency().Run();
Expand Down

0 comments on commit 4d2a5d3

Please sign in to comment.