Почему бы не иметь словарь ожидаемых выражений и выражение foreach, возвращаемое методом, который вы проверяете в словаре, чтобы они были и были только один раз.
Примерно так:
IDictionary<string, bool> CreateExpectedDictionary()
{
IDcitionary<string, bool> expectedDictionary = new Dictionary<string, bool>();
// Here add all the expressions you expect to be returned
expectedDictionary.Add("1*3+5*7+9", false);
expectedDictionary.Add("-1-3*5+7*9", false);
return expectedDictionary ;
}
[TestMethod]
public void GetAnswersForResultIs47()
{
List<string> listOfExpressions = findArithmeticSymbolsInNumericOrder13579ThatGivesThisResult(47);
Dictionary<string, bool> expectedDic = CreateExpectedDictionary();
foreach (string expression in listOfExpressions)
{
if(expectedDic.ContainsKey(expression))
{
if(expectedDic[expression])
{
Assert.Fail(String.Format("The expression {0} was returned more than once.",expression));
}
expectedDic[expression] = true;
}
else
{
Assert.Fail(String.Format("The expression {0} was not expected", expression));
}
}
foreach(string exp in expectedDic.Keys)
{
if(!expectedDic[exp])
{
Assert.Fail(String.Format("The expression {0} is missing.", exp));
}
}
}