views:

11

answers:

0

I'm using Fluent NHibernate to map a a class that has a collection of strings 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 a 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 test throws NHibernate.MappingException: No persister for: System.String when calling CheckList(). However, if I try to persist the object myself, it works just 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 is the first unit test failing?