Esempio n. 1
0
        }   // private static string GenerateDetailFormatStringFromLabelRow


        /// <summary>
        /// Perform the first JSON transformation exercise.
        /// </summary>
        /// <param name="pintTestNumber">
        /// This integer is the number assigned to the last test that ran, which
        /// is fed to Utl.BeginTest, along with <paramref name="pstrTestReportLabel"/>,
        /// which increments it. Because the value is passed by reference, Utl.BeginTest
        /// need not return it to preserve the new value.
        /// </param>
        /// <param name="pfConvertLineEndings">
        /// Specify TRUE to have line endings in input file
        /// <paramref name="pstrRESTResponseFileName"/> converted to Unix line
        /// breaks, or FALSE to preserve whatever is there, which will be
        /// Windows line breaks.
        /// </param>
        /// <param name="pstrTestReportLabel">
        /// Specify the string to apply as a label to the test report. Utility
        /// method Utl.BeginTest receives this value, along with
        /// <paramref name="pintTestNumber"/>.
        /// </param>
        /// <param name="pstrRESTResponseFileName">
        /// Pass in a string that contains the unqualified name of the file that
        /// contains the JSON response returned by the REST API.
        /// </param>
        /// <param name="pstrIntermediateFileName">
        /// Pass in a string that contains the unqualified name of the file that
        /// will store the output of the first transformation of the data in the
        /// file named by <paramref name="pstrRESTResponseFileName"/>.
        /// </param>
        /// <param name="pstrFinalOutputFileName">
        /// Pass in a string that contains the unqualified name of the file that
        /// will store the output of the second transformation of the data in
        /// the file named by <paramref name="pstrRESTResponseFileName"/>.
        /// </param>
        /// <param name="pstrResponseObjectFileName">
        /// Pass in a string that contains the unqualified name of the file that
        /// will store the output of the report of member values of the 
        /// deserialized object constructed from the transformed data read from
        /// the file named by <paramref name="pstrRESTResponseFileName"/>.
        /// </param>
        /// <returns>
        /// This routine calls Utl.BeginTest, which increments the test number.
        /// The new value is returned so that it can be fed to the next test.
        /// </returns>
        /// <remarks>
        /// The argument list could be simplified by passing in a reference to
        /// the JSONDeserializationUseCase object from which all but the first
        /// parameter is extracted. It wasn't because I perfected the test from
        /// a set of discrete values; the JSONDeserializationUseCase objec came
        /// much later, and I saw no point in changing the signature for a
        /// demonstration program.
        /// </remarks>
        private static int PerformJSONTransofmration (
            int pintTestNumber ,
            bool pfConvertLineEndings ,
            string pstrTestReportLabel ,
            string pstrRESTResponseFileName ,
            string pstrIntermediateFileName ,
            string pstrFinalOutputFileName ,
            string pstrResponseObjectFileName )
        {
            Utl.BeginTest (
                pstrTestReportLabel ,
                ref pintTestNumber );

            string strRawResponse = pfConvertLineEndings
                                    ? Utl.GetRawJSONString ( pstrRESTResponseFileName ).UnixLineEndings ( )
                                    : Utl.GetRawJSONString ( pstrRESTResponseFileName );
            JSONFixupEngine engine = new JSONFixupEngine ( @"TIME_SERIES_DAILY_ResponseMap" );
            string strFixedUp_Pass_1 = engine.ApplyFixups_Pass_1 ( strRawResponse );

            Utl.PreserveResult (
                strFixedUp_Pass_1 ,                                             // string pstrPreserveThisResult
                pstrIntermediateFileName ,                                      // string pstrOutputFileNamePerSettings
                Properties.Resources.FILE_LABEL_INTERMEDIATE );                 // string pstrLabelForReportMessage

            string strFixedUp_Pass_2 = engine.ApplyFixups_Pass_2 ( strFixedUp_Pass_1 );

            Utl.PreserveResult (
                strFixedUp_Pass_2 ,                                             // string pstrPreserveThisResult
                pstrFinalOutputFileName ,                                       // string pstrOutputFileNamePerSettings
                Properties.Resources.FILE_LABEL_FINAL );                        // string pstrLabelForReportMessage

            //  ------------------------------------------------------------
            //  TimeSeriesDailyResponse
            //  ------------------------------------------------------------

            Utl.ConsumeResponse (
                pstrResponseObjectFileName ,
                Newtonsoft.Json.JsonConvert.DeserializeObject<TimeSeriesDailyResponse> (
                    strFixedUp_Pass_2 ) );

            s_smThisApp.BaseStateManager.AppReturnCode = Utl.TestDone (
                MagicNumbers.ERROR_SUCCESS ,
                pintTestNumber );
            return pintTestNumber;
        }   // private static int PerformJSONTransofmration
Esempio n. 2
0
        }   // static void Main


        /// <summary>
        /// When called by the main routine, this routine generates two lists of
        /// the application settings defined in the application configuration
        /// file associated with the entry assembly. The first list is displayed
        /// on the console, while the second is written into a file as a set of
        /// tab delimited list of records.
        /// </summary>
        /// <param name="pintTestNumber">
        /// The sequential test number is passed into this routine, which
        /// increments it, and returns the new value.
        /// </param>
        /// <returns>
        /// The return value is <paramref name="pintTestNumber"/> incremented by
        /// one.
        /// </returns>
        private static int ListAppSettings ( int pintTestNumber )
        {
            Utl.BeginTest (
                Properties.Resources.MSG_TEST_2_PROLOGUE ,
                ref pintTestNumber );

            //  ----------------------------------------------------------------
            //  Load the settings into a SettingsPropertyCollection object, then
            //  enumerate it with two objectives.
            //
            //  1)  Show that the items returned by the enumerator are unsorted.
            //  2)  Fill an array of SortableSettingsProperty objects.
            //  ----------------------------------------------------------------

            SettingsPropertyCollection spcMySettings = Properties.Settings.Default.Properties;
            int intTotalItems = spcMySettings.Count;
            Console.WriteLine (
                Properties.Resources.MSG_SETTINGS_ENUMERATION_HEADING ,         // Format control string
                intTotalItems ,                                                 // Format Item 0
                Environment.NewLine );                                          // Format Item 1
            SortableSettingsProperty [ ] asspSortableSettings = new SortableSettingsProperty [ intTotalItems ];
            int intItenNumber = ListInfo.LIST_IS_EMPTY;

            foreach ( SettingsProperty setting in spcMySettings )
            {   // Do everything in one pass, using the third constructor, since the single-argument constructor left most of the fields uninitialized.
                asspSortableSettings [ intItenNumber ] = new SortableSettingsProperty (
                    setting.Name ,                                              // string                       name
                    setting.PropertyType ,                                      // Type                         propertType
                    setting.Provider ,                                          // SettingsProvider             provider
                    true ,                                                      // bool                         isReadOnly
                    setting.DefaultValue ,                                      // object                       defaultValue
                    setting.SerializeAs ,                                       // SettingsSerializeAs          serializeAs
                    setting.Attributes ,                                        // SettingsAttributeDictionary  attributes
                    true ,                                                      // bool                         throwOnErrorDeserializing
                    true );                                                     // bool                         throwOnErrorSerializing
                Console.WriteLine (
                    Properties.Resources.MSG_APP_SETTINGS_DETAIL_TEMPLATE ,     // Format control string
                    ++intItenNumber ,                                           // Format Item 0: {0,2} of
                    intTotalItems ,                                             // Format Item 1: of {1,2}:
                    setting.Name ,                                              // Format Item 2: Name = {2}
                    setting.DefaultValue );                                     // Format Item 3: Value = {3}
            }   // foreach ( SettingsProperty setting in spcMySettings )

            //  ----------------------------------------------------------------
            //  Sort the array, then iterate it by way of a conventional FOR
            //  loop, listing the name, type, and default value of each setting.
            //  This listing is ordered by setting name.
            //  ----------------------------------------------------------------

            Array.Sort ( asspSortableSettings );
            Console.WriteLine (
                Properties.Resources.MSG_SORTED_APP_SETTINGS_LIST_HEADING ,     // Format control string
                intTotalItems ,                                                 // Format Item 0: Enumerate the {0}
                Environment.NewLine );                                          // Format Item 1: sorted settings:{1}
            intItenNumber = ListInfo.LIST_IS_EMPTY;

            string strAppSettingsReportFileName = Utl.AssembleAbsoluteFileName ( Properties.Settings.Default.APP_SETTINGS_REPORT_FILENAME );
            using ( StreamWriter swAppSettings = new StreamWriter ( strAppSettingsReportFileName ,
                                                                    FileIOFlags.FILE_OUT_CREATE ,
                                                                    System.Text.Encoding.ASCII ,
                                                                    MagicNumbers.CAPACITY_08KB ) )
            {
                string strDetailRowFormatString = GenerateDetailFormatStringFromLabelRow ( swAppSettings );

                for ( int intIndex = ArrayInfo.ARRAY_FIRST_ELEMENT ;
                          intIndex < intTotalItems ;
                          intIndex++ )
                {
                    SortableSettingsProperty settingsProperty = asspSortableSettings [ intIndex ];
                    Console.WriteLine (
                        Properties.Resources.MSG_APP_SETTINGS_SORTED_ITEM ,     // Format control string
                        ++intItenNumber ,                                       // Format Item 0: {0,2} of
                        intTotalItems ,                                         // Format Item 1: of {1,2}:
                        settingsProperty.Name ,                                 // Format Item 2: Name = {2}
                        settingsProperty.PropertyType.FullName ,                // Format Item 3: Type = {2}
                        settingsProperty.DefaultValue );                        // Format Item 4: Value = {4}
                    swAppSettings.WriteLine (
                        strDetailRowFormatString ,                              // The generated format control string consists entirely of format items and TAB characters.
                        intItenNumber ,                                         // The item number was incremented just before the console line was assembled.
                        settingsProperty.Name ,
                        settingsProperty.PropertyType.FullName ,
                        settingsProperty.DefaultValue );
                }   // for ( int intIndex = ArrayInfo.ARRAY_FIRST_ELEMENT ; intIndex < intTotalItems ; intIndex++ )
            }   // using ( StreamWriter swAppSettings = new StreamWriter ( Utl.AssembleAbsoluteFileName ( Properties.Settings.Default.APP_SETTINGS_REPORT ) , FileIOFlags.FILE_OUT_CREATE , System.Text.Encoding.ASCII , MagicNumbers.CAPACITY_08KB ) )

            Console.WriteLine (
                Utl.ShowFileDetails (
                    Properties.Resources.FILE_LABEL_APP_SETTINGS_LIST ,         // string pstrLabel
                    strAppSettingsReportFileName ,                              // string pstrFileName
                    true ,                                                      // bool   pfPrefixWithNewline = false
                    false ) );                                                  // bool   pfSuffixWithNewline = true
            s_smThisApp.BaseStateManager.AppReturnCode = Utl.TestDone (
                MagicNumbers.ERROR_SUCCESS ,
                pintTestNumber );
            return pintTestNumber;
        }   // private static int ListAppSettings
Esempio n. 3
0
        internal static int Exercise ( ref int pintTestNumber )
        {
            const int SCENARIO_COUNT = 3;

            Utl.BeginTest (
                string.Concat (
                    nameof ( StringExtensions ) ,
                    @" (Line ending transformation methods)" ) ,
                ref pintTestNumber );

            int intInputCase = ListInfo.LIST_IS_EMPTY;
            int intOverallCase = ListInfo.LIST_IS_EMPTY;
            int intTotalTestCases = s_astrTestStrings.Length * SCENARIO_COUNT;

            WizardWrx.ConsoleStreams.MessageInColor micSuccessfulOutcomeMessage = new WizardWrx.ConsoleStreams.MessageInColor (
                Properties.Settings.Default.SuccessfulOutcomeMessageColor.EnumFromString<ConsoleColor> ( ) ,
                Properties.Settings.Default.SuccessfulOutcomeMessageBackgroundColor.EnumFromString<ConsoleColor> ( ) );

            WizardWrx.ConsoleStreams.MessageInColor micUnsuccessfulOutcomeMessage = new WizardWrx.ConsoleStreams.MessageInColor (
                WizardWrx.ConsoleStreams.ErrorMessagesInColor.FatalExceptionTextColor ,
                WizardWrx.ConsoleStreams.ErrorMessagesInColor.FatalExceptionBackgroundColor );

            for ( int intJ = ArrayInfo.ARRAY_FIRST_ELEMENT ;
                      intJ < s_astrTestStrings.Length ;
                      intJ++ )
            {
                Console.WriteLine (
                    @"        Input string test {0} of {1}: Input String Length = {2}, Input String:{4}{3}{4}" ,
                    new object [ ]
                    {
                        ++intInputCase ,                                        // Format Item 0: Input string test {0}
                        s_astrTestStrings.Length ,                              // Format Item 1: of {1}:
                        s_astrTestStrings [ intJ ].InputString.Length ,         // Format Item 2: Input String Length = {2}
                        s_astrTestStrings [ intJ ].InputString ,                // Format Item 3:  (s_astrTestStrings [ intJ ].InputString):{4}{3}
                        Environment.NewLine                                     // Format Item 4
                    } );

                string strFormattedForMac = s_astrTestStrings [ intJ ].InputString.OldMacLineEndings ( );
                string strFormattedForUnix = s_astrTestStrings [ intJ ].InputString.UnixLineEndings ( );
                string strFormattedForWindows = s_astrTestStrings [ intJ ].InputString.WindowsLineEndings ( );

                intOverallCase = ReportTestOutcome (
                    intOverallCase ,
                    intTotalTestCases ,
                    intJ ,
                    nameof ( strFormattedForMac ) ,
                    strFormattedForMac ,
                    SpecialCharacters.CARRIAGE_RETURN );
                intOverallCase = ReportTestOutcome (
                    intOverallCase ,
                    intTotalTestCases ,
                    intJ ,
                    nameof ( strFormattedForUnix ) ,
                    strFormattedForUnix ,
                    SpecialCharacters.LINEFEED );
                intOverallCase = ReportTestOutcome (
                    intOverallCase ,
                    intTotalTestCases ,
                    intJ ,
                    nameof ( strFormattedForWindows ) ,
                    strFormattedForWindows ,
                    SpecialStrings.STRING_SPLIT_NEWLINE );
            }   // for ( int intK = ArrayInfo.ARRAY_FIRST_ELEMENT ; intK < s_astrTestStrings.Length ; intK++ )

            Console.WriteLine (
                @"{1}    Test summary: Successful Outcome Count   = {0}" ,
                s_intGoodOutcomes ,
                Environment.NewLine );
            Console.WriteLine (
                @"                  Unsuccessful Outcome Count = {0}{1}" ,
                s_intBadOutcomes ,
                Environment.NewLine );

            if ( s_intBadOutcomes == ListInfo.LIST_IS_EMPTY )
            {
                micSuccessfulOutcomeMessage.WriteLine ( @"    A-OK!" );
            }   // TRUE (antiicpated outcome) block, if ( s_intBadOutcomes == ListInfo.LIST_IS_EMPTY )
            else
            {
                micUnsuccessfulOutcomeMessage.WriteLine ( @"    YIKES!" );
            }   // FALSE (unantiicpated outcome) block, if ( s_intBadOutcomes == ListInfo.LIST_IS_EMPTY )

            return Utl.TestDone (
                MagicNumbers.ERROR_SUCCESS ,
                pintTestNumber );
        }   // internal static int Exercise