Skip to content

Commit 13d1877

Browse files
committed
Merge branch 'master' into nugetMigration
2 parents 91b1179 + 4f9ab2e commit 13d1877

File tree

17 files changed

+187
-33
lines changed

17 files changed

+187
-33
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<img src="http://fluentnhibernate.org/images/logo.png" alt="Fluent NHibernate - Fluent mapping for your model" />
1+
<img src="https://github.com/jagregory/fluent-nhibernate/blob/master/docs/logo.png" alt="Fluent NHibernate - Fluent mapping for your model" />
22
=============================================
33

44
Fluent, XML-less, compile safe, automated, convention-based mappings for NHibernate. *Get your fluent on.*
@@ -26,4 +26,4 @@ Fluent NHibernate wouldn't be possible without the time and effort of its contri
2626

2727
Thanks goes to [Jeremy Miller](http://codebetter.com/blogs/jeremy.miller) for the original idea and implementation.
2828

29-
Fluent NHibernate is &copy; 2008-2011 [James Gregory](http://jagregory.com) and contributors under the [BSD license](fluent-nhibernate/blob/master/LICENSE.txt)
29+
Fluent NHibernate is &copy; 2008-2013 [James Gregory](http://jagregory.com) and contributors under the [BSD license](fluent-nhibernate/blob/master/LICENSE.txt)

src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Subclass.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Linq;
2+
using FluentNHibernate.Mapping;
23
using FluentNHibernate.MappingModel.ClassBased;
34
using FluentNHibernate.Specs.FluentInterface.Fixtures;
45
using Machine.Specifications;

src/FluentNHibernate.Testing/DomainModel/Mapping/MappingTester.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public class MappingTester<T>
1616
private readonly PersistenceModel model;
1717
private string currentPath;
1818

19-
public MappingTester()
20-
: this(new PersistenceModel())
19+
public MappingTester(): this(new PersistenceModel())
2120
{}
2221

2322
public MappingTester(PersistenceModel model)
@@ -65,9 +64,7 @@ public virtual MappingTester<T> ForMapping(ClassMap<T> classMap)
6564
model.Add(classMap);
6665

6766
var mappings = model.BuildMappings();
68-
var foundMapping = mappings
69-
.Where(x => x.Classes.FirstOrDefault(c => c.Type == typeof(T)) != null)
70-
.FirstOrDefault();
67+
var foundMapping = mappings.FirstOrDefault(x => x.Classes.FirstOrDefault(c => c.Type == typeof(T)) != null);
7168

7269
if (foundMapping == null)
7370
throw new InvalidOperationException("Could not find mapping for class '" + typeof(T).Name + "'");
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using FluentNHibernate.Automapping;
7+
using FluentNHibernate.Cfg.Db;
8+
using FluentNHibernate.Mapping;
9+
using FluentNHibernate.Mapping.Providers;
10+
using FluentNHibernate.Testing.DomainModel.Mapping;
11+
using NHibernate.Cfg;
12+
using NUnit.Framework;
13+
14+
namespace FluentNHibernate.Testing.FluentInterfaceTests
15+
{
16+
[TestFixture]
17+
public class TablePerHierarchyTests//: BaseManualMapFixture
18+
{
19+
//[Test]
20+
//public void ShouldHonorBatchSizeOnASubclass()
21+
//{
22+
// var model = new PersistenceModel();
23+
// model.Add(new BaseMapping());
24+
// model.Add(new DerivedMapping());
25+
26+
// var mappings = model.BuildMappings();
27+
// var subclassMap = mappings.SelectMany(m => m.Classes)
28+
// .FirstOrDefault(cm => cm.Subclasses.Any()).Subclasses.FirstOrDefault();
29+
// subclassMap.BatchSize.ShouldEqual(858);
30+
//}
31+
32+
//[Test]
33+
//public void ShouldHonorBatchSizeOnASubclass()
34+
//{
35+
// AddClassMapping(new BaseMapping());
36+
// Test<Derived>(x => x.ForSubclassMapping(new DerivedMapping()).HasAttribute("batch-size", "858"));
37+
//}
38+
}
39+
40+
public class Base
41+
{
42+
public int Id { get; set; }
43+
public string Discriminator { get; set; }
44+
public decimal Value { get; set; }
45+
}
46+
47+
public class Derived : Base
48+
{
49+
public string FirstName { get; set; }
50+
}
51+
52+
public class BaseMapping : ClassMap<Base>
53+
{
54+
public BaseMapping()
55+
{
56+
Id(x => x.Id);
57+
Map(x => x.Value);
58+
DiscriminateSubClassesOnColumn("Discriminator");
59+
}
60+
}
61+
62+
public class DerivedMapping : SubclassMap<Derived>
63+
{
64+
public DerivedMapping()
65+
{
66+
Map(x => x.FirstName);
67+
BatchSize(858);
68+
}
69+
}
70+
71+
public abstract class BaseManualMapFixture
72+
{
73+
private Configuration cfg;
74+
private PersistenceModel model;
75+
76+
[SetUp]
77+
public void CreateDatabaseCfg()
78+
{
79+
cfg = new Configuration();
80+
model = new PersistenceModel();
81+
82+
SQLiteConfiguration.Standard
83+
.InMemory()
84+
.ConfigureProperties(cfg);
85+
}
86+
87+
protected void AddClassMapping(IMappingProvider mapping)
88+
{
89+
model.Add(mapping);
90+
}
91+
92+
protected void AddSubClassMapping(IIndeterminateSubclassMappingProvider mapping)
93+
{
94+
model.Add(mapping);
95+
}
96+
97+
protected void OutputMappings(StringBuilder builder)
98+
{
99+
model.WriteMappingsTo(new StringWriter(builder));
100+
}
101+
102+
protected void Test<T>(Action<MappingTester<T>> mappingTester)
103+
{
104+
mappingTester(new MappingTester<T>(model));
105+
}
106+
}
107+
}

src/FluentNHibernate.Testing/FluentInterfaceTests/WhereTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ public void ShouldAllowWhereAsString()
103103
.ShouldEqual("some where clause");
104104
}
105105

106+
[Test]
107+
public void ShouldAllowInheritedProperty()
108+
{
109+
WhereSubChild(x => x.String == SomeValue)
110+
.ShouldEqual("String = 'SomeValue'");
111+
}
106112
#region helpers
107113

108114
private string Where(Expression<Func<Child, bool>> where)
@@ -123,6 +129,24 @@ private string Where(Expression<Func<Child, bool>> where)
123129
.Where;
124130
}
125131

132+
private string WhereSubChild(Expression<Func<SubChild, bool>> where)
133+
{
134+
var classMap = new ClassMap<Target>();
135+
classMap.Id(x => x.Id);
136+
classMap.HasMany(x => x.SubChildren)
137+
.Where(where);
138+
139+
var model = new PersistenceModel();
140+
141+
model.Add(classMap);
142+
143+
return model.BuildMappings()
144+
.First()
145+
.Classes.First()
146+
.Collections.First()
147+
.Where;
148+
}
149+
126150
private string Where(string where)
127151
{
128152
var classMap = new ClassMap<Target>();
@@ -147,6 +171,7 @@ private class Target
147171
{
148172
public int Id { get; set; }
149173
public IList<Child> Children { get; set;}
174+
public IList<SubChild> SubChildren { get; set; }
150175
}
151176

152177
private class Child
@@ -156,6 +181,10 @@ private class Child
156181
public Enum Enum { get; set; }
157182
}
158183

184+
private class SubChild : Child
185+
{
186+
}
187+
159188
private enum Enum
160189
{
161190
One = 1

src/FluentNHibernate.Testing/FluentNHibernate.Testing.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
<Compile Include="Fixtures\AutoMappingAlterations\AbstractOverrideImplementation.cs" />
138138
<Compile Include="Fixtures\AutoMappingAlterations\Model\Qux.cs" />
139139
<Compile Include="Cfg\Db\IngresConfigurationTester.cs" />
140+
<Compile Include="FluentInterfaceTests\TablePerHierarchyTests.cs" />
140141
<Compile Include="StubTypeSource.cs" />
141142
<Compile Include="AutoMapping\TestFixtures.cs" />
142143
<Compile Include="Cfg\Db\DB2ConfigurationTester.cs" />

src/FluentNHibernate/Cfg/Fluently.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@ namespace FluentNHibernate.Cfg
55
/// <summary>
66
/// Fluently configure NHibernate
77
/// </summary>
8-
public static class Fluently
8+
public class Fluently
99
{
10+
/// <summary>
11+
/// Begin fluently configuring NHibernate
12+
/// </summary>
13+
/// <returns>Fluent Configuration</returns>
14+
public FluentConfiguration BeginConfigure()
15+
{
16+
return Fluently.Configure();
17+
}
18+
1019
/// <summary>
1120
/// Begin fluently configuring NHibernate
1221
/// </summary>
@@ -15,6 +24,16 @@ public static FluentConfiguration Configure()
1524
{
1625
return new FluentConfiguration();
1726
}
27+
28+
/// <summary>
29+
/// Begin fluently configuring NHibernate
30+
/// </summary>
31+
/// <param name="cfg">Instance of an NHibernate Configuration</param>
32+
/// <returns>Fluent Configuration</returns>
33+
public FluentConfiguration BeginConfigure(Configuration cfg)
34+
{
35+
return Fluently.Configure(cfg);
36+
}
1837

1938
/// <summary>
2039
/// Begin fluently configuring NHibernate
@@ -26,4 +45,4 @@ public static FluentConfiguration Configure(Configuration cfg)
2645
return new FluentConfiguration(cfg);
2746
}
2847
}
29-
}
48+
}

src/FluentNHibernate/Conventions/AcceptanceCriteria/ConcreteAcceptanceCriteria.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public IAcceptanceCriteria<TInspector> Expect(Expression<Func<TInspector, string
5252
return this;
5353
}
5454

55-
public IAcceptanceCriteria<TInspector> Expect(Expression<Func<TInspector, bool>> evaluation)
55+
public IAcceptanceCriteria<TInspector> Expect(Func<TInspector, bool> evaluation)
5656
{
5757
var expectation = CreateEvalExpectation(evaluation);
5858

@@ -113,7 +113,7 @@ protected virtual IExpectation CreateExpectation(Expression<Func<TInspector, obj
113113
return new Expectation<TInspector>(expression, value);
114114
}
115115

116-
protected virtual IExpectation CreateEvalExpectation(Expression<Func<TInspector, bool>> expression)
116+
protected virtual IExpectation CreateEvalExpectation(Func<TInspector, bool> expression)
117117
{
118118
return new EvalExpectation<TInspector>(expression);
119119
}

src/FluentNHibernate/Conventions/AcceptanceCriteria/EvalExpectation.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@ namespace FluentNHibernate.Conventions.AcceptanceCriteria
66
{
77
public class EvalExpectation<TInspector> : IExpectation
88
where TInspector : IInspector
9-
{
10-
private readonly Expression<Func<TInspector, bool>> expression;
9+
{
10+
private readonly Func<TInspector, bool> expression;
1111

12-
public EvalExpectation(Expression<Func<TInspector, bool>> expression)
12+
public EvalExpectation(Func<TInspector, bool> expression)
1313
{
1414
this.expression = expression;
1515
}
1616

1717
public bool Matches(TInspector inspector)
1818
{
19-
var compiledFunc = expression.Compile();
20-
21-
return compiledFunc(inspector);
19+
return expression(inspector);
2220
}
2321

2422
bool IExpectation.Matches(IInspector inspector)

src/FluentNHibernate/Conventions/AcceptanceCriteria/IAcceptanceCriteria.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ IAcceptanceCriteria<TInspector> SameAs<T>()
1313
IAcceptanceCriteria<TInspector> OppositeOf<T>()
1414
where T : IConventionAcceptance<TInspector>, new();
1515

16-
IAcceptanceCriteria<TInspector> Expect(Expression<Func<TInspector, bool>> evaluation);
16+
IAcceptanceCriteria<TInspector> Expect(Func<TInspector, bool> evaluation);
1717
IAcceptanceCriteria<TInspector> Expect(Expression<Func<TInspector, object>> propertyExpression, IAcceptanceCriterion value);
1818

1919
// special case for string, because it's actually an IEnumerable<char>, which makes it fall through

0 commit comments

Comments
 (0)