2011-10-17 84 views
3

我最近一直在玩弄流利的nhibernate &更具體的持久性規範測試。用流暢的nhibernate映射進行持久性規範測試

但是,當我在運行一個相對簡單的nunit測試時,在構建這一行上的測試模式時,我一直遇到sql lite錯誤:(SessionSource.BuildSchema(Session))。

System.Data.SQLite.SQLiteException:SQLite的錯誤附近「/」:語法錯誤

什麼我做錯了,我是比較新的流利尋求一些一些指導。有沒有更簡單的方法來解決這個錯誤信息?

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(); 
} 

配置:

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; 
} 

最後的持久性測試:

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(); 

回答

7

你應該在PersistanceSpecification類,而不是CheckReference在上面的代碼中使用CheckList

+0

謝謝科爾,請牢記這一點。但是,我的問題是,在此行上執行操作測試之前,模式生成似乎因爲某種原因而失敗:SessionSource.BuildSchema(Session) – Jesse

1

嗯,我覺得有點傻。我從最初的帖子中排除的其中一列是DateTime字段,該字段有一個不正確的默認值集,在構建模式時,該字段又會產生無效的sql。

構建模式時輸出表的配置突出顯示了我的錯誤。

相關問題