Skip to content

Commit

Permalink
Implemented support for setting the length attribute of an Element.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbatum authored and jagregory committed Oct 17, 2009
1 parent 573ac3e commit 6f30230
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ public void FormulaIsNotSet()
.ShouldBeFalse();
}

[Test]
public void LengthMapped()
{
mapping.Length = 50;
inspector.Length.ShouldEqual(50);
}

[Test]
public void LengthIsSet()
{
mapping.Length = 50;
inspector.IsSet(Prop(x => x.Length))
.ShouldBeTrue();
}

[Test]
public void LengthIsNotSet()
{
inspector.IsSet(Prop(x => x.Length))
.ShouldBeFalse();
}

#region Helpers

private PropertyInfo Prop(Expression<Func<IElementInspector, object>> propertyExpression)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using FluentNHibernate.Mapping;
using FluentNHibernate.Testing.DomainModel.Mapping;
using FluentNHibernate.MappingModel.Collections;

namespace FluentNHibernate.Testing.FluentInterfaceTests
{
[TestFixture]
public class ElementPartTests
{
[Test]
public void CanSetLength()
{
var part = new ElementPart(typeof(MappedObject));
part.Length(50);

ElementMapping elementMapping = part.GetElementMapping();
elementMapping.Length.ShouldEqual(50);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<Compile Include="ConventionsTests\ForeignKeyConventionTests.cs" />
<Compile Include="ConventionsTests\Inspection\HibernateMappingInspectorMapsToHibernateMapping.cs" />
<Compile Include="ConventionsTests\Inspection\ValueTypes\SchemaActionTests.cs" />
<Compile Include="FluentInterfaceTests\ElementPartTests.cs" />
<Compile Include="FluentInterfaceTests\WhereTests.cs" />
<Compile Include="MappingModel\Output\XmlDiscriminatorWriterTester.cs" />
<Compile Include="ModelTestExtensions.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,14 @@ public void ShouldWriteColumns()
writer.VerifyXml(mapping)
.Element("column").Exists();
}

[Test]
public void ShouldWriteLength()
{
var testHelper = new XmlWriterTestHelper<ElementMapping>();
testHelper.Check(x => x.Length, 50).MapsToAttribute("length");

testHelper.VerifyAll(writer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,10 @@ public string Formula
{
get { return mapping.Formula; }
}

public int Length
{
get { return mapping.Length; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public interface IElementInspector : IInspector
TypeReference Type { get; }
IEnumerable<IColumnInspector> Columns { get; }
string Formula { get; }
int Length { get; }
}
}
6 changes: 6 additions & 0 deletions src/FluentNHibernate/Mapping/ElementPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,11 @@ public ElementMapping GetElementMapping()

return mapping;
}

public ElementPart Length(int length)
{
attributes.Set(x => x.Length, length);
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public string Formula
set { attributes.Set(x => x.Formula, value); }
}

public int Length
{
get { return attributes.Get(x => x.Length); }
set { attributes.Set(x => x.Length, value); }
}

public void AddColumn(ColumnMapping mapping)
{
columns.Add(mapping);
Expand Down
3 changes: 3 additions & 0 deletions src/FluentNHibernate/MappingModel/Output/XmlElementWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public override void ProcessElement(ElementMapping mapping)

if (mapping.HasValue(x => x.Type))
element.WithAtt("type", mapping.Type);

if (mapping.HasValue(x => x.Length))
element.WithAtt("length", mapping.Length);
}

public override void Visit(ColumnMapping columnMapping)
Expand Down

0 comments on commit 6f30230

Please sign in to comment.