}	// ASCII_Table_Gen


		internal static void TestFormatItemBuilders ( )
		{
			const string ERRMSG_UNEQUAL_ARRAYS = @"An internal error has occurred. Arrays s_astrLabelsOfVariousLengths and s_astrValuseOfIrrelevantLengths are of unequal length.{2}s_astrLabelsOfVariousLengths Length    = {0}{2}s_astrValuseOfIrrelevantLengths Length = {1}";
			const string MSG_PROLOGUE = @"{1}Exercising routine AdjustToMaximumWidth: Item Count = {0}{1}";
			const string MSG_REPORT_LINE = @"    Item {0}: {1} = {2}";
			const int REPORT_LABEL_ITEM_INDEX = 1;
			const string REPORT_SUMMARY = @"{0}AdjustToMaximumWidth exercises completed!{0}";

			int intNLabels = s_astrLabelsOfVariousLengths.Length;

			if ( intNLabels == s_astrValuseOfIrrelevantLengths.Length )
			{
				Console.WriteLine ( MSG_PROLOGUE ,                              // Format template string
					intNLabels ,                                                // Format Item 0 = Item count
					Environment.NewLine );                                      // Format Item 1 = Newline, my way
				string strDynamicFormat = FormatItem.UpgradeFormatItem (
					MSG_REPORT_LINE ,                                           // string     pstrFormat       = Prototype format template string
					REPORT_LABEL_ITEM_INDEX ,                                   // int        pintItemIndex    = Index (zero based) of format item to upgrade
					FormatItem.Alignment.Left ,                                 // Alignment  penmAlignment    = Left or Right
					null ,                                                      // string     pstrFormatString = Omit
					s_astrLabelsOfVariousLengths );                             // string [ ] pastrValueArray  = Must fit all of these.

				for ( int intItem = ARRAY_FIRST_ELEMENT ; intItem < intNLabels ; intItem++ )
				{
					Console.WriteLine (
						strDynamicFormat ,                                      // Dynamically generated Format template string
						intItem + ARRAY_LIST_ORDINAL_TO_SUBSCRIPT ,             // Format Item 0 = Item number (1 based)
						s_astrLabelsOfVariousLengths [ intItem ] ,              // Format Item 1 = Label
						s_astrValuseOfIrrelevantLengths [ intItem ] );          // Format Item 1 = Value
				}   // for ( int intItem = ARRAY_FIRST_ELEMENT ; intItem < intNLabels ; intItem++ )

				Console.WriteLine (
					REPORT_SUMMARY ,
					Environment.NewLine );
			}   // TRUE (expected outcome) block, if ( intNLabels == s_astrValuseOfIrrelevantLengths.Length )
			else
			{
				throw new InvalidOperationException (
					string.Format (
						ERRMSG_UNEQUAL_ARRAYS ,                                 // Format template string
						s_astrLabelsOfVariousLengths.Length ,                   // Format Item 0 = Length of s_astrLabelsOfVariousLengths array
						s_astrValuseOfIrrelevantLengths.Length ,                // Format Item 1 = Length of s_astrValuseOfIrrelevantLengths array
						Environment.NewLine ) );                                // Format Item 2 = Newline, my way
			}   // FALSE (UNexpected outcome) block, if ( intNLabels == s_astrValuseOfIrrelevantLengths.Length )
		}   // TestFormatItemBuilders
Пример #2
0
        }   // private void ReportDetailsTests


        private static void ReportHelpersTests ( )
        {
            const uint DESIRED_WIDTH_MINIMUM = 1;
            const uint DESIRED_WIDTH_MAXIMUM = 10;

            const uint ITEM_NUMBER_MINIMUM = 0;
            const uint ITEM_NUMBER_MAXIMUM = 4;

            string strTaskName = System.Reflection.MethodBase.GetCurrentMethod ( ).Name;

            Console.WriteLine (
                Properties.Resources.IDS_MSG_BATCH ,
                strTaskName ,
                Properties.Resources.IDS_MSG_BEGIN ,
                Environment.NewLine );

            uint uintTestNumber = MagicNumbers.ZERO;
            uint uintExceptionCount = MagicNumbers.ZERO;
            long lngTotalTests = MagicNumbers.ZERO;
            string strHeadingFormat = null;

#if DBG_REPORTHELPERSTESTS
            uint uintItemIndexCounter = MagicNumbers.ZERO;
#endif  // DBG_REPORTHELPERSTESTS

            for ( uint uintItemIndex = ITEM_NUMBER_MINIMUM ;
                       uintItemIndex <= ITEM_NUMBER_MAXIMUM ;
                       uintItemIndex++ )                           
            {

#if DBG_REPORTHELPERSTESTS
                Console.WriteLine (
                    "LOOP DEBUG: uintItemIndexCounter = {0}, uintItemIndex = {1}" ,
                    ++uintItemIndexCounter ,
                    uintItemIndex );
                uint uintMaximumWidthCounter = MagicNumbers.ZERO;
#endif  // DBG_REPORTHELPERSTESTS

                for ( uint uintMaximumWidth = DESIRED_WIDTH_MINIMUM ;
                           uintMaximumWidth < DESIRED_WIDTH_MAXIMUM ;
                           uintMaximumWidth++ )
                {

#if DBG_REPORTHELPERSTESTS
                    Console.WriteLine (
                        "LOOP DEBUG: uintMaximumWidthCounter = {0}, uintMaximumWidth = {1}" ,
                        ++uintMaximumWidthCounter ,
                        uintMaximumWidth );
                    uint uintAlignmentCounter = MagicNumbers.ZERO;
#endif  // DBG_REPORTHELPERSTESTS

                    foreach ( FormatItem.Alignment enmAlignment in s_aenmAlignment )
                    {

#if DBG_REPORTHELPERSTESTS
                        Console.WriteLine (
                            "LOOP DEBUG: uintAlignmentCounter = {0}, enmAlignment = {1}" ,
                            ++uintAlignmentCounter ,
                            enmAlignment );
                        uint uintTestFormatCounter = MagicNumbers.ZERO;
#endif  // DBG_REPORTHELPERSTESTS

                        foreach ( string strTestFormat in s_astrFormats )
                        {

#if DBG_REPORTHELPERSTESTS
                        Console.WriteLine (
                            "LOOP DEBUG: uintTestFormatCounter = {0}, strTestFormat = {1}" ,
                            ++uintTestFormatCounter ,
                            strTestFormat );
#endif  // DBG_REPORTHELPERSTESTS

                            if ( lngTotalTests == MagicNumbers.ZERO )
                            {
								lngTotalTests = ( ( ITEM_NUMBER_MAXIMUM - ITEM_NUMBER_MINIMUM ) + ArrayInfo.ORDINAL_FROM_INDEX )
                                                * ( DESIRED_WIDTH_MAXIMUM - DESIRED_WIDTH_MINIMUM )
                                                * s_aenmAlignment.Length
                                                * s_astrFormats.Length;
                                strHeadingFormat = FormatItem.UpgradeFormatItem (
                                    Properties.Resources.MSG_NEW_TEST ,
                                    ITEM_NUMBER_MINIMUM ,
                                    FormatItem.AdjustToMaximumWidth (
                                        ITEM_NUMBER_MINIMUM ,
                                        ( uint ) lngTotalTests.ToString (
                                            NumericFormats.NUMBER_PER_REG_SETTINGS_0D ).Length ,
                                        FormatItem.Alignment.Right ,
                                        NumericFormats.NUMBER_PER_REG_SETTINGS_0D ) );
                            }   // if ( lngTotalTests == MagicNumbers.ZERO )

                            Console.WriteLine (
                                strHeadingFormat ,
                                ++uintTestNumber ,
                                lngTotalTests ,
                                Environment.NewLine );
                            string strUpgradedFormat = FormatItem.AdjustToMaximumWidth (
                                uintItemIndex ,
                                uintMaximumWidth ,
                                enmAlignment ,
                                strTestFormat );

                            ReportDetails rdColl = new ReportDetails ( );

                            rdColl.Add ( new ReportDetail (
                                Properties.Resources.MSG_PENMALIGNMENT ,
                                ( object ) uintItemIndex ) );
                            rdColl.Add ( new ReportDetail (
                                Properties.Resources.MSG_PUINTMAXIMUMWIDTH ,
                                ( object ) uintMaximumWidth ) );
                            rdColl.Add ( new ReportDetail (
                                Properties.Resources.MSG_PENMALIGNMENT ,
                                enmAlignment ) );
                            rdColl.Add ( new ReportDetail (
                                Properties.Resources.MSG_PSTRFORMATSTRING ,
                                ( object ) strTestFormat ) );               // Coerce strTestFormat into the object.

                            rdColl.Add ( new ReportDetail (
                                Properties.Resources.MSG_UPGRADED_FORMAT ,
                                ( object ) strUpgradedFormat ) );

                            int uintRequiredWidth = rdColl.WidthOfWidestLabel;

                            foreach ( ReportDetail rdItem in rdColl )
                            {
                                Console.WriteLine (
                                    ReportDetail.DEFAULT_FORMAT ,
                                    rdItem.Label.PadRight ( ( int ) uintRequiredWidth ) ,
                                    rdItem.Value );
                            }   // foreach ( ReportDetail rdItem in rdColl )


                            //  ------------------------------------------------
                            //  There are intentionally programed exceptions in
                            //  this test.
                            //  ------------------------------------------------

                            try
                            {
                                Console.WriteLine (
                                    Properties.Resources.MSG_SHOW_SAMPLE_BEFORE_AND_AFTER ,
                                    Properties.Resources.MSG_SAMPLE_FORMAT_STRING ,
                                    FormatItem.UpgradeFormatItem (
                                        Properties.Resources.MSG_SAMPLE_FORMAT_STRING ,
                                        uintItemIndex ,
                                        strUpgradedFormat ) ,
                                    Environment.NewLine );
                            }
                            catch ( Exception exAllKinds )
                            {
								rs_appThis.BaseStateManager.AppExceptionLogger.ReportException ( exAllKinds );
                                uintExceptionCount++;
                            }

                            if ( uintTestNumber == lngTotalTests )
                            {   // We need just one test of this type of error.
                                try
                                {
                                    Console.WriteLine (
                                        Properties.Resources.MSG_SHOW_SAMPLE_BEFORE_AND_AFTER ,
                                        Properties.Resources.MSG_SAMPLE_FORMAT_STRING ,
                                        FormatItem.UpgradeFormatItem (
                                            Properties.Resources.MSG_SAMPLE_FORMAT_STRING ,
                                            uintItemIndex ,
                                            "(4,9:X8)" ) ,      // This format item is invalid.
                                        Environment.NewLine );
                                }
                                catch ( Exception exAllKinds )
                                {
									rs_appThis.BaseStateManager.AppExceptionLogger.ReportException ( exAllKinds );
                                    uintExceptionCount++;
                                }
                            }   // if ( uintTestNumber == lngTotalTests )
                        }   // foreach ( string strTestFormat in s_astrFormats )
                    }   // foreach ( FormatItem.Alignment enmAlignment in s_aenmAlignment )
                }   // for ( uint uintMaximumWidth = MINIMUM_DESIRED_WIDTH ; uintMaximumWidth <= MAXIMUM_DESIRED_WIDTH ; uintMaximumWidth++ )
            }   // for ( uint uintItemIndex = MINIMUM_ITEM_NUMBER ; uintItemIndex < FORMAT_ITEM_LIMIT ; uintItemIndex++ )

            Console.WriteLine (
                Properties.Resources.MSG_EXCETIONS_COUNTED ,
                uintExceptionCount ,
                Environment.NewLine );
            Console.WriteLine (
                Properties.Resources.IDS_MSG_BATCH ,
                strTaskName ,
                Properties.Resources.IDS_MSG_DONE ,
                Environment.NewLine );
        }   // ReportHelpersTests