开发者

ADO.Net Mocking Context Generator Interface Problem

I'm working with EF 4 and a repository pattern. In my adventures in trying to unit test my EF data context, I came across the ADO.Net Mocking Context Generator template, which as the name describes, aids in mocking the data context.

While my context does build fine, I'm having problems with my repository and it's a bit of a mystery. Here is my repository interface (abbreviated):

 public interface IRepository<T> where T : class
{
    /// <summary>
    /// Finds all entities
    /// </summary>
    /// <returns></returns>
    IQueryable<T> Find();

    /// <summary>
    /// Find alls entities and loads included relational properties.
    /// </summary>
    /// <param name="includes">Relational properties to load.</param>
    /// <returns></returns>
    IQueryable<T> Find(params Expression<Func<T, object>>[] includes);

    /// <summary>
    /// Adds an entity to the repository.
    /// </summary>
    /// <param name="entity">Entity to add.</param>
    void Add(T entity);

    /// <summary>
    /// Updates an entity in the repository.
    /// <开发者_开发问答;/summary>
    /// <param name="entity">Entity to update.</param>
    void Update(T entity)...etc

With the mock context, you get a new set of generated entities with virtual properties. I have given those entities the same namespace as my real entities for the purpose of mocking them and they are identical types as my real ones with only a reference to the mock entities.

The problem is when I have an implementation of my repository interface I get interface not implemented exceptions, even though I am in fact implementing the interface. This only occurs when I try to build the project. Intellisense thinks everything is fine (ie, no litte arrow under the interface telling me I need to implement it).

Below is an implementation of the interface via my ICategoryLocalized interface (it inherits from IRepository).

public class CategoryLocalizedRepository : MockDatabaseRepository, ICategoryLocalizedRepository
{
    #region Constructor

    public CategoryLocalizedRepository(MockContext context)
        : base(context)
    {
    }

    #endregion

    #region Data Methods

    public IQueryable<CategoryLocalized> Find()
    {
        return Context.CategoryLocalized;
    }

    public IQueryable<CategoryLocalized> Find(params Expression<Func<CategoryLocalized, object>>[] includes)
    {
        return CreateObjectQuery<CategoryLocalized>(Context.CategoryLocalized, includes);
    }

    public CategoryLocalized Get(int id)
    {
        return Context.CategoryLocalized.SingleOrDefault(d => d.CategoryLocalizedID == id);
    }

    public CategoryLocalized Get(int id, params Expression<Func<CategoryLocalized, object>>[] includes)
    {
        IObjectSet<CategoryLocalized> query = CreateObjectQuery<CategoryLocalized>(Context.CategoryLocalized, includes);
        return query.SingleOrDefault(d => d.CategoryLocalizedID == id);
    }

    public void Add(CategoryLocalized categoryLocal)
    {
        AddEntity<CategoryLocalized>(Context.CategoryLocalized, categoryLocal);
    }

    public void Update(CategoryLocalized categoryLocal)
    {
        UpdateEntity<CategoryLocalized>(Context.CategoryLocalized, categoryLocal);
    }...etc

I don't know why the compiler is saying that the interface (IRepository) is not implemented in CategoryLocalizedRepository when it clearly is.


Turns out I had a reference to another set of entities in my repository and a reference to a different set in my mock data project.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜