-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from RaymondHuy/Issue#8
Enhance Issue #8: Support complex type when configure module
- Loading branch information
Showing
5 changed files
with
139 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
test/Autofac.Configuration.Test/Core/ModuleConfiguration_ComplexTypeFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace Autofac.Configuration.Test.Core | ||
{ | ||
public class ModuleConfiguration_ComplexTypeFixture | ||
{ | ||
[Fact] | ||
public void RegisterConfiguredModules_ComplexParameterType() | ||
{ | ||
var builder = EmbeddedConfiguration.ConfigureContainerWithJson("ModuleConfiguration_ComplexType.json"); | ||
var container = builder.Build(); | ||
|
||
var poco = container.Resolve<ComplexParameterComponent>(); | ||
|
||
Assert.Equal(2, poco.List.Count()); | ||
Assert.Equal("Val1", poco.List[0]); | ||
Assert.Equal("Val2", poco.List[1]); | ||
} | ||
|
||
[Fact] | ||
public void RegisterConfiguredModules_ComplexPropertyType() | ||
{ | ||
var builder = EmbeddedConfiguration.ConfigureContainerWithJson("ModuleConfiguration_ComplexType.json"); | ||
var container = builder.Build(); | ||
|
||
var poco = container.Resolve<ComplexPropertyComponent>(); | ||
|
||
Assert.Equal(2, poco.List.Count()); | ||
Assert.Equal("Val3", poco.List[0]); | ||
Assert.Equal("Val4", poco.List[1]); | ||
} | ||
|
||
private class ComplexParameterTypeModule : Module | ||
{ | ||
public ComplexType ComplexType { get; set; } | ||
|
||
public ComplexParameterTypeModule(ComplexType complexType) | ||
{ | ||
ComplexType = complexType; | ||
} | ||
|
||
protected override void Load(ContainerBuilder builder) | ||
{ | ||
builder.RegisterType<ComplexParameterComponent>().WithProperty("List", ComplexType.List); | ||
} | ||
} | ||
|
||
private class ComplexPropertyTypeModule : Module | ||
{ | ||
public ComplexType ComplexType { get; set; } | ||
|
||
protected override void Load(ContainerBuilder builder) | ||
{ | ||
builder.RegisterType<ComplexPropertyComponent>().WithProperty("List", ComplexType.List); | ||
} | ||
} | ||
|
||
private class ComplexType | ||
{ | ||
public IList<string> List { get; set; } | ||
} | ||
|
||
private class ComplexParameterComponent | ||
{ | ||
public IList<string> List { get; set; } | ||
} | ||
|
||
private class ComplexPropertyComponent | ||
{ | ||
public IList<string> List { get; set; } | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
test/Autofac.Configuration.Test/Files/ModuleConfiguration_ComplexType.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"defaultAssembly": "Autofac.Configuration.Test", | ||
"modules": [ | ||
{ | ||
"type": "Autofac.Configuration.Test.Core.ModuleConfiguration_ComplexTypeFixture+ComplexParameterTypeModule", | ||
"parameters": { | ||
"ComplexType": { | ||
"List": [ "Val1", "Val2" ] | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "Autofac.Configuration.Test.Core.ModuleConfiguration_ComplexTypeFixture+ComplexPropertyTypeModule", | ||
"properties": { | ||
"ComplexType": { | ||
"List": [ "Val3", "Val4" ] | ||
} | ||
} | ||
} | ||
] | ||
} |