Skip to content

Commit

Permalink
small thing adjusting the test
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Jun 23, 2022
1 parent 7832c59 commit dd47a64
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
36 changes: 30 additions & 6 deletions src/DryIoc/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8426,10 +8426,35 @@ public static class Resolver
typeof(IResolver).Method(nameof(IResolver.Resolve), typeof(Type), typeof(object),
typeof(IfUnresolved), typeof(Type), typeof(Request), typeof(object[]));

// todo: @wip add multiple overloads #498
// internal static readonly MethodInfo ResolveMethod =
// typeof(IResolver).Method(nameof(IResolver.Resolve), typeof(Type), typeof(object),
// typeof(IfUnresolved), typeof(Type), typeof(Request), typeof(object[]));
/// <summary>Code Generation specific overload</summary>
public static object CodeGenResolve(this IResolver resolver, Type serviceType, Request parent) =>
resolver.Resolve(serviceType, null, IfUnresolved.Throw, null, parent, null);
internal static readonly MethodInfo CodeGenResolveWithReqMethod =
typeof(Resolver).Method(nameof(Resolver.CodeGenResolve), typeof(IResolver), typeof(Type), typeof(Request));

/// <summary>Code Generation specific overload</summary>
public static object CodeGenResolve(this IResolver resolver, Type serviceType, Request parent, object[] args) =>
resolver.Resolve(serviceType, null, IfUnresolved.Throw, null, parent, args);
internal static readonly MethodInfo CodeGenResolveWithReqAndArgsMethod =
typeof(Resolver).Method(nameof(Resolver.CodeGenResolve), typeof(IResolver), typeof(Type), typeof(Request), typeof(object[]));

/// <summary>Code Generation specific overload</summary>
public static object CodeGenResolve(this IResolver resolver, Type serviceType, IfUnresolved ifUnresolved, Request parent) =>
resolver.Resolve(serviceType, null, ifUnresolved, null, parent, null);
internal static readonly MethodInfo CodeGenResolveWithIfUnresolvedAndReqMethod =
typeof(Resolver).Method(nameof(Resolver.CodeGenResolve), typeof(IResolver), typeof(Type), typeof(IfUnresolved), typeof(Request));

/// <summary>Code Generation specific overload</summary>
public static object CodeGenResolve(this IResolver resolver, Type serviceType, Type requiredServiceType, Request parent) =>
resolver.Resolve(serviceType, requiredServiceType, IfUnresolved.Throw, null, parent, null);
internal static readonly MethodInfo CodeGenResolveWithRequiredTypeAndReqMethod =
typeof(Resolver).Method(nameof(Resolver.CodeGenResolve), typeof(IResolver), typeof(Type), typeof(Type), typeof(Request));

/// <summary>Code Generation specific overload</summary>
public static object CodeGenResolve(this IResolver resolver, Type serviceType, object serviceKey, Request parent) =>
resolver.Resolve(serviceType, serviceKey, IfUnresolved.Throw, null, parent, null);
internal static readonly MethodInfo CodeGenResolveWithServiceKeyAndReqMethod =
typeof(Resolver).Method(nameof(Resolver.CodeGenResolve), typeof(IResolver), typeof(Type), typeof(object), typeof(Request));

internal static readonly MethodInfo ResolveManyMethod =
typeof(IResolver).GetMethod(nameof(IResolver.ResolveMany));
Expand All @@ -8443,8 +8468,7 @@ public static object Resolve(this IResolver resolver, Type serviceType, IfUnreso
resolver.Resolve(serviceType, ifUnresolved);

/// <summary>Resolves instance of type TService from container.</summary>
public static TService Resolve<TService>(this IResolver resolver,
IfUnresolved ifUnresolved = IfUnresolved.Throw) =>
public static TService Resolve<TService>(this IResolver resolver, IfUnresolved ifUnresolved = IfUnresolved.Throw) =>
(TService)resolver.Resolve(typeof(TService), ifUnresolved);

/// <summary>Tries to resolve instance of service type from container.</summary>
Expand Down
36 changes: 24 additions & 12 deletions test/DryIoc.IssuesTests/Issue_HandleVariance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,39 @@
namespace DryIoc.IssuesTests
{
[TestFixture]
public class Issue_HandleVariance
public class Issue_HandleVariance : ITest
{
[Test, Explicit] // Ignore("fixme") todo: @bug? check why it is failing
public void CommandHandlers_CanBeResolved_From_IoC()
public int Run()
{
Test();
return 1;
}

[Test]
public void Test()
{
var container = new Container();

container.Register(typeof(IBird<>), typeof(BirdBaseImpl<>));
container.Register(typeof(IBird<Bird>), typeof(BirdImpl));
container.Register(typeof(IContain<>), typeof(ContainBirdBase<>));
container.Register(typeof(IContain<Bird>), typeof(ContainBird));

var birds = container.ResolveMany<IContain<Bird>>().ToList();
Assert.AreEqual(1, birds.Count());

var birdBases = container.ResolveMany<IContain<BirdBase<string>>>();
Assert.AreEqual(1, birdBases.Count());

var services = container.ResolveMany<IBird<Bird>>();
Assert.AreEqual(2, services.Count());
var birdsArray = container.Resolve<IContain<Bird>[]>();
Assert.AreEqual(1, birdsArray.Length);

var servicesArray = container.Resolve<IBird<Bird>[]>();
Assert.AreEqual(2, servicesArray.Length);
var birdBasesArray = container.Resolve<IContain<BirdBase<string>>[]>();
Assert.AreEqual(1, birdBasesArray.Length);
}

public interface IBird<in T> { }
public interface IContain<in T> { }
public class BirdBase<T> { }
public class Bird : BirdBase<string> { } // IBird<string>
public class BirdImpl : IBird<Bird> { }
public class BirdBaseImpl<T> : IBird<BirdBase<T>> { }
public class ContainBird : IContain<Bird> { }
public class ContainBirdBase<T> : IContain<BirdBase<T>> { }
}
}
1 change: 1 addition & 0 deletions test/DryIoc.TestRunner.net472/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static void RunAllTests()
var issueTests = new ITest[]
{
new Issue_Can_resolve_singleton_with_Func_of_scoped_dependency(),
new Issue_HandleVariance(),
new Issue_InjectingSerilogLogger(),
new ParameterResolutionFixture(),
new Issue_Register_null_string(),
Expand Down
1 change: 1 addition & 0 deletions test/DryIoc.TestRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static void RunAllTests()
var issueTests = new ITest[]
{
new Issue_Can_resolve_singleton_with_Func_of_scoped_dependency(),
new Issue_HandleVariance(),
new Issue_InjectingSerilogLogger(),
new ParameterResolutionFixture(),
new Issue_Register_null_string(),
Expand Down

0 comments on commit dd47a64

Please sign in to comment.