Would be possible to use generics with MethodDataSource ? #5031
Unanswered
rodrigovaras
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
Do your objects share a base type or interface? I'm thinking something like: public class RpcContextTest
{
[Test]
[MethodDataSource(nameof(GetContext))]
public async Task TestContext(Context context)
{
await TestInternal(context, false);
}
public static IEnumerable<Func<Context>> GetContext()
{
yield return () =>
{
var jsonRpcContext = new JsonRpcContext();
jsonRpcContext.AddJsonNodeTypes();
return jsonRpcContext;
};
yield return () =>
{
var protoRpcContext = new ProtoRpcContext();
protoRpcContext.AddProtoNodeTypes();
return protoRpcContext;
};
}
private async Task TestInternal<TPayload>(IRpcContextPayloadConverter<TPayload> rpcContext, bool typeMatch)
{
...
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This is the scenario I would like to refactor.
public class RpcContextTest
{
[Test]
public async Task TestJsonContext()
{
var jsonRpcContext = new JsonRpcContext();
jsonRpcContext.AddJsonNodeTypes();
await TestInternal(jsonRpcContext, false);
}
...
}
}
Beta Was this translation helpful? Give feedback.
All reactions