简体   繁体   English

Expression> 在模拟设置 xunit .net6 中未按预期工作

[英]Expression> is not working as expected in mock setup xunit .net6

I try to test this method using xunit.我尝试使用 xunit 测试此方法。

public async Task<IList<DraftEntity>> Handle(GetDraftsQuery request, CancellationToken cancellationToken)
{
    var res = await _repository.GetAllAsync(a => a.CustomerIsin == _user.CustomerIsin);
    return res.Data;
}

Here is my test code:这是我的测试代码:

  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)));

     }

But when I debug the code the res variable in my method is null.Why?但是当我调试代码时,我的方法中的res变量是 null。为什么?

Final setup最终设置

  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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM