Skip to content

Commit 2cd1819

Browse files
committed
almost got #105 working, one tests still fails
1 parent 63593b5 commit 2cd1819

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.NestedClasses.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Reflection;
45
using FluentNHibernate.Automapping;
56
using FluentNHibernate.MappingModel.ClassBased;
67
using FluentNHibernate.Specs.Automapping.Fixtures;
@@ -55,6 +56,39 @@ public override bool ShouldMap(Type type)
5556
}
5657
}
5758
}
59+
60+
public class when_automapper_is_told_to_map_a_class_with_a_nested_classes
61+
{
62+
Establish context = () =>
63+
{
64+
nonPublicNestedType = typeof(PersonCard).GetNestedTypes(BindingFlags.NonPublic).Single();
65+
model = AutoMap.Source(new StubTypeSource(typeof(PersonCard), typeof(PersonCard.PublicAddress), nonPublicNestedType),
66+
new DefaultAutomappingConfiguration());
67+
};
68+
69+
Because of = () => mappings = model.BuildMappings().SelectMany(m => m.Classes);
70+
It should_map_public_nested_class = () => mappings.ShouldContain(m => m.Type == typeof(PersonCard.PublicAddress));
71+
It should_not_map_not_public_nested_class = () => mappings.ShouldNotContain(m => m.Type == nonPublicNestedType);
72+
73+
static AutoPersistenceModel model;
74+
static DefaultAutomappingConfiguration configuration;
75+
static Type nonPublicNestedType;
76+
static IEnumerable<ClassMapping> mappings;
77+
}
78+
79+
public class PersonCard
80+
{
81+
public int Id { get; set; }
82+
public class PublicAddress
83+
{
84+
public int Id { get; set; }
85+
}
86+
private class PrivateAddress
87+
{
88+
public int Id { get; set; }
89+
}
90+
}
91+
5892
public class Order
5993
{
6094
public int Id { get; set; }

src/FluentNHibernate/Automapping/DefaultAutomappingConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public virtual bool ShouldMap(Type type)
1919
{
2020
return !type.ClosesInterface(typeof(IAutoMappingOverride<>)) &&
2121
!type.HasInterface(typeof(IMappingProvider)) &&
22-
!type.IsNested &&
22+
(type.IsPublic || (type.IsNotPublic && !type.IsNested)) &&
2323
type.IsClass;
2424
}
2525

0 commit comments

Comments
 (0)