简体   繁体   English

在使用EFProf(Entity Framework Profiler)进行单元测试中使用Effort的ASP Boilerplate问题

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

Having issues using EFProf ( http://www.hibernatingrhinos.com/products/EFProf ) with ASP Boilerplate ( http://www.aspnetboilerplate.com/ ). 使用EFProf( http://www.hibernatingrhinos.com/products/EFProf )和ASP Boilerplate( http://www.aspnetboilerplate.com/ )时遇到问题。

For unit testing, ASP Boilerplate uses Effort ( https://github.com/tamasflamich/effort ) for mocking the database in-memory. 对于单元测试,ASP Boilerplate使用Effort( https://github.com/tamasflamich/effort )在内存中模拟数据库。

If I run the unit tests without adding the reference to EFProf, the tests run correctly (green). 如果我运行单元测试时未添加对EFProf的引用,则测试将正确运行(绿色)。

If I add the initialization line: 如果添加初始化行:

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

in either my test base ctor or my application project's Initialize(), I get the following error: 在我的测试库ctor或应用程序项目的Initialize()中,出现以下错误:

Castle.MicroKernel.ComponentActivator.ComponentActivatorException

ComponentActivator: could not instantiate MyApp.EntityFramework.MyAppDataContext ComponentActivator:无法实例化MyApp.EntityFramework.MyAppDataContext

The inner exception has the relevant information: 内部异常具有相关信息:

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

Is Effort just not compatible with EFProf? 努力仅仅是与EFProf不兼容吗? Or am I doing something blindingly obvious wrong in my initialization? 还是我在初始化过程中做了一些明显错误的事情?

Answering my own question: Effort fakes the DbContect object but does not actually create SQL for in-memory, thus there is nothing to intercept by profilers. 回答我自己的问题:努力会伪造DbContect对象,但实际上并没有为内存创建SQL,因此没有探查器可以拦截的内容。 It is also the reason why the CommandText is always null when using EF6's Database.Log with Effort. 这也是为什么使用EF6的Database.Log时,CommandText始终为null的原因。

Am going to try using Moq with EF6 to use an in-memory database implementation for testing as an alternative to Asp Boilerplate's testing project that utilizes Effort per this article: https://msdn.microsoft.com/en-us/library/dn314429(v=vs.113).aspx 我打算尝试将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