简体   繁体   English

Simple.Data和单元测试业务层

[英]Simple.Data and unit testing the business layer

I'm thinking of using the Simple.Data package ( https://github.com/markrendle/Simple.Data ) and thought of an interesting issue in terms of implementation. 我正在考虑使用Simple.Data包( https://github.com/markrendle/Simple.Data ),并在实现方面想到了一个有趣的问题。

Simple.Data appears to be designed abstract away a lot of the need to implement your own data layer through providing a dynamic object, so you could do something like: Simple.Data似乎是通过提供动态对象来抽象设计的,它消除了实现自己的数据层的大量需求,因此您可以执行以下操作:

var user = Database.Open().Users.FindById(id);

....which is great. ....那太好了。 However I usually develop something like a generic repository with an interface to allow me to stub the data layer in unit tests and remain flexible for swapping my data layer out in future. 但是,我通常会开发带有接口的通用存储库之类的东西,以使我能够在单元测试中对数据层进行存根,并在以后交换数据层时保持灵活性。

If anyone has used Simple.Data - what are your thoughts on using a repository pattern with it? 如果有人使用过Simple.Data-您对使用存储库模式有何想法? Is it unnecessary? 没必要吗? Have you had any experience replacing the dependency upon the Database object when unit testing with Simple.Data? 使用Simple.Data进行单元测试时,您是否有过替换数据库对象依赖项的经验?

Any feedback would be appreciated! 对于任何反馈,我们都表示感谢!

ps I'm not talking about unit testing data retrieval itself using Simple.Data as covered here - http://simplefx.org/simpledata/docs/pages/Test/Basics.htm - more about replacing the dependency on simple data when unit testing my business layer for example, something a repository pattern could help achieve PS我不是在谈论使用Simple.Data单元测试数据检索本身作为这里介绍- http://simplefx.org/simpledata/docs/pages/Test/Basics.htm -更多有关更换简单的数据时,单位的依赖例如,测试我的业务层,某种存储库模式可以帮助实现

You might find this blog post I wrote about using Impromptu-Interface with Simple.Data helps your decision. 您可能会发现我写的有关将Impromptu-Interface与Simple.Data结合使用的博客文章,可以帮助您做出决定。 Effectively, you can declare the interfaces for your repository layer and Simple.Data will implement them automagically. 有效地,您可以声明存储库层的接口,Simple.Data将自动实现它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM