【发布时间】:2011-10-29 20:26:21
【问题描述】:
我们正在使用 EF4 并为 DAL 层创建测试用例(DAL 层有 linq 查询)。我们使用 TypeMock 作为模拟框架。为了测试,我们正在创建ObjectContext 的Fakecontext 并模拟CreateObjectSet 方法,如下所示:
Isolate.WhenCalled(() => fakeContext.Context.CreateObjectSet<User>)).WillReturnCollectionValuesOf(fakeUsers.AsQueryable());
以上工作正常。问题是当我们尝试使用“包含”包含相关表时。我们对 include 方法进行了如下扩展:
public static IQueryable<T> Include<T>(this IQueryable<T> source, Expression<Func<T>> property)
{
var objectQuery = source as ObjectQuery<T>;
if (objectQuery != null)
{
var propertyPath = GetPropertyPath(property);
return objectQuery.Include(propertyPath);
}
return source;
}
所以发生的情况是,在上面的Include 方法中,源类型应该是ObjectQuery<T>。但正如我们已经模拟了CreateObjectSet,Include 方法中的源类型是Collection.Generic.List 类型。请让我们知道在上述情况下我们应该如何模拟。您的及时帮助将不胜感激。谢谢
【问题讨论】:
-
你能正确格式化至少一个问题吗?
标签: entity-framework-4 typemock-isolator