C# Assert.That()不计算给定的约束

C# Assert.That()不计算给定的约束,c#,nunit,nunit-3.0,C#,Nunit,Nunit 3.0,我有一个字符串值列表。我用foreach迭代这个列表。我应用于每个列表项Assert.That()方法。现在是一个转折点:我给出了一个返回IResolveConstraint的函数作为方法的第二个参数。当函数返回时,Has.justice(1).Contains(),然后在列表的第二个项(foreach的第二次迭代)断言计算(抛出)此消息:“预期:包含“value”的集合”。但是断言应该通过,因为它只验证一个项目,而不是一个集合 我有NUnit 3.2.1。我升级到3.12.0版,之后消息从:“

我有一个字符串值列表。我用foreach迭代这个列表。我应用于每个列表项Assert.That()方法。现在是一个转折点:我给出了一个返回IResolveConstraint的函数作为方法的第二个参数。当函数返回时,Has.justice(1).Contains()然后在列表的第二个项(foreach的第二次迭代)断言计算(抛出)此消息:“预期:包含“value”的集合”。但是断言应该通过,因为它只验证一个项目,而不是一个集合

我有NUnit 3.2.1。我升级到3.12.0版,之后消息从:“预期:包含“值”的集合”更改为:“预期:某些项等于“值”,断言仍然没有通过


公共类验证器
{
public void VerifyCollectedValues(列出collectedValues,列出expectedValues
,从中收集的字符串值,int countofvalueexpact,bool verifyExactSameValue=true)
{
//创建约束函数
Func constraintFunction=CreateConstraintFunction(Has.justice(countOfValueExpactance),verifyExactSameValue);
//将约束传递给方法
验证collectedValues(constraintFunction、collectedValues、expectedValues、collectedValuesFrom);
}
public void VerifyCollectedValues(函数约束函数、列表collectedValues、列表expectedValues
,从中收集的字符串值)
{
foreach(expectedValues中的字符串expectedValue)
{
//应用约束
Assert.That(collectedValues,constraintFunction(expectedValue));
}
}
公共函数CreateConstraintFunction(ConstraintExpression ConstraintExpression,布尔验证ExactSameValue)
{
if(验证ExactSamEvalue)
{
返回值(字符串值)=>constraintExpression.EqualTo(值);
}
其他的
{              
返回(字符串值)=>constraintExpression.Contains(值);
}
}
}
示例代码:


验证器验证器=新验证器();
List expectedValues=新列表()
{
“价值1”,
“价值2”,
“价值3”,
};
var collectedValues=新列表()
{
“一些价值0”,
“一些价值1”,
“一些价值2”,
“一些价值3”,
};
//这过去了
foreach(expectedValues中的字符串expectedValue)
{
Assert.That(collectedValues,Has.justice(1).Contains(expectedValue));
}
//此操作失败,消息为:“预期:包含“value2”(使用NUnit v3.2.1)的集合/”预期:某些项等于“value2”(使用NUnit v3.12.0)
VerifyCollectedValues(collectedValues,expectedValues,1,false);
我的假设是这个问题是由我自己造成的。我不明白的是为什么列表的第一项通过了,而第二项没有通过

如果有任何答复,我将不胜感激

更新:

我做了一些编辑,并在此基础上排除了IResolveConstraint导致问题的可能性。以下是当前代码的示例:


公共类验证器
{
public void VerifyCollectedValues(List collectedValues、List expectedValues、string collectedValues from、int countOfValueExpectance、bool verifyExactSameValue=true)
{            
VerifyCollectedValues(CreateConstraintExpressionExactly(countOfValueExpectance)、collectedValues、expectedValues、collectedValuesFrom、verifyExactSameValue);
}
private void VerifyCollectedValues(ConstraintExpression ConstraintExpression,列出collectedValues,列出expectedValues,字符串collectedValues from,bool exactSameValue)
{
if(精确相同值)
{
验证CollectedValueSequalto(constraintExpression、collectedValues、expectedValues、collectedValuesFrom);
}
其他的
{
验证CollectedValuesContains(constraintExpression、collectedValues、expectedValues、collectedValuesFrom);
}
}
private void VerifyCollectedValuesEqualTo(ConstraintExpression ConstraintExpression,列出collectedValues,列出expectedValues,字符串collectedValuesFrom)
{
Func constraintFunction=(字符串值)=>constraintExpression.EqualTo(值);
foreach(expectedValues中的字符串expectedValue)
{
Assert.That(collectedValues,constraintFunction(expectedValue));
}
}
private void VerifyCollectedValuesContains(ConstraintExpression ConstraintExpression、List collectedValues、List expectedValues、string collectedValuesFrom)
{
//如果我不使用constraintExpression,而是手动编写表达式(Has.justice(1).Contains(value)),那么它就可以正常工作
Func constraintFunction=(字符串值)=>constraintExpression.Contains(值);
foreach(expectedValues中的字符串expectedValue)
{
Assert.That(collectedValues,constraintFunction(expectedValue));
}
}
私有约束表达式CreateConstraintExpressionExactly(预期的整数计数)
{
返回值为。精确(预期计数);
}
var验证器=新验证器();
List expectedValues=新列表()
{                
“价值1”,
“价值2”,
“价值3”,
};
var collectedValues=新列表()
{
“一些价值0”,
“一些价值1”,
“有些价值2