C#单元测试 - 生成素DataContexts / LINQ - > SQL类 [英] C# Unit Testing - Generating Mock DataContexts / LINQ -> SQL classes

查看:173
本文介绍了C#单元测试 - 生成素DataContexts / LINQ - > 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.

我的code当前通过DatabaseDataContext对象(* .dbml文件)使用数据库,什么是创建一个模拟此对象的最佳方式?由于它是多么容易生成数据库LINQ - > SQL code和要求有多普遍这一定是我希望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.

如果我的路要走,这必须手动完成,你可以请赐教,以你的preferred办法?

If I'm way off and this must be done manually could you please enlighten me as to your preferred approach?

非常感谢,

加文

推荐答案

与DataContext的问题是,它不是专为嘲讽。

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

一个免费工具,嘲讽unmockable是痣从Pex公司(PEX痣?)。其大致相当于TypeMock

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

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

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