Unit testing dynamic queries in Entity Framework 4?

Don't know what you mean by "correct" it depends on your situation, but the general answer is that you will need some abstractions that can be replaced during test. For some inspiration, here is what we use (we use self tracking poco entities) summary> /// Object context interface for abstracting the service layer from the /// implementation details of object storage. /// public interface IObjectContext : IDisposable { /// /// Returns the entity objects of the given type known by this object context.

/// /// The type of the entity. /// The instances of the given type already loaded into this object context IEnumerable GetManagedEntities() where TEntity : EntityBase; /// /// Creates an object set for the provided entity type. /// /// The type of the entity.

/// IObjectSet CreateObjectSet() where TEntity : EntityBase; /// /// Applies the changes made to the provided entity object graph to this object context. /// /// The type of entity (inferred). /// The entity object graph that has been modified.

Void ApplyChanges(TEntity entity) where TEntity : EntityBase, IObjectWithChangeTracker; /// /// Saves the changes known by this object context instance to the database. /// void Save(); /// /// Creates a new logical unit of work spanning a single business transaction. /// IUnitOfWork CreateUnitOfWork(); /// /// Creates a new logical unit of work spanning a single business transaction.

/// /// The transaction isolation level used by the /// unit of work ambient transaction. /// IUnitOfWork CreateUnitOfWork(IsolationLevel isolationLevel); } and for abstracting transactions summary> /// Interface abstraction for a unit of work, aka all persistent work spanning a single /// business transaction and to be performed in unity. /// /// Used to support outer and inner units of work where one outer UoW may consist /// of multiple nested inner UoW instances and have all of them share a transaction.

Public interface IUnitOfWork : IDisposable { /// /// Gets the transaction isolation level used by the unit of work ambient transaction. /// /// The isolation level. IsolationLevel IsolationLevel { get; } /// /// Gets the transaction timeout time span used by the unit of work ambient transaction.

/// /// The transaction timeout duration. TimeSpan TransactionTimeout { get; } /// /// Completes the unit of work that this instance represents. /// /// /// For an outer unit of work, will persist all changes represented by this business /// transaction and will then signal the ambient transaction in use as complete.

/// For an inner unit of work, will signal itself as completed to the outer unit of /// work that it is part of. /// void Complete(); } then modify the object context generation code to support these interfaces + implement your UoW according to your needs (our implementation omitted for brevity). HTH.

Don't know what you mean by "correct" it depends on your situation, but the general answer is that you will need some abstractions that can be replaced during test. For some inspiration, here is what we use (we use self tracking poco entities) /// /// Object context interface for abstracting the service layer from the /// implementation details of object storage. /// public interface IObjectContext : IDisposable { /// /// Returns the entity objects of the given type known by this object context.

/// /// The type of the entity. /// The instances of the given type already loaded into this object context IEnumerable GetManagedEntities() where TEntity : EntityBase; /// /// Creates an object set for the provided entity type. /// /// The type of the entity.

/// IObjectSet CreateObjectSet() where TEntity : EntityBase; /// /// Applies the changes made to the provided entity object graph to this object context. /// /// The type of entity (inferred). /// The entity object graph that has been modified.

Void ApplyChanges(TEntity entity) where TEntity : EntityBase, IObjectWithChangeTracker; /// /// Saves the changes known by this object context instance to the database. /// void Save(); /// /// Creates a new logical unit of work spanning a single business transaction. /// IUnitOfWork CreateUnitOfWork(); /// /// Creates a new logical unit of work spanning a single business transaction.

/// /// The transaction isolation level used by the /// unit of work ambient transaction. /// IUnitOfWork CreateUnitOfWork(IsolationLevel isolationLevel); } and for abstracting transactions /// /// Interface abstraction for a unit of work, aka all persistent work spanning a single /// business transaction and to be performed in unity. /// /// Used to support outer and inner units of work where one outer UoW may consist /// of multiple nested inner UoW instances and have all of them share a transaction.

Public interface IUnitOfWork : IDisposable { /// /// Gets the transaction isolation level used by the unit of work ambient transaction. /// /// The isolation level. IsolationLevel IsolationLevel { get; } /// /// Gets the transaction timeout time span used by the unit of work ambient transaction.

/// /// The transaction timeout duration. TimeSpan TransactionTimeout { get; } /// /// Completes the unit of work that this instance represents. /// /// /// For an outer unit of work, will persist all changes represented by this business /// transaction and will then signal the ambient transaction in use as complete.

/// For an inner unit of work, will signal itself as completed to the outer unit of /// work that it is part of. /// void Complete(); } then modify the object context generation code to support these interfaces + implement your UoW according to your needs (our implementation omitted for brevity). HTH.

Returns the entity objects of the given type known by this object context. /// The type of the entity. /// Creates an object set for the provided entity type.

/// The type of the entity. /// Applies the changes made to the provided entity object graph to this object context. /// The type of entity (inferred).

/// The entity object graph that has been modified. /// Saves the changes known by this object context instance to the database. /// Creates a new logical unit of work spanning a single business transaction.

/// Creates a new logical unit of work spanning a single business transaction. /// unit of work ambient transaction. /// business transaction and to be performed in unity.

/// of multiple nested inner UoW instances and have all of them share a transaction. /// Gets the transaction isolation level used by the unit of work ambient transaction. /// The isolation level.

/// Gets the transaction timeout time span used by the unit of work ambient transaction. /// The transaction timeout duration. /// Completes the unit of work that this instance represents.

/// transaction and will then signal the ambient transaction in use as complete. /// work that it is part of.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions