James,
Attached is a patch that gets most of the way there, I think. I added
a test for the unique attribute and made changes similar to what you
did for the previous fix.
There is one test that isn't passing. The hbm is getting two lengths
for strings now - the correct one on the column (length 20) and one on
the property (length 100). I'm guessing it's from a convention that
has been set. I'm going to try to track that down but in case I can't
find it, hopefully this will get you most of the way there.
s.
Index: src/FluentNHibernate.Testing/DomainModel/Mapping/
ClassMapXmlCreationTester.cs
===================================================================
--- src/FluentNHibernate.Testing/DomainModel/Mapping/
ClassMapXmlCreationTester.cs (revision 330)
+++ src/FluentNHibernate.Testing/DomainModel/Mapping/
ClassMapXmlCreationTester.cs (working copy)
@@ -463,7 +463,7 @@
{
new MappingTester<MappedObject>()
.ForMapping(m => m.Map(x => x.Name).Unique())
- .Element("class/property").HasAttribute("unique",
"true");
+ .Element("class/property/column").HasAttribute
("unique", "true");
}
[Test]
@@ -471,7 +471,7 @@
{
new MappingTester<MappedObject>()
.ForMapping(m => m.Map(x => x.Name).Not.Unique())
- .Element("class/property").HasAttribute("unique",
"false");
+ .Element("class/property/column").HasAttribute
("unique", "false");
}
[Test]
Index: src/FluentNHibernate.Testing/DomainModel/Mapping/
PropertyMapTester.cs
===================================================================
--- src/FluentNHibernate.Testing/DomainModel/Mapping/
PropertyMapTester.cs (revision 330)
+++ src/FluentNHibernate.Testing/DomainModel/Mapping/
PropertyMapTester.cs (working copy)
@@ -129,35 +129,21 @@
[Test]
public void
Map_WithFluentLength_OnString_UsesWithLengthOf_PropertyColumnAttribute
()
{
- var classMap = new ClassMap<PropertyTarget>();
+ new MappingTester<PropertyTarget>()
+ .ForMapping(m => m.Map(x => x.Name).WithLengthOf(20))
+ .Element("class/property
[@name='Name']").DoesntHaveAttribute("length")
+ .Element("class/property[@name='Name']/
column").HasAttribute("length", "20");
+ }
- classMap.Map(x => x.Name)
- .WithLengthOf(20);
-
- var document = classMap.CreateMapping(new MappingVisitor
());
-
- // attribute on property
- var classElement =
document.DocumentElement.SelectSingleNode("class");
- var propertyElement = (XmlElement)
classElement.SelectSingleNode("property");
- propertyElement.AttributeShouldEqual("length", "20");
+ [Test]
+ public void
Map_WithFluentLength_OnDecimal_UsesWithLengthOf_PropertyColumnAttribute
()
+ {
+ new MappingTester<PropertyTarget>()
+ .ForMapping(m => m.Map(x =>
x.DecimalProperty).WithLengthOf(1))
+ .Element("class/property
[@name='DecimalProperty']").DoesntHaveAttribute("length")
+ .Element("class/property[@name='DecimalProperty']/
column").HasAttribute("length", "1");
}
- [Test]
- public void
Map_WithFluentLength_OnDecimal_UsesWithLengthOf_PropertyColumnAttribute
()
- {
- var classMap = new ClassMap<PropertyTarget>();
-
- classMap.Map(x => x.DecimalProperty)
- .WithLengthOf(1);
-
- var document = classMap.CreateMapping(new MappingVisitor());
-
- // attribute on property
- var classElement = document.DocumentElement.SelectSingleNode
("class");
- var propertyElement = (XmlElement)classElement.SelectSingleNode
("property");
- propertyElement.AttributeShouldEqual("length", "1");
- }
-
[Test]
[ExpectedException(typeof(InvalidOperationException))]
public void
Map_WithFluentLength_UsesInvalidWithLengthOf_PropertyColumnAttribute()
@@ -198,6 +184,15 @@
}
[Test]
+ public void
Map_WithFluentLength_UsesUnique_PropertyColumnAttribute()
+ {
+ new MappingTester<PropertyTarget>()
+ .ForMapping(m => m.Map(x => x.Name).Unique())
+ .Element("class/property
[@name='Name']").DoesntHaveAttribute("unique")
+ .Element("class/property[@name='Name']/
column").HasAttribute("unique", "true");
+ }
+
+ [Test]
public void
Map_WithFluentLength_UsesUniqueKey_PropertyColumnAttribute()
{
var classMap = new ClassMap<PropertyTarget>();
Index: src/FluentNHibernate/Mapping/PropertyMap.cs
===================================================================
--- src/FluentNHibernate/Mapping/PropertyMap.cs (revision 330)
+++ src/FluentNHibernate/Mapping/PropertyMap.cs (working copy)
@@ -157,7 +157,7 @@
public IProperty WithLengthOf(int length)
{
if (CanApplyLengthAttribute())
- this.AddAlteration(x => x.SetAttribute("length",
length.ToString()));
+ SetAttributeOnColumnElement("length", length.ToString
());
else
throw new InvalidOperationException(String.Format
("{0} is not a string.", this._property.Name));
return this;
@@ -232,7 +232,7 @@
public IProperty Unique()
{
- _extendedProperties.Store("unique", nextBool.ToString
().ToLowerInvariant());
+ SetAttributeOnColumnElement("unique", nextBool.ToString
().ToLowerInvariant());
nextBool = true;
return this;
}
On Feb 19, 5:33 pm, James Gregory <
jagregory....@gmail.com> wrote:
> Thanks for the heads up, I'll fix this asap.
>