簡體   English   中英

在使用EFProf(Entity Framework Profiler)進行單元測試中使用Effort的ASP Boilerplate問題

[英]ASP Boilerplate problems using Effort in unit testing with EFProf (Entity Framework Profiler)

使用EFProf( http://www.hibernatingrhinos.com/products/EFProf )和ASP Boilerplate( http://www.aspnetboilerplate.com/ )時遇到問題。

對於單元測試,ASP Boilerplate使用Effort( https://github.com/tamasflamich/effort )在內存中模擬數據庫。

如果我運行單元測試時未添加對EFProf的引用,則測試將正確運行(綠色)。

如果添加初始化行:

HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize();

在我的測試庫ctor或應用程序項目的Initialize()中,出現以下錯誤:

Castle.MicroKernel.ComponentActivator.ComponentActivatorException

ComponentActivator:無法實例化MyApp.EntityFramework.MyAppDataContext

內部異常具有相關信息:

Error: Unable to cast object of type 'Effort.Provider.EffortConnection' to type 'HibernatingRhinos.Profiler.Appender.ProfiledDataAccess.ProfiledConnection'.

努力僅僅是與EFProf不兼容嗎? 還是我在初始化過程中做了一些明顯錯誤的事情?

回答我自己的問題:努力會偽造DbContect對象,但實際上並沒有為內存創建SQL,因此沒有探查器可以攔截的內容。 這也是為什么使用EF6的Database.Log時,CommandText始終為null的原因。

我打算嘗試將Moq與EF6結合使用,以使用內存數據庫實現進行測試,以替代Asp Boilerplate的利用本文努力的測試項目: https ://msdn.microsoft.com/zh-cn/library/dn314429 (v = vs.113).aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM