1

我刚刚在使用 Moq 框架进行测试的现有实体框架解决方案中添加了 GraphDiff。我在插入和更新方法中使用 Moq 的所有测试现在都失败了,因为方法_context.UpdateGraph引发以下异常:System.NullReferenceException:对象引用未设置为对象的实例。GitHub 上的 GraphDiff https://github.com/refactorthis/GraphDiff

UpdateGraph 扩展方法: https ://github.com/refactorthis/GraphDiff/blob/develop/GraphDiff/GraphDiff/DbContextExtensions.cs

您应该如何将起订量与 GraphDiff 连接起来?

4

1 回答 1

1

我们也遇到了这个问题。这就是我们解决它的方法。

所以这是在 IContext 接口中:

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; }

这是在基本上下文中:

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

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

这是在实际的具体情况下:

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);
        }

private ObjectContext ObjectContext
        {
            get { return (this as IObjectContextAdapter).ObjectContext; }
        }
于 2015-09-04T20:44:54.367 回答