使用 Mock 在方法调用中引发作为参数传递的回调
Raising a Callback passed as a parameter in a method call using Mock
我有一个将回调作为参数的方法:
public void GetAllAvailableNames(Action<List<string>> callback, Exchange? exchange = null, string symbol = null)
{
callback.Invoke(new List<string> {"test"});
}
如何使用 mock 引发回调,这是我尝试过的方法:
this._marketDataClientMock
.Setup(x => x.GetAllAvailableNames( It.IsAny<Action<List<string>>>(), It.IsAny<Exchange>(), It.IsAny<string>()))
.Callback((List<string> x) => x = this.Vets);
捕获 CallBack
中的操作参数并手动调用它
this._marketDataClientMock
.Setup(x => x.GetAllAvailableNames( It.IsAny<Action<List<string>>>(), It.IsAny<Exchange>(), It.IsAny<string>()))
.Callback((Action<List<string>> callback, Exchange? exchange, string symbol) => callback.Invoke(this.Vets));
我有一个将回调作为参数的方法:
public void GetAllAvailableNames(Action<List<string>> callback, Exchange? exchange = null, string symbol = null)
{
callback.Invoke(new List<string> {"test"});
}
如何使用 mock 引发回调,这是我尝试过的方法:
this._marketDataClientMock
.Setup(x => x.GetAllAvailableNames( It.IsAny<Action<List<string>>>(), It.IsAny<Exchange>(), It.IsAny<string>()))
.Callback((List<string> x) => x = this.Vets);
捕获 CallBack
中的操作参数并手动调用它
this._marketDataClientMock
.Setup(x => x.GetAllAvailableNames( It.IsAny<Action<List<string>>>(), It.IsAny<Exchange>(), It.IsAny<string>()))
.Callback((Action<List<string>> callback, Exchange? exchange, string symbol) => callback.Invoke(this.Vets));