我正在为以下代码编写一些单元测试:
public async Task<dynamic> GetResults([FromBody] MultiSelectQueryResultRequest request)
{
var results = await _multiSelectRepository.GetResults(request);
var items = new List<ExpandoObject>();
foreach (var result in results)
{
var expando = new ExpandoObject();
foreach (var column in request.columns.Split(','))
{
AddProperty(expando, column, result.GetType().GetProperty(column).GetValue(result));
}
items.Add(expando);
}
return new { Items = items };
}
回到我的测试中,我有这个:
[Fact]
public async Task GetResults_ReturnsResults()
{
var request = new MultiSelectQueryResultRequest { project_block = "SM2 BLK 3B", APBU_nalc = "cwex", columns = "msl_key,FZBSTR_nalc,SAD_pn" };
var response = await _controller.GetResults(request);
Assert.Equal(105, response.Items.Count);
}
以下消息失败:
消息:Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: “对象”不包含“项目”的定义
调试时,我绝对可以看到Items在响应中,并且其中包含105个元素。在我看来,它应该过去了,显然不是。为什么?