Unit testing dynamic queries in Entity Framework 4 -


when implementing unit of work pattern entity framework 4.0, correct design give ability create dynamic queries createquery method of object context? , correct mean designing somehow can use in unit test mock objects.

thanks.

don't know mean "correct" depends on situation, general answer need abstractions can replaced during test. inspiration, here use (we use self tracking poco entities)

/// <summary> /// object context interface abstracting service layer /// implementation details of object storage. /// </summary> public interface iobjectcontext : idisposable {     /// <summary>     /// returns entity objects of given type known object context.     /// </summary>     /// <typeparam name="tentity">the type of entity.</typeparam>     /// <returns>the instances of given type loaded object context</returns>     ienumerable<tentity> getmanagedentities<tentity>() tentity : entitybase;      /// <summary>     /// creates object set provided entity type.     /// </summary>     /// <typeparam name="tentity">the type of entity.</typeparam>     /// <returns></returns>     iobjectset<tentity> createobjectset<tentity>() tentity : entitybase;      /// <summary>     /// applies changes made provided entity object graph object context.     /// </summary>     /// <typeparam name="tentity">the type of entity (inferred).</typeparam>     /// <param name="entity">the entity object graph has been modified.</param>     void applychanges<tentity>(tentity entity) tentity : entitybase, iobjectwithchangetracker;      /// <summary>     /// saves changes known object context instance database.     /// </summary>     void save();      /// <summary>     /// creates new logical unit of work spanning single business transaction.     /// </summary>     iunitofwork createunitofwork();      /// <summary>     /// creates new logical unit of work spanning single business transaction.     /// </summary>     /// <param name="isolationlevel">the transaction isolation level used     /// unit of work ambient transaction.</param>     /// <returns></returns>     iunitofwork createunitofwork(isolationlevel isolationlevel); } 

and abstracting transactions

/// <summary> /// interface abstraction unit of work, aka persistent work spanning single /// business transaction , performed in unity. /// </summary> /// <remarks>used support outer , inner units of work 1 outer uow may consist /// of multiple nested inner uow instances , have of them share transaction.</remarks> public interface iunitofwork : idisposable {     /// <summary>     /// gets transaction isolation level used unit of work ambient transaction.     /// </summary>     /// <value>the isolation level.</value>     isolationlevel isolationlevel { get; }      /// <summary>     /// gets transaction timeout time span used unit of work ambient transaction.     /// </summary>     /// <value>the transaction timeout duration.</value>     timespan transactiontimeout { get; }      /// <summary>     /// completes unit of work instance represents.     /// </summary>     /// <remarks>     /// outer unit of work, persist changes represented business     /// transaction , signal ambient transaction in use complete.     /// inner unit of work, signal completed outer unit of     /// work part of.     /// </remarks>     void complete(); } 

then modify object context generation code support these interfaces + implement uow according needs (our implementation omitted brevity). hth


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -