C#单元测试 - 生成Mock DataContexts / LINQ - > SQL类 [英] C# Unit Testing - Generating Mock DataContexts / LINQ -> SQL classes
问题描述
我喜欢C#的新世界,我已经开始在我的玩具程序中开始编写一些单元测试。
我的代码当前通过DatabaseDataContext对象(* .dbml文件)使用数据库,为此对象创建模拟的最好方法是什么?考虑到生成数据库LINQ - > SQL代码的容易程度以及请求的通用性,我希望VS2010具有帮助测试的内置功能。</ p>
如果我离开,这必须手动完成,你能告诉我你的首选方法吗?
很感谢,
Gavin
DataContext的问题是它不是为嘲笑而设计的。 / p>
一个用于模拟unmockable的免费工具是来自Pex(Pex mole?)的摩尔数。它大致相当于TypeMock。
I am loving the new world that is C#, I've come to a point with my toy programs where I want to start writing some unit tests.
My code currently uses a database via a DatabaseDataContext object (*.dbml file), what's the best way to create a mock for this object? Given how easy it is to generate the database LINQ -> SQL code and how common a request this must be I'm hoping that VS2010 has built in functionality to help with testing.
If I'm way off and this must be done manually could you please enlighten me as to your preferred approach?
Many Thanks,
Gavin
The problem with the DataContext is that it isn't designed for mocking.
A free tool for mocking the unmockable is Moles from Pex (Pex moles?). Its roughly equivalent to TypeMock.
这篇关于C#单元测试 - 生成Mock DataContexts / LINQ - > SQL类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!