Following is what I did to implement HasOne
mapping and unit test. Maps are as followed:
public class PatronMap : ClassMap<Patron>
{
public PatronMap()
{
Id(x => x.ID);
Map(x => x.FirstName);
Map(x => x.LastName);
Map(x => x.Gender);
Map(x => x.Age);
Map(x => x.Address);
Map(x => x.Occupation);
Map(x => x.Telephone1);
Map(x => x.Telephone2);
Map(x => x.AshramRoom);
HasOne(x => x.Member).ForeignKey();
Table("Patrons");
}
}
public class MemberMap : ClassMap<Member>
{
public MemberMap()
{
Id(x => x.ID);
Map(x => x.IsRegistered);
Map(x => x.Reference1);
Map(x => x.Reference2);
References(x => x.Patron)
.Column("PatronID")
.Unique()
.UniqueKey("IDX_UniquePatronID");
Table("Members");
}
}
Unit test is as thus:
public void MemberMap_Create_Success()
{
new PersistenceSpecification<Member>( Database.Session, new CustomEqualityComparer() )
.CheckProperty(x => x.ID, "1")
.CheckReference(x => x.Patron, new Patron()
{
ID = "2",
FirstName = "Abc",
LastName = "Xyz",
Gender = "M",
Age = 99,
Address = "Address",
Telephone1 = 0000000001,
Telephone2 = 1000000000,
Occupation = "Occupation",
AshramRoom = "Room"
})
.CheckProperty(x => x.Reference1, "Ref1")
.CheckProperty(x => x.Reference2, "Ref2")
.CheckProperty(x => x.IsRegistered, true)
.VerifyTheMappings();
}
Hope this helps someone. :-)