public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = "HTTP response valid", Status = TestResult.INCONCLUSIVE }; try { var c = new WebClient(); byte[] data = c.DownloadData(o.Url + RelativeUrl); if (HttpValidationTests.IsValidJson(c.ResponseHeaders) && HttpValidationTests.IsValidCharsetUtf8(c.ResponseHeaders)) { res.Status = TestResult.OK; } else { res.Status = TestResult.FAIL; res.ExtraInformation = "No response header Content-Type. Invalid HTTP"; } } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } return(res); }
public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = "Calling HTTP (no SSL)", Status = TestResult.INCONCLUSIVE }; try { WebClient c = SetupWebClient(o); string data = Encoding.UTF8.GetString(c.DownloadData((o.Url + RelativeUrl).Replace("https", "http"))); if (c.ResponseHeaders["Location"] != null && c.ResponseHeaders["Location"].Contains("https")) { res.Status = TestResult.OK; res.ExtraInformation = "Using redirect"; } if (HttpValidationTests.IsValidJson(c.ResponseHeaders) && HttpValidationTests.IsValidCharsetUtf8(c.ResponseHeaders)) { if (data.Contains("generation_time") && data.Contains("ref_position_lon") && data.Contains("ref_position_lat") && data.Contains("speed") && data.Contains("heading") && data.Contains("provider_id") && data.Contains("user_id_anonymous")) { res.Status = TestResult.FAIL; res.ExtraInformation = "Received http 200 ok with all data fields present."; } else { res.Status = TestResult.FAIL; res.ExtraInformation = "Received http 200 ok, but required data fields were not present."; } } else { res.Status = TestResult.OK; res.ExtraInformation = "No json data received. "; } } catch (WebException wex) { var response = (HttpWebResponse)wex.Response; if (response.StatusCode != HttpStatusCode.Accepted && response.StatusCode != HttpStatusCode.NotModified) { res.Status = TestResult.OK; res.ExtraInformation = "Ok - received " + response.StatusCode + " (expected behaviour)"; } } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } return(res); }
public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = "Check completeness response", Status = TestResult.INCONCLUSIVE }; try { var c = SetupWebClient(o); if (OnSetupWebClient != null) { OnSetupWebClient(c); } var watch = new Stopwatch(); watch.Start(); string data = Encoding.UTF8.GetString(c.DownloadData(o.Url + RelativeUrl)); if (data == "[]" || c.StatusCode == HttpStatusCode.NoContent) { res.Status = TestResultWhenNoData.HasValue ? TestResultWhenNoData.Value : TestResult.INCONCLUSIVE; res.ExtraInformation = "NO DATA at " + RelativeUrl; return(res); } watch.Stop(); ResponseData = data; RequestDuration = watch.ElapsedMilliseconds; if (HttpValidationTests.IsValidJson(c.ResponseHeaders) && HttpValidationTests.IsValidCharsetUtf8(c.ResponseHeaders)) { if (FieldsThatShouldBePresent.All(data.Contains)) { res.Status = TestResult.OK; } else { res.Status = TestResult.FAIL; res.ExtraInformation = "Response DTO did not contain all the required fields"; } } else { res.Status = TestResult.FAIL; res.ExtraInformation = "No response header Content-Type. Invalid HTTP"; } } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } finally { res.ExtraInformation += " Url: " + RelativeUrl; } return(res); }