[英]Expression<Func<T, bool>> is not working as expected in mock setup
[英]Expression> is not working as expected in mock setup xunit .net6
我尝试使用 xunit 测试此方法。
public async Task<IList<DraftEntity>> Handle(GetDraftsQuery request, CancellationToken cancellationToken)
{
var res = await _repository.GetAllAsync(a => a.CustomerIsin == _user.CustomerIsin);
return res.Data;
}
这是我的测试代码:
public async void GetDraftsQueryTest_when_customerISIN_is_same_draft_is_not_null()
{
//Arange
IList<DraftEntity> ListOutpuddata = new List<DraftEntity>() { new DraftEntity()
{
CustomerIsin=customerisin,
}
};
repo.Setup(i => i.GetAllAsync(i=>i.CustomerIsin==It.IsAny<string>())).Returns(Task.FromResult(OperationResult<IList<DraftEntity>>.Succeed(ListOutpuddata)));
}
但是当我调试代码时,我的方法中的res
变量是 null。为什么?
最终设置
repo.Setup(i => i.GetAllAsync(It.IsAny<Expression<Func<DraftEntity, bool>>>())).Returns(Task.FromResult(OperationResult<IList<DraftEntity>>.Succeed(ListOutpuddata)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.