Pregunta

I'm failing to grok how to set up a shim for specific generic method. Here's the signature for the actual method:

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

And here's how I'm currently trying (and failing) to configure the shim:

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

The compiler is just giving me a couple "Invalid expression term" errors, so obviously I'm missing something pretty basic here.

edit: here's the shim signature that is generated by 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();
¿Fue útil?

Solución

I can't find any official docs that cover this, but the problem was pretty simple after all. I am used to convention Fakes uses for simple methods, where you just assign a Func to the shimmed method delegate you're interested in, like so:

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

When generics are involved, though, Fakes creates a method that takes a Func as an argument instead of directly exposing the delegate. So what I needed was:

shimTable.ExecuteQueryOf1TableQueryOfM0TableRequestOptionsOperationContext<MyEntity>((query, options, context) =>
{
    return new List<MyEntity>();
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top