Пример #1
0
        public DigestTestCases ( )        
        {
            const int LABEL_ROW = 1;
            const int FIELD_FILE_NAME = ArrayInfo.ARRAY_FIRST_ELEMENT;
            const int FIELD_EXPECTED_DIGEST = FIELD_FILE_NAME + MagicNumbers.PLUS_ONE;
            const int TOTAL_FIELDS = FIELD_EXPECTED_DIGEST + MagicNumbers.PLUS_ONE;

            const string TEST_CASE_FILENAME = @"DigestMD5TestCases.TXT";

            try
            {
                string [ ] astrCases = Utl.LoadTextFileFromEntryAssembly ( TEST_CASE_FILENAME );
                   
                int intNRecords = astrCases.Length;

                if ( intNRecords > LABEL_ROW )
                {   // File contains detail records.
                    _lstCaseRecords = new List<CaseRecord> ( intNRecords - LABEL_ROW );

                    for ( int intRecordNumber = LABEL_ROW ; intRecordNumber < intNRecords ; intRecordNumber++ )
                    {   // Skipping the label row, which is for human consumption, populate the list from the data records.
                        string [ ] astrFields = astrCases [ intRecordNumber ].Split ( new char [ ] { SpecialCharacters.TAB_CHAR } );

                        if ( astrFields.Length == TOTAL_FIELDS )
                        {
                            CaseRecord cr = new CaseRecord ( );
                            cr.strFileName = astrFields [ FIELD_FILE_NAME ];
                            cr.strDigest = astrFields [ FIELD_EXPECTED_DIGEST ];
                            _lstCaseRecords.Add ( cr );
                        }
                        else
                        {
                            throw new ArgumentException (
                                string.Format (
                                INVALID_RECORD ,
                                TEST_CASE_FILENAME ,
                                intRecordNumber ) );
                        }   // if ( astrFields.Length == EXPECTED_FIELD_COUNT )
                    }   // for ( int intRecordNumber = LABEL_ROW ; intRecordNumber < intNRecords ; intNRecords++ )
                }
                else
                {   // File is empty.
                    throw new ArgumentException ( 
                        string.Format (
                            EMPTY ,
                            TEST_CASE_FILENAME ) );
                }   // if ( intNRecords > LABEL_ROW )
            }
            catch
            {
                throw;
            }
        }   // public DigestTestCases