所有人。
我一直在尝试为我的ielasticclient调用编写模拟测试,但是我遇到了一个关于转换的错误。将igetresponse转换为getresponse。
我的elasicclient方法:
public class GetClientByIdQueryHandler : IQueryHandler<GetClientByIdQuery, Client>
{
private readonly IElasticClient _elasticClient;
private readonly IReadModel _readModel;
public GetProposalByIdQueryHandler(IElasticClient elasticClient, IReadModel readModel)
{
...
}
public async Task<Client> ExecuteQueryAsync(GetClientByIdQuery query, CancellationToken cancellationToken)
{
var readModelDescription = _readModel.GetReadModelDescription<ClientReadModel>();
var indexName = readModelDescription.IndexName.Value;
var getResponse = await _elasticClient
.GetAsync<ClientReadModel>(query.Id.Value, d => d.Index(indexName).RequestConfiguration(c => c.AllowedStatusCodes((int)HttpStatusCode.NotFound)), cancellationToken)
.ConfigureAwait(false);
return getResponse.Source;
}
}
我的模拟测试:
private const string _indexName = "client-document";
private ClientReadModel GetClientReadModel()
{
var response = JsonConvert.DeserializeObject<ClientReadModel>("...string json...");
return response;
}
[Fact]
public async Task GetClientByIdQueryHandler()
{
// Arrange
var mockElasticClient = new Mock<IElasticClient>();
var mockResponse = new Mock<IGetResponse<ClientReadModel>>();
mockResponse.SetupGet(r => r.Source).Returns(GetClientReadModel());
mockElasticClient
.Setup(x => x.GetAsync(
"id-d862975d-06ea-4f50-b7d3-d2b19413cb4c",
It.IsAny<Func<GetDescriptor<ClientReadModel>, IGetRequest>>(),
It.IsAny<CancellationToken>()))
.Returns(mockResponse.Object); // <== error here
...
...
}
几乎可以,但它在“returns(mockresponse.object);”行返回一个错误:
无法从“nest.igetresponse”转换为“nest.getresponse”
有人知道如何解决这个问题吗?
谢谢!
暂无答案!
目前还没有任何答案,快来回答吧!