我有一个单元测试,它使用 Microsoft Fakes 将以下接口(interface) stub :
public interface ITable
{
Task<TableResult> Retrieve(string tableReference, string partitionKey, string rowKey);
}
stub 看起来像这样:
ITable table = new MessagesAPI.Azure.Fakes.StubITable()
{
RetrieveStringStringString = delegate
{
TableResult tableResult = new TableResult();
return Task.FromResult(tableResult);
}
};
这工作正常。但是我想将界面更改为更通用,如下所示:
public interface ITable
{
Task<TableResult> Retrieve<T>(string tableReference, string partitionKey, string rowKey)
where T : ITableEntity;
}
问题是我将如何 stub 这个新版本的界面?我无法正确使用语法。
有任何想法吗?
最佳答案
您将行为设置如下:
var table = new MessagesAPI.Azure.Fakes.StubITable();
table.RetrieveOf1StringStringString<ITableEntity>(
(tableReference, partitionKey, rowKey) =>
{
TableResult tableResult = new TableResult();
return Task.FromResult(tableResult);
});
关于unit-testing - 如何在 C# 中使用 Microsoft Fakes 在接口(interface)中 stub 通用方法定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32307972/