C#单元测试-生成模拟数据上下文/LINQ-& gt;SQL类 [英] C# Unit Testing - Generating Mock DataContexts / LINQ -> SQL classes

查看:45
本文介绍了C#单元测试-生成模拟数据上下文/LINQ-& gt;SQL类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我热爱C#这个新世界,我的玩具程序已经到了要开始编写一些单元测试的地步.

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.

我的代码当前通过DatabaseDataContext对象(* .dbml文件)使用数据库,为此对象创建模拟的最佳方法是什么?鉴于生成数据库LINQ-> SQL代码非常容易,并且必须很常见,我希望VS2010具有内置功能来帮助测试.

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?

非常感谢,

Gavin

推荐答案

DataContext的问题在于它不是为模拟而设计的.

The problem with the DataContext is that it isn't designed for mocking.

来自Pex的痣(Pex痣?).它大致相当于TypeMock.

A free tool for mocking the unmockable is Moles from Pex (Pex moles?). Its roughly equivalent to TypeMock.

这篇关于C#单元测试-生成模拟数据上下文/LINQ-& gt;SQL类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆