private static void ProcessTestPage(TestPage testPage) { try { // Create page load (async) CQ.CreateFromUrlAsync(testPage.URL, responseSuccess => { var testResult = new TestResult() { URL = testPage.URL }; // Fix "stream close" var doc = responseSuccess.Dom; foreach (var element in testPage.ElementList) { // Check if element is supported if (_checkSupportedElements && !_supportedElements.Contains(element.Name.ToLowerInvariant())) { testResult.Cases.Add(new TestCase(element) {Unsupported = true}); } else { // Select element var foundElement = doc.Select(element.Name); if (foundElement != null && foundElement.Contents().Any()) { // Found, check if meets expected value var currentValue = foundElement.Contents()[0].NodeValue.Trim(); // Compare current value to expected // Note: Empty expected values are considered valid if (string.IsNullOrEmpty(element.ExpectedValue) || currentValue.Equals(element.ExpectedValue)) { System.Diagnostics.Debug.WriteLine("Valid"); } else { System.Diagnostics.Debug.WriteLine("Invalid, expected {0} received {1}", currentValue, element.ExpectedValue); testResult.Cases.Add(new TestCase(element) { ActualValue = currentValue }); } } } } // Prevent - "collection was modified enumeration operation may not execute" error. Syncs collection before modifying lock (((ICollection)TestResultsHub.GetTestResults().Results).SyncRoot) { TestResultsHub.GetTestResults().Results.Add(testResult); TestResultsHub.Instance.GetResults(); } }, responseFail => { // TODO }); } catch (UriFormatException) { System.Diagnostics.Debug.WriteLine("Invalid URL"); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error: {0}", e.Message); } }
private static void ProcessTestPage(TestPage testPage, ObservableCollection<TestResult> testResults, ProgressBar testingProgress) { try { // Create page load (async) CQ.CreateFromUrlAsync(testPage.URL, responseSuccess => { var testResult = new TestResult() { URL = testPage.URL }; // Fix "stream close" var doc = responseSuccess.Dom; foreach (var element in testPage.ElementList) { // Check if element is supported if (_checkSupportedElements && !_supportedElements.Contains(element.Name.ToLowerInvariant())) { testResult.Cases.Add(new TestCase(element) { Unsupported = true }); } else { // Select element var foundElement = doc.Select(element.Name); if (foundElement != null && foundElement.Contents().Any()) { // Found, check if meets expected value var currentValue = foundElement.Contents()[0].NodeValue.Trim(); // Compare current value to expected // Note: Empty expected values are considered valid if (string.IsNullOrEmpty(element.ExpectedValue) || currentValue.Equals(element.ExpectedValue)) { System.Diagnostics.Debug.WriteLine("Valid"); } else { System.Diagnostics.Debug.WriteLine("Invalid, expected {0} received {1}", currentValue, element.ExpectedValue); testResult.Cases.Add(new TestCase(element) { ActualValue = currentValue }); } } } } // Set test icons based on results testResult.Icon = new TestResultIcon( testResult.Cases.Any() ? TestResultIcon.TestResultState.FAIL : TestResultIcon.TestResultState.PASS ); // Add results (invoke main ui thread) System.Windows.Application.Current.Dispatcher.Invoke(() => { testResults.Add(testResult); DoubleAnimation doubleanimation = new DoubleAnimation(testingProgress.Value + 100, new Duration(TimeSpan.FromSeconds(1))); testingProgress.BeginAnimation(System.Windows.Controls.Primitives.RangeBase.ValueProperty, doubleanimation); }); }, responseFail => { // TODO }); } catch (UriFormatException) { System.Diagnostics.Debug.WriteLine("Invalid URL"); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error: {0}", e.Message); } }