如何将 LinqToSql 与元数据注释集成
我刚刚开始一个新的 MVC 项目,并且像一个好孩子一样,我试图尽可能长时间地推迟使用数据库。 这是独家新闻:
- 我计划使用 ComponentModel.DataAnnotations 装饰。
- 我还计划使用 LinqToSql
是否可以针对 DataAnnotations 元数据类编写单元测试? 我不想尽可能晚地放置这样的模式,但我仍然想编写测试来验证模型。
关于好的方法有什么想法吗? 也许是完全不同的东西?
I'm just getting started on a new MVC project, and like a good boy I am trying to defer going to the DB for as long as possible. Here's the scoop:
- I'm planning on using the ComponentModel.DataAnnotations decorations.
- I'm also planning on using LinqToSql
Is is possible to write a unit test against the DataAnnotations metadata classes? I don't want to put a schema such until as late as possible but I'd still like to write tests to validate the model.
Any ideas on a good approach? Maybe something completely different?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Brad Wilson 写了一篇关于使用 DataAnnotations 及其单元测试的精彩博客文章; http://bradwilson.typepad.com/blog/2009/04/index.html测试
策略的要点是:
基本原理是,您将 System.ComponentModel.DataAnnotations 视为基础设施的一部分,并仅测试您如何使用它。
Brad Wilson wrote a great blog post about using DataAnnotations and unit testing them; http://bradwilson.typepad.com/blog/2009/04/index.html
The gist of the testing strategy is this:
The rationale is that you treat System.ComponentModel.DataAnnotations like a piece of infrastructure and just test how you have utilized it.