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); }
/// <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)); }