如何关闭或“取消初始化”城堡活动记录?

发布于 2024-08-15 14:01:54 字数 208 浏览 3 评论 0原文

我正在使用 Castle ActiveRecord 运行一些与数据库交互的单元测试。在每次测试中与数据库交互之前,我有一个过程可以删除数据库(如果存在),然后重新创建它。

如果我运行一个测试,效果很好。

如果我运行多个测试,第二个测试就会失败,因为它无法删除数据库。

Castle ActiveRecord 中是否有某种方法可以告诉它关闭并释放数据库?

I'm running some unit tests using Castle ActiveRecord that interact with a database. I have a procedure to drop the database (if it exists), then re-create it, before I interact with it in each test.

If I run one test, this works fine.

If I run multiple tests, the second one fails because it can't drop the database.

Is there some way in Castle ActiveRecord to tell it to shut down and let go of the database?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦回梦里 2024-08-22 14:01:54

我建议删除并重新创建架构,而不是删除整个数据库

删除架构:ActiveRecordStarter.DropSchema();

创建架构:ActiveRecordStarter.CreateSchema();

重新初始化 ActiveRecord:ActiveRecordStarter.ResetInitializationFlag();< /code> 然后重新配置它。

请参阅 基础 AR 测试类 寻求指导。

为了进行测试,我建议查看新的 内存测试

另请参阅:ActiveRecord 单元测试文档

Instead of dropping the whole database, I recommend dropping and recreating the schema.

To drop the schema: ActiveRecordStarter.DropSchema();

To create the schema: ActiveRecordStarter.CreateSchema();

To reinitialize ActiveRecord: ActiveRecordStarter.ResetInitializationFlag(); then reconfigure it.

See the base AR test class for guidance.

For testing, I recommend taking a look at the new InMemoryTest.

See also: docs for ActiveRecord unit-testing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文