I have the method:
public static int Add(List<int> numbers)
{
if (numbers == null || numbers.Count == 0)
return 0;
if (numbers.Count == 1)
return numbers[0];
throw new NotImplementedException();
}
Here is my test against it, but it does not like new List<int> {1}
in the TestCase:
[TestCase(new List<int>{1}, 1)]
public void Add_WithOneNumber_ReturnsNumber(List<int> numbers)
{
var result = CalculatorLibrary.CalculatorFunctions.Add(numbers);
Assert.AreEqual(1, result);
}
It gives me the error:
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
Do I have to do it like this:
[Test]
public void Add_WithOneNumber_ReturnsNumber()
{
var result = CalculatorLibrary.CalculatorFunctions.Add(new List<int>{7});
Assert.AreEqual(7, result);
var result2 = CalculatorLibrary.CalculatorFunctions.Add(new List<int> {3});
Assert.AreEqual(4,result2);
}
question from:
https://stackoverflow.com/questions/19479817/how-do-i-put-new-listint-1-in-an-nunit-testcase 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…