Microsoft 用于通用方法的假货垫片



我无法了解如何为特定的通用方法设置垫片。下面是实际方法的签名:

public IEnumerable<TElement> ExecuteQuery<TElement>(TableQuery<TElement> query, TableRequestOptions requestOptions = null, OperationContext operationContext = null) where TElement : ITableEntity, new();

以下是我目前尝试(并失败)配置填充程序的方式:

ShimCloudTable shimTable = new ShimCloudTable();
shimTable.ExecuteQueryOf1TableQueryOfM0TableRequestOptionsOperationContext<MyEntity> = (query, options, context) => {
    return new List<MyEntity>();
};

编译器只是给了我几个"无效的表达式术语"错误,所以显然我在这里错过了一些非常基本的东西。

编辑:这是MS Fakes生成的填充码签名:

public void ExecuteQueryOf1TableQueryOfM0TableRequestOptionsOperationContext<TElement>(FakesDelegates.Func<TableQuery<TElement>, TableRequestOptions, Microsoft.WindowsAzure.Storage.OperationContext, System.Collections.Generic.IEnumerable<TElement>> shim) where TElement : ITableEntity, new();

我找不到任何涵盖此内容的官方文档,但问题毕竟很简单。我习惯于将 Fakes 用于简单方法,您只需将 Func 分配给您感兴趣的填充方法委托,如下所示:

shimAccount.CreateCloudTableClient = () => { return shimTableClient; };

但是,当涉及泛型时,Fakes 会创建一个将 Func 作为参数而不是直接公开委托的方法。所以我需要的是:

shimTable.ExecuteQueryOf1TableQueryOfM0TableRequestOptionsOperationContext<MyEntity>((query, options, context) =>
{
    return new List<MyEntity>();
});

最新更新