Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ public void CreateInstance_UsesInjectedContainerToCreateInstanceOfRequestedType(
Assert.Equal<string>(expectedCtorParam, pageData.Injected);
}

[Fact]
public void CreateInstance_UsesInjectedContainerToCreateInstanceOfPropertyGroupInRequestedType()
{
string expectedCtorParam = Guid.NewGuid().ToString();
Mock<IContainer> fakeContainer = new Mock<IContainer>();
fakeContainer.Setup(container => container.GetInstance(typeof(string))).Returns(expectedCtorParam);
StructureMapTypedPageActivator activator = new StructureMapTypedPageActivator(fakeContainer.Object);

PageTypeThatHasPropertyGroup pageData = (PageTypeThatHasPropertyGroup)activator.CreateAndPopulateTypedInstance(new PageTypeThatHasPropertyGroup(), typeof(PageTypeThatHasPropertyGroup));

Assert.Equal<string>(expectedCtorParam, pageData.PropertyGroup.Injected);
}

[Fact]
public void CreateInstance_ThrowsPageTypeBuilderExceptionForTypeWithNoPublicCtor()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="CreateInstanceTests.cs" />
<Compile Include="PageTypeThatHasPropertyGroup.cs" />
<Compile Include="PageTypeWithNoPublicConstructor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PageTypeWithStringCtorParam.cs" />
<Compile Include="PropertyGroupWithStringCtorParam.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PageTypeBuilder.Activation.StructureMap\PageTypeBuilder.Activation.StructureMap.csproj">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace PageTypeBuilder.Activation.StructureMap.Tests
{
public class PageTypeThatHasPropertyGroup : TypedPageData
{
[PageTypePropertyGroup]
public virtual PropertyGroupWithStringCtorParam PropertyGroup { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace PageTypeBuilder.Activation.StructureMap.Tests
{
public class PropertyGroupWithStringCtorParam : PageTypePropertyGroup
{
public string Injected;
public PropertyGroupWithStringCtorParam(string someDependency)
{
Injected = someDependency;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public override TypedPageData CreateInstance(Type typedType)
return base.CreateInstance(typedType, ctorParameters);
}

public override PageTypePropertyGroup CreatePropertyGroupInstance(Type typedType)
{
ParameterInfo[] expectedParameters = GetCtorParameters(typedType);

object[] ctorParameters = GetResolvedParameters(expectedParameters);

return base.CreatePropertyGroupInstance(typedType, ctorParameters);
}

private static ParameterInfo[] GetCtorParameters(Type typedType)
{
ConstructorInfo constructor = GetConstructorWithMostParameters(typedType);
Expand Down
3 changes: 1 addition & 2 deletions PageTypeBuilder/TypedPageData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ public string TargetFrame
{
PageData page = base.CreateWritableClone();
IEnumerable<PropertyInfo> properties = page.GetType().GetPageTypePropertyGroupProperties();
new TypedPageActivator().CreateAndPopulateNestedPropertyGroupInstances(page as TypedPageData, page, properties, string.Empty);
PageTypeResolver.Instance.Activator.CreateAndPopulateNestedPropertyGroupInstances(page as TypedPageData, page, properties, string.Empty);
return page;
}

}
}