Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions src/Ninject.Test/Integration/ReadOnlyKernelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ public void TryGet_ServiceAndParameters()
bindings.Should().OnlyContain(b => !b.IsImplicit);
}

[Fact(Skip = "Unique?")]
public void TryGet_ServiceAndNameAndParameters_ResolvesUsingFirstMatchingBindingWhenTypeIsSelfBinding()
[Fact()]
public void TryGet_ServiceAndNameAndParameters_WhenTypeIsSelfBinding()
{
var service = typeof(Sword);

Expand All @@ -371,17 +371,16 @@ public void TryGet_ServiceAndNameAndParameters_ResolvesUsingFirstMatchingBinding
Kernel = Configuration.BuildReadOnlyKernel();

var weapon = Kernel.TryGet(service, "a", Array.Empty<IParameter>());
weapon.Should().NotBeNull();
weapon.Should().BeOfType<Sword>();
weapon.Should().BeNull();

var bindings = Kernel.GetBindings(service);
bindings.Should().HaveCount(2);
bindings.Should().OnlyContain(b => !b.IsImplicit);
}


[Fact(Skip = "Unique?")]
public void TryGet_ServiceAndNameAndParameters_ResolvesUsingFirstMatchingBindingWhenTypeIsNotSelfBinding()
[Fact()]
public void TryGet_ServiceAndNameAndParameters_WhenTypeIsNotSelfBinding()
{
var service = typeof(IWeapon);

Expand All @@ -391,16 +390,15 @@ public void TryGet_ServiceAndNameAndParameters_ResolvesUsingFirstMatchingBinding
Kernel = Configuration.BuildReadOnlyKernel();

var weapon = Kernel.TryGet(service, "a", Array.Empty<IParameter>());
weapon.Should().NotBeNull();
weapon.Should().BeOfType<Sword>();
weapon.Should().BeNull();

var bindings = Kernel.GetBindings(service);
bindings.Should().HaveCount(2);
bindings.Should().OnlyContain(b => !b.IsImplicit);
}

[Fact(Skip = "Unique?")]
public void TryGet_ServiceAndConstraintAndParameters_ResolvesUsingFirstMatchingBindingWhenTypeIsSelfBinding()
[Fact()]
public void TryGet_ServiceAndConstraintAndParameters_WhenTypeIsSelfBinding()
{
var service = typeof(Sword);

Expand All @@ -412,16 +410,15 @@ public void TryGet_ServiceAndConstraintAndParameters_ResolvesUsingFirstMatchingB

var weapon = Kernel.TryGet(service, (metadata) => metadata.Name == "a", Array.Empty<IParameter>());

weapon.Should().NotBeNull();
weapon.Should().BeOfType<Sword>();
weapon.Should().BeNull();

var bindings = Kernel.GetBindings(service);
bindings.Should().HaveCount(3);
bindings.Should().OnlyContain(b => !b.IsImplicit);
}

[Fact(Skip ="Unique?")]
public void TryGet_ServiceAndConstraintAndParameters_ResolvesUsingFirstMatchingBindingWhenTypeIsNotSelfBindingAndNotGeneric()
[Fact()]
public void TryGet_ServiceAndConstraintAndParameters_WhenTypeIsNotSelfBindingAndNotGeneric()
{
var service = typeof(IWeapon);

Expand All @@ -432,8 +429,7 @@ public void TryGet_ServiceAndConstraintAndParameters_ResolvesUsingFirstMatchingB

var weapon = Kernel.TryGet(service, (metadata) => metadata.Name == "a", Array.Empty<IParameter>());

weapon.Should().NotBeNull();
weapon.Should().BeOfType<Sword>();
weapon.Should().BeNull();

var bindings = Kernel.GetBindings(service);
bindings.Should().HaveCount(2);
Expand Down
4 changes: 2 additions & 2 deletions src/Ninject/Syntax/ResolutionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public static object TryGet(this IResolutionRoot root, Type service, params IPar
/// </returns>
public static object TryGet(this IResolutionRoot root, Type service, string name, params IParameter[] parameters)
{
return TryGet(() => ResolveSingle(root, service, b => b.Name == name, parameters, true, false));
return TryGet(() => ResolveSingle(root, service, b => b.Name == name, parameters, true, true));
}

/// <summary>
Expand All @@ -296,7 +296,7 @@ public static object TryGet(this IResolutionRoot root, Type service, string name
/// </returns>
public static object TryGet(this IResolutionRoot root, Type service, Func<IBindingMetadata, bool> constraint, params IParameter[] parameters)
{
return TryGet(() => ResolveSingle(root, service, constraint, parameters, true, false));
return TryGet(() => ResolveSingle(root, service, constraint, parameters, true, true));
}

/// <summary>
Expand Down