0

我正在尋找一個實用程序類來在運行時生成假實體實例。 我正在實施一個ASP.NET MVC3網站使用EF4與代碼第一的方法,所以我想在創建任何數據庫之前運行該網站。假實例應包含有效數據(希望能夠反映每個類定義中使用的各種DataAnnotation屬性)。在運行時生成假實例

回答

0

您是否正在尋找一個框架如FakeItEasy

說明從網站採取:

A .Net dynamic fake framework for creating 
all types of fake objects, mocks, stubs etc. 

    * Easier semantics, all fake objects are 
    just that - fakes - the use of the fakes 
    determines whether they're mocks or stubs. 
    * Context aware fluent interface guides the developer. 
    * Full VB.Net support. 

Designed for ease of use and for compatibility with both C# and VB.Net. 
0

開始的地方是看的「種子數據」的例子在這個帖子:http://blogs.msdn.com/b/adonet/archive/2010/09/02/ef-feature-ctp4-dbcontext-and-databases.aspx

這將允許您編寫必要的程序來填充測試數據

+0

謝謝Clicktricity,這是一個很好的職位,但我正在尋找一個內存假 – hemme 2010-09-28 13:08:28

+0

沒問題。在這種情況下,您需要爲每個實體創建一個虛假的數據上下文並實現IDbSet。這裏有一個很好的例子:http://romiller.com/2010/09/07/ef-ctp4-tips-tricks-testing-with-fake-dbcontext/ – Clicktricity 2010-09-28 13:48:50

0

我們使用控制檯應用程序中我們生成我們需要測試的任何項目都是開始安裝。