Skip to content

Commit

Permalink
added the tests for #643
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed May 29, 2024
1 parent c12cd9c commit 728b818
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using NUnit.Framework;
using NUnit.Framework.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace DryIoc.IssuesTests;

[TestFixture]
public sealed class GHIssue643_WithConcreteTypeDynamicRegistrations_results_in_unintended_instantiation : ITest
{
public int Run()
{
Test_1();
Test_2();
Test_3();
return 3;
}

[Test]
public void Test_1()
{
var rules = Rules.Default.WithAutoConcreteTypeResolution();

var container = new Container(rules);
container.Register<MyRegistry>();

var registry = container.Resolve<MyRegistry>();
Assert.IsEmpty(registry.Things);
}

[Test]
public void Test_2()
{
var rules = Rules.Default.WithConcreteTypeDynamicRegistrations();

var container = new Container(rules);
container.Register<MyRegistry>();

var registry = container.Resolve<MyRegistry>();
// Assert.IsEmpty(registry.Things); // todo: @wip
}

[Test]
public void Test_3()
{
var rules = Rules.Default;

var container = new Container(rules);
container.Register<Thing>();
container.Register<MyRegistry>();

var registry = container.Resolve<MyRegistry>();
Assert.AreEqual(1, registry.Things.ToArray().Length);
}

public class MyRegistry
{
public readonly IEnumerable<Thing> Things;
public MyRegistry(IEnumerable<Thing> things) => Things = things;
}

public class Thing
{
public Guid Id { get; set; }
}
}
11 changes: 6 additions & 5 deletions test/DryIoc.TestRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ public class Program
{
public static void Main()
{
new DecoratorTests().Run();
new GHIssue623_Scoped_service_decorator().Run();
new GHIssue191_Optional_IResolverContext_argument_in_Func_of_service().Run();
new InitializerTests().Run();
new GHIssue636_ServiceKey_in_RegisterDelegate_parameters().Run();
new GHIssue643_WithConcreteTypeDynamicRegistrations_results_in_unintended_instantiation().Run();
// new DecoratorTests().Run();
// new GHIssue623_Scoped_service_decorator().Run();
// new GHIssue191_Optional_IResolverContext_argument_in_Func_of_service().Run();
// new InitializerTests().Run();
// new GHIssue636_ServiceKey_in_RegisterDelegate_parameters().Run();
// new GHIssue631_Conditional_registrations().Run();

RunAllTests();
Expand Down

0 comments on commit 728b818

Please sign in to comment.