cust1.Add_PhoneNumber("12312312345")
is passing in a string that's 11 characters long, so it'll be throwing at throw new ArgumentOutOfRangeException("Too many numbers");
, not returning a value. More generally speaking, don't forget that you can debug and step through unit tests which should help to find problems like this.
Why this test will not pass?
Amos Matthew
26
Reputation points
Working on this test for days now. What am I doing wrong?
public long Add_PhoneNumber(string v)
{
Console.WriteLine(v);
string line = Console.ReadLine();
if (line.Length > 10 )
throw new ArgumentOutOfRangeException("Too many numbers");
if (line.Length < 10)
throw new ArgumentOutOfRangeException("Too few numbers");
return (long.Parse(line));
}
public void Passing_AddPhoneNumber()
{
// Arrange
long expected_Number = 1231231234;
Customer cust1 = new Customer("Amos", "Matthew", expected_Number);
// Act
long actualNumber = cust1.Add_PhoneNumber("12312312345");
Assert.AreNotSame(expected_Number, cust1.Add_PhoneNumber("12312312345"));
}
Accepted answer
-
Mark Allan 426 Reputation points
2020-06-12T06:55:14.94+00:00
1 additional answer
Sort by: Most helpful
-
Ryan Hill 29,651 Reputation points Microsoft Employee
2020-06-12T04:48:58.987+00:00 First thing sticking out to me is that even though you're passing
"12312312345"
intocust1.Add_PhoneNumber
,string line
isn't equal to that. I'm not certain a testing framework like mstest; as I'm not sure which one you're using, will allow you text input during the run a test harness. Remove theConsole.ReadLine()
, it's not needed since you're passing in the entry as an argument.Hope this helps.
Regards,
Ryan