Why this test will not pass?

Amos Matthew 21 Reputation points

Working on this test for days now. What am I doing wrong?

public long Add_PhoneNumber(string 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"));

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
4,899 questions
0 comments No comments
{count} votes

Accepted answer
  1. Mark Allan 416 Reputation points MVP

    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.

1 additional answer

Sort by: Most helpful
  1. Ryan Hill 18,396 Reputation points Microsoft Employee

    First thing sticking out to me is that even though you're passing "12312312345" into cust1.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 the Console.ReadLine(), it's not needed since you're passing in the entry as an argument.

    Hope this helps.