Fluent NHibernate PersistenceSpecification cannot test rowset

I use Fluent NHibernate to map a class that has a set of lines like this:

public class Foo { public virtual ICollection<string> Strings { get; set; } } public class FooMap : ClassMap<Foo> { public FooMap() { HasMany(f => f.Strings).Element("SomeColumnName"); } } 

When I write unit test using the PersistenceSpecification class included in the FNH package, it fails:

 [TestMethod] public void CanMapCollectionOfStrings() { var someStrings = new List<string> { "Foo", "Bar", "Baz" }; new PersistenceSpecification<Foo>(CurrentSession) .CheckList(x => x.Strings, someStrings) // MappingException .VerifyTheMappings(); } 

This call throws NHibernate.MappingException: No persister for: System.String when calling CheckList() . However, if I try to save the object myself, it works fine.

 [TestMethod] public void CanPersistCollectionOfStrings() { var foo = new Foo { Strings = new List<string> { "Foo", "Bar", "Baz" }; }; CurrentSession.Save(foo); CurrentSession.Flush(); var savedFoo = CurrentSession.Linq<Foo>.First(); Assert.AreEqual(3, savedFoo.Strings.Count()); // Test passes } 

Why does the first unit test not work?

+6
unit-testing nhibernate fluent-nhibernate
source share
1 answer

The CheckComponentList method is probably the right way in this case:

 var someStrings = new List<string> { "Foo", "Bar", "Baz" }; new PersistenceSpecification<Foo>(CurrentSession) .CheckComponentList(x => x.Strings, someStrings) .VerifyTheMappings(); 

This code works well for me (NH 3.1, FNH 1.2). I hope for this help.

+3
source share

All Articles