模拟实体框架上下文 [英] Mocking Entity Framework Context

查看:133
本文介绍了模拟实体框架上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用实体框架访问我​​的数据库,我想在我的单元测试中模拟数据库环境,以便我可以测试我的中间层类,而不依赖于实际数据。我知道我不是第一个要求这个(模拟实体框架模型) a>,但是经过一些谷歌搜索之后,我有一种本能,可以根据模型的元数据实例化上下文。



有没有人能做到这一点?

解决方案

你可以只用元数据来做,有一篇很好的文章,单元测试一般来说, =http://blogs.msdn.com/diego/archive/2008/03/03/unit-testing-your-entity-framework-domain-classes.aspx =noreferrer> here


I'm using the entity framework to access my database and I want to mock the database context inside my unit tests so that I can test my middle tier classes free of their dependency on real data. I know that I'm not the first to ask about this (Mocking an Entity Framework Model), but after some googling I have an instinct that it might be possible to instantiate the context based on the model's metadata alone.

Has anyone been able to do this?

解决方案

You can do it with just metadata, there's a good article on it, and unit testing EF in general, here.

这篇关于模拟实体框架上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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