I get an exception when I try to unit test an ordered list with fluent nhibernate. The code seems to run ok but my PersistenceSpecification fails!
System.ApplicationException: Expected 'CareerNote.Core.Model.Section' but got 'CareerNote.Core.Model.Section' at position 0
The full code is on github: http://github.com/fodonnel/CareerNote/blob/master/src/CareerNote.Persistence.Tests/Mappings/SectionMapTests.cs
My class:
public partial class Section
{
private Guid _id;
private string _title = "";
private Section _parent;
private IList<Section> _children = new List<Section>();
public virtual Guid Id
{
get { return _id; }
set { _id = value; }
}
public virtual string Title
{
get { return _title; }
set { _title = value + ""; }
}
public virtual Section Parent
{
get { return _parent; }
set { _parent = value; }
}
public virtual IList<Section> Children
{
get { return _children; }
set { _children = value; }
}
}
Its Mapping:
public SectionMap()
{
Id(x => x.Id).Column("SectionId")
.GeneratedBy.Guid().UnsavedValue(Guid.Empty);
Map(x => x.Title).Length(100).Access.CamelCaseField(Prefix.Underscore);
References<Section>(x => x.Parent).Column("SectionParentId")
.Access.CamelCaseField(Prefix.Underscore);
HasMany<Section>(x => x.Children).KeyColumn("SectionParentId").Cascade.All()
.Access.CamelCaseField(Prefix.Underscore)
.AsList(index => index.Column("Position").Type<int?>());
}
The Test:
new PersistenceSpecification<Section>(new SessionProvider().GetSession())
.CheckProperty(c => c.Title, "Title")
.CheckList(c => c.Children, new List<Section> { new Section { Title = "C"} })
.VerifyTheMappings();