Skip to content

Commit

Permalink
Add mixed constructor + property tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
alistairjevans committed Jan 28, 2023
1 parent 22dc230 commit 34a05a1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/Autofac.Specification.Test/Features/RequiredPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ public void MissingRequiredPropertyServiceThrowsException()
Assert.Contains(nameof(Component.ServiceB), exception.InnerException.Message);
}

[Fact]
public void CanMixConstructorsAndProperties()
{
var builder = new ContainerBuilder();
builder.RegisterType<ServiceA>();
builder.RegisterType<ServiceB>();
builder.RegisterType<MixedConstructorAndPropertyComponent>();

var container = builder.Build();

var component = container.Resolve<MixedConstructorAndPropertyComponent>();

Assert.NotNull(component.ServiceA);
Assert.NotNull(component.ServiceB);
}

[Fact]
public void ExplicitParameterOverridesRequiredAutowiring()
{
Expand Down Expand Up @@ -239,6 +255,18 @@ public ConstructorComponent()
required public ServiceB ServiceB { get; set; }
}

private class MixedConstructorAndPropertyComponent
{
public MixedConstructorAndPropertyComponent(ServiceA serviceA)
{
ServiceA = serviceA;
}

public ServiceA ServiceA { get; set; }

required public ServiceB ServiceB { get; set; }
}

private class MultiConstructorComponent
{
[SetsRequiredMembers]
Expand Down

0 comments on commit 34a05a1

Please sign in to comment.