[英]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.