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)
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());
Why does the first unit test not work?
unit-testing nhibernate fluent-nhibernate
Brant bobby
source share