Skip to content

Commit

Permalink
Add tests to validate fix for #1427.
Browse files Browse the repository at this point in the history
  • Loading branch information
tillig committed Sep 15, 2024
1 parent 42745cd commit 061efb4
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/Autofac.Specification.Test/Features/PropertyInjectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,39 @@ public void DecoratedInstanceWithPropertyInjectionAllowingCircularReferencesStil
instance.AssertProp();
}

[Fact]
public void WithPropertyDelegateAllowsNullValue()
{
// Issue 1427: WithProperty should consistently allow null values.
var builder = new ContainerBuilder();
builder.RegisterType<HasPublicSetter>().WithProperty(t => t.Val, null);
var container = builder.Build();
var instance = container.Resolve<HasPublicSetter>();
Assert.Null(instance.Val);
}

[Fact]
public void WithPropertyNamedAllowsNullValue()
{
// Issue 1427: WithProperty should consistently allow null values.
var builder = new ContainerBuilder();
builder.RegisterType<HasPublicSetter>().WithProperty(nameof(HasPublicSetter.Val), null);
var container = builder.Build();
var instance = container.Resolve<HasPublicSetter>();
Assert.Null(instance.Val);
}

[Fact]
public void WithPropertyTypedAllowsNullValue()
{
// Issue 1427: WithProperty should consistently allow null values.
var builder = new ContainerBuilder();
builder.RegisterType<HasPublicSetter>().WithProperty(TypedParameter.From<string>(null));
var container = builder.Build();
var instance = container.Resolve<HasPublicSetter>();
Assert.Null(instance.Val);
}

private class ConstructorParamNotAttachedToProperty
{
[SuppressMessage("SA1401", "SA1401")]
Expand Down

0 comments on commit 061efb4

Please # to comment.