Using Moq with EntityFramework graphdiff

entity-framework graphdiff moq

Question

I recently integrated GraphDiff to an existing Entity Framework solution that uses the Moq testing framework. As a result of method _context.UpdateGraph throwing the following exception, all of my tests that use Moq in insert and update methods are currently failing. System. Object reference not set to an instance of an object: NullReferenceException. GraphDiff https://github.com/refactorthis/GraphDiff on GitHub

Extension method for UpdateGraph: https://github.com/refactorthis/GraphDiff/blob/develop/GraphDiff/GraphDiff/DbContextExtensions.cs

How should Moq and GraphDiff be connected?

1
1
5/15/2015 12:17:56 PM

Accepted Answer

We also experienced similar issue. This was our solution.

In the IContext interface, we see the following:

T UpdateGraph<T>(T entity, Expression<Func<IUpdateConfiguration<T>, object>> mapping = null) where T : class, new();

DbEntityEntry<TEntity> Entry<TEntity>(TEntity entity) where TEntity : class;
        DbEntityEntry Entry(object entity);

        DbContextConfiguration Configuration { get; }

This is the fundamental context:

 public virtual T UpdateGraph<T>(T entity, Expression<Func<IUpdateConfiguration<T>, object>> mapping = null) where T : class, new()
        {
            return null;
        }

and

private ObjectContext ObjectContext
        {
            get { return (this as IObjectContextAdapter).ObjectContext; }
        }

In the actual tangible context, this is what is happening:

public override T UpdateGraph<T>(T entity, Expression<Func<IUpdateConfiguration<T>, object>> mapping = null) // where T : class, new()
        {
            return DbContextExtensions.UpdateGraph<T>(this, entity, mapping);
        }

and

private ObjectContext ObjectContext
        {
            get { return (this as IObjectContextAdapter).ObjectContext; }
        }
1
9/4/2015 8:44:54 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow