Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistence specification testing with fluent nhibernate mappings

I've recently been playing around with fluent nhibernate & more specifically persistence specification testing.

However, I keep running into a sql lite error while running a relatively simple test with nunit when building the schema for the test on this line: (SessionSource.BuildSchema(Session)).

System.Data.SQLite.SQLiteException : SQLite error near "/": syntax error

Seeking some some guidance on what I am doing wrong as I'm relatively new to fluent. Is there an easier way to troubleshoot this error message?

public class Contact
{
    public int Id { get; protected set; }
    // some other properties 
    public IList<Note> Notes { get; set; }
}

public ContactMapping()
{
    Not.LazyLoad();
    Id(m => m.Id).GeneratedBy.Identity();
    HasMany(x => x.Notes).KeyColumns.Add("ContactId");
}

public class Note
{
    public int Id { get; protected set; }
    public Contact Contact { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
}

public NoteMapping()
{
    Not.LazyLoad();
    Id(m => m.Id).GeneratedBy.Identity();
    Map(m => m.Title).Not.Nullable().Length(250);
    Map(m => m.Description).Not.Nullable().Length(2500);
    References(x => x.Contact).Column("ContactId").Cascade.All();
}

Config:

public void SetupContext()
{
    var cfg = Fluently.Configure()
        .Database(SQLiteConfiguration.Standard
            .ShowSql()
            .InMemory
            );
    SessionSource = new SessionSource(cfg.BuildConfiguration()
                                            .Properties, PersistenceModel());
    Session = SessionSource.CreateSession();
    SessionSource.BuildSchema(Session);
}

private static PersistenceModel PersistenceModel()
{
    var model = new PersistenceModel();
    model.AddMappingsFromAssembly(typeof(Contact).Assembly);
    return model;
}

And finally the persistence test:

new PersistenceSpecification<Contact>(Session)
    .CheckProperty(c => c.Id, 1)
    .CheckProperty(c => c.First, "Coding")
    .CheckProperty(c => c.Last, "Quiz")
    .CheckProperty(c => c.Email, "[email protected]")
    .CheckReference(c => c.Notes, new Note { Title = "Title", Description = "Description" })
    .VerifyTheMappings();
like image 975
Jesse Avatar asked Sep 02 '25 13:09

Jesse


1 Answers

You should be using CheckList in the PersistanceSpecification class instead of CheckReference in the above code.

like image 198
Cole W Avatar answered Sep 05 '25 10:09

Cole W