gpt4 book ai didi

c# - 使用流畅的 nhibernate 映射进行持久性规范测试

转载 作者:行者123 更新时间:2023-11-30 14:01:44 25 4
gpt4 key购买 nike

我最近一直在研究 fluent nhibernate 和更具体的持久性规范测试。

但是,在为这一行的测试构建架构时,我在使用 nunit 运行相对简单的测试时一直遇到 sql lite 错误:(SessionSource.BuildSchema(Session))。

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

寻求一些关于我做错了什么的指导,因为我是流利的新手。是否有更简单的方法来解决此错误消息?

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, "mail@test.com")
.CheckReference(c => c.Notes, new Note { Title = "Title", Description = "Description" })
.VerifyTheMappings();

最佳答案

您应该在 PersistanceSpecification 类中使用 CheckList 而不是上面代码中的 CheckReference

关于c# - 使用流畅的 nhibernate 映射进行持久性规范测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7797829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com