简体   繁体   中英

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/ ).

For unit testing, ASP Boilerplate uses Effort ( https://github.com/tamasflamich/effort ) for mocking the database in-memory.

If I run the unit tests without adding the reference to EFProf, the tests run correctly (green).

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:

Castle.MicroKernel.ComponentActivator.ComponentActivatorException

ComponentActivator: could not instantiate 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? 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. It is also the reason why the CommandText is always null when using EF6's Database.Log with Effort.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM