コード例 #1
0
        public static void TestJsonSample(JsonSampleInfo sampleInfo, Action <JsonSampleInfo> testMethod)
        {
            AdfTestLogger.LogInformation(string.Format(
                                             CultureInfo.InvariantCulture,
                                             "Testing JSON sample '{0}': {1}",
                                             sampleInfo.Name,
                                             sampleInfo.Json));

            testMethod(sampleInfo);
        }
コード例 #2
0
        /// <summary>
        /// Tests each of the given JSON samples using the given test method. If an error occurs when testing a
        /// sample, the error is logged and then the remaining samples are tested. Once all samples have been tested,
        /// an Assert.Fail is triggered if any of the samples failed.
        /// </summary>
        public static void TestJsonSamples(IEnumerable <JsonSampleInfo> samples, Action <JsonSampleInfo> testMethod)
        {
            int failureCount = 0;
            int sampleCount  = 0;

            foreach (JsonSampleInfo sampleInfo in samples)
            {
                string sampleName = sampleInfo.Name;
                sampleCount++;
                AdfTestLogger.LogInformation(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "Testing JSON sample #{0}: {1}",
                        sampleCount,
                        sampleInfo.Name));

                try
                {
                    testMethod(sampleInfo);
                    AdfTestLogger.LogInformation(sampleName + " PASSED");
                }
                catch (Exception ex)
                {
                    // When a sample test fails, log the exception and then continue testing the remaining samples.
                    AdfTestLogger.LogInformation(
                        string.Format(
                            "{0} FAILED: Exception: {1}{2}{3} JSON:{4}{5}",
                            sampleName,
                            ex,
                            Environment.NewLine,
                            sampleName,
                            Environment.NewLine,
                            sampleInfo.Json));
                    failureCount++;
                }
            }

            // Fail the test if any of the samples failed.
            Assert.False(failureCount > 0, string.Format(
                             CultureInfo.InvariantCulture,
                             "{0} of {1} samples failed. See test output for details.",
                             failureCount,
                             sampleCount));
        }
コード例 #3
0
        private static DateTime ParseDateTime(string value)
        {
            try
            {
                return(DateTime.ParseExact(value,
                                           CustomIsoDateTimeConverter.ValidDateTimeFormats,
                                           CustomIsoDateTimeConverter.DefaultCulture,
                                           CustomIsoDateTimeConverter.DefaultDateTimeStyles));
            }
            catch (Exception ex)
            {
                // This happens when the Json was serialized with the Customization codes in the client side MAML layer.
                AdfTestLogger.LogVerbose(
                    "Failed to parse \"{0}\" with CustomIsoDateTimeConverter with exception {1}. Fall back to the default DateTime parser.",
                    value, ex.Message);

                return(DateTime.Parse(value, CultureInfo.InvariantCulture));
            }
        }