lundi 8 mai 2017

c# - How to generate random ITIN

How to generate an 9 digit ITIN number with 70-88 in the fourth and fifth digit?


The IRS site says that

An Individual Taxpayer Identification Number (ITIN) begins with the number 9 and has a range of **70-88 in the fourth and fifth digit. The range was extended to include 900-70-0000 through 999-88-9999, 900-90-0000 through 999-92-9999 and 900-94-0000 through 999-99-9999.


My test is to validate that an error message is seen when user tries to input a valid ITIN

My code is checking for fourth and fifth digit after getting a random number. A better way would be to get a random number with 9xx-70-0000 to 9xx-88-9999

        int RangeOneBoundaryStart = 70;
        int RangeOneBoundaryEnd = 88;       
        int count = 100;
        string InvalidMsg = "Invalid Entry. Individual Tax Identification Numbers are not accepted.";

        Random rand = new Random();

        for (int i = 1; i <=count; i++ )
        {
            int Rndm1 = rand.Next(900700000, 999889999);
            string num = Rndm1.ToString();                
            string chcknum = num.Substring(3, 2);
            int chcknumint = Int32.Parse(chcknum);

            if ( chcknumint >= RangeOneBoundaryStart && Rndm1 < RangeOneBoundaryEnd)
            {
                _applyPage.ClearField(VerifyElement);
                _applyPage.EnterTextWithValue(VerifyElement, num);
                _applyPage.Click(ClickAnotherElement);
                _TestMethods.ValidateError(ElementToVld, InvalidMsg);
            }            

        }




Aucun commentaire:

Enregistrer un commentaire