public void Assert(Scenario scenario, ScenarioAssertionException ex) { var values = scenario.Context.Response.Headers[_headerKey]; switch (values.Count) { case 0: ex.Add($"Expected a single header value of '{_headerKey}' matching '{_regex}', but no values were found on the response"); break; case 1: var actual = values.Single(); if (_regex.IsMatch(actual) == false) { ex.Add($"Expected a single header value of '{_headerKey}' matching '{_regex}', but the actual value was '{actual}'"); } break; default: var valueText = string.Join(",", values.Select(x => "'" + x + "'")); ex.Add($"Expected a single header value of '{_headerKey}' matching '{_regex}', but the actual values were {valueText}"); break; } }
public void Assert(Scenario scenario, HttpContext context, ScenarioAssertionException ex) { if (context.Response is StubHttpResponse response) { if (!string.Equals(response.RedirectedTo, Expected, StringComparison.OrdinalIgnoreCase)) { ex.Add($"Expected to be redirected to '{Expected}' but was '{response.RedirectedTo}'."); } if (Permanent != response.RedirectedPermanent) { ex.Add($"Expected permanent redirect to be '{Permanent}' but it was not."); } } else { var location = context.Response.Headers["Location"]; if (!string.Equals(location, Expected, StringComparison.OrdinalIgnoreCase)) { ex.Add($"Expected to be redirected to '{Expected}' but was '{location}'."); } if (Permanent && context.Response.StatusCode != 301) { ex.Add($"Expected permanent redirect to be '{Permanent}' but it was not."); } } }
public void all_messages_are_in_the_ex_message() { var ex = new ScenarioAssertionException(); ex.Add("You stink!"); ex.Add("You missed a header!"); ex.Message.ShouldContain("You stink!"); ex.Message.ShouldContain("You missed a header!"); }
/// <summary> /// Assert Override for Alba GraphQL Extension Scenario /// </summary> /// <param name="scenario"></param> /// <param name="context"></param> /// <param name="ex">Assertion Exception</param> public override void Assert(Scenario scenario, HttpContext context, ScenarioAssertionException ex) { var writer = new DocumentWriter(); var expectedResult = writer.WriteToStringAsync(CreateQueryResult(_result)).GetAwaiter().GetResult(); var body = ex.ReadBody(context); if (!body.Equals(expectedResult)) { if (_ignoreExtensions) { try { var json = JObject.Parse(body, new JsonLoadSettings() { CommentHandling = CommentHandling.Ignore, LineInfoHandling = LineInfoHandling.Ignore }); JToken token; // Verify the property data appears in the payload if (json.HasValues && json.TryGetValue("data", out token)) { // convert to string and remove formatting var data = token.ToString(Newtonsoft.Json.Formatting.None); // Add the data structure as expected from the data payload var bodyWithoutExtensions = @"{""data"":" + data + "}"; if (bodyWithoutExtensions.Equals(expectedResult)) { return; } else { ex.Add($"Expected '{expectedResult}' but got '{bodyWithoutExtensions}'"); } } } catch { //Handle the case when can't parje the json object ex.Add("Unable to parse jsonObject. " + ex.Message); return; } } else { ex.Add($"Expected '{expectedResult}' but got '{body}'"); } } }
public void Assert(Scenario scenario, ScenarioAssertionException ex) { var response = scenario.Context.Response.As <StubHttpResponse>(); if (!string.Equals(response.RedirectedTo, Expected, StringComparison.OrdinalIgnoreCase)) { ex.Add($"Expected to be redirected to '{Expected}' but was '{response.RedirectedTo}'."); } if (Permanent != response.RedirectedPermanent) { ex.Add($"Expected permanent redirect to be '{Permanent}' but it was not."); } }
public override void Assert(Scenario scenario, HttpContext context, ScenarioAssertionException ex) { var expectedResult = CreateQueryResult(_result); // for Alba v4 // string actualResultJson = ex.ReadBody(context); // for Alba v6 [ScenarioAssertionException.ReadBody internal] context.Request.Body.Position = 0; string actualResultJson = new StreamReader(context.Response.Body).ReadToEnd(); if (_ignoreExtensions) { expectedResult.Extensions = null; var actualResult = actualResultJson.ToDictionary(); if (actualResult.ContainsKey(extensionsKey)) { actualResult.Remove(extensionsKey); } actualResultJson = _writer.Serialize(actualResult); } string expectedResultJson = _writer.Serialize(expectedResult); if (!actualResultJson.Equals(expectedResultJson)) { ex.Add($"Expected '{expectedResultJson}' but got '{actualResultJson}'"); } }
public void assert_with_any_messages_blows_up() { var ex = new ScenarioAssertionException(); ex.Add("You stink!"); Exception <ScenarioAssertionException> .ShouldBeThrownBy(() => ex.AssertAll()); }
public void Assert(Scenario scenario, ScenarioAssertionException ex) { var body = ex.ReadBody(scenario); if (body.Contains(Text)) { ex.Add($"Text '{Text}' should not be found in the response body"); } }
public void Assert(Scenario scenario, ScenarioAssertionException ex) { var body = ex.ReadBody(scenario); if (!body.Contains(Text)) { ex.Add($"Expected text '{Text}' was not found in the response body"); } }
public override void Assert(Scenario scenario, HttpContext context, ScenarioAssertionException ex) { var body = ex.ReadBody(context); if (!body.Contains(_result)) { ex.Add($"Expected to find '{_result}' but got '{body}'"); } }
public void Assert(Scenario scenario, ScenarioAssertionException ex) { var body = ex.ReadBody(scenario); if (!body.Equals(Text)) { ex.Add($"Expected the content to be '{Text}'"); } }
public void Assert(Scenario scenario, HttpContext context, ScenarioAssertionException ex) { var values = context.Response.Headers[_headerKey]; var expectedText = _expected.Select(x => "'" + x + "'").Join(", "); switch (values.Count) { case 0: ex.Add($"Expected header values of '{_headerKey}'={expectedText}, but no values were found on the response."); break; default: if (!_expected.All(x => values.Contains(x))) { var valueText = values.Select(x => "'" + x + "'").Join(", "); ex.Add($"Expected header values of '{_headerKey}'={expectedText}, but the actual values were {valueText}."); } break; } }
public void Assert(Scenario scenario, ScenarioAssertionException ex) { var body = ex.ReadBody(scenario); if (!body.Contains(Text)) { // Add the failure message to the exception. This exception only // gets thrown if there are failures. ex.Add($"Expected text '{Text}' was not found in the response body"); } }
public void Assert(Scenario scenario, ScenarioAssertionException ex) { var statusCode = scenario.Context.Response.StatusCode; if (statusCode != Expected) { ex.Add($"Expected status code {Expected}, but was {statusCode}"); ex.ShowActualBodyInErrorMessage(scenario); } }
public override void Assert(Scenario scenario, HttpContext context, ScenarioAssertionException ex) { var writer = new DocumentWriter(); var expectedResult = writer.WriteToStringAsync(CreateQueryResult(_result)).GetAwaiter().GetResult(); var body = ex.ReadBody(context); if (!body.Equals(expectedResult)) { ex.Add($"Expected '{expectedResult}' but got '{body}'"); } }
public void Assert(Scenario scenario, ScenarioAssertionException ex) { var values = scenario.Context.Response.Headers[_headerKey]; switch (values.Count) { case 0: ex.Add( $"Expected a single header value of '{_headerKey}', but no values were found on the response"); break; case 1: // nothing, thats' good;) break; default: var valueText = values.Select(x => "'" + x + "'").Join(", "); ex.Add($"Expected a single header value of '{_headerKey}', but found multiple values on the response: {valueText}"); break; } }
public override void Assert(Scenario scenario, ScenarioAssertionException ex) { var writer = (IDocumentWriter)scenario.Context.RequestServices.GetService(typeof(IDocumentWriter)); var expectedResult = writer.WriteToStringAsync(CreateQueryResult(_result)).GetAwaiter().GetResult(); var body = ex.ReadBody(scenario); if (!body.Equals(expectedResult)) { ex.Add($"Expected '{expectedResult}' but got '{body}'"); } }
public void show_the_body_in_the_message_if_set() { var ex = new ScenarioAssertionException(); ex.Add("You stink!"); ex.Message.ShouldNotContain("Actual body text was:"); ex.Body = "<html></html>"; ex.Message.ShouldContain("Actual body text was:"); ex.Message.ShouldContain(ex.Body); }
public void Assert(Scenario scenario, HttpContext context, ScenarioAssertionException ex) { var values = context.Response.Headers[_headerKey]; switch (values.Count) { case 0: ex.Add($"Expected a single header value of '{_headerKey}'='{_expected}', but no values were found on the response"); break; case 1: var actual = values.Single(); if (actual != _expected) { ex.Add($"Expected a single header value of '{_headerKey}'='{_expected}', but the actual value was '{actual}'"); } break; default: var valueText = values.Select(x => "'" + x + "'").Join(", "); ex.Add($"Expected a single header value of '{_headerKey}'='{_expected}', but the actual values were {valueText}"); break; } }
public override void Assert(Scenario scenario, HttpContext context, ScenarioAssertionException ex) { var writer = new DocumentWriter(); var expectedResult = writer.WriteToStringAsync(CreateQueryResult(_result)).GetAwaiter().GetResult(); var body = ex.ReadBody(context); if (!body.Equals(expectedResult)) { if (_ignoreExtensions) { var json = JObject.Parse(body); json.Remove("extensions"); var bodyWithoutExtensions = json.ToString(Newtonsoft.Json.Formatting.None); if (bodyWithoutExtensions.Equals(expectedResult)) { return; } } ex.Add($"Expected '{expectedResult}' but got '{body}'"); } }
public override void Assert(Scenario scenario, HttpContext context, ScenarioAssertionException ex) { var expectedResult = CreateQueryResult(_result); var actualResultJson = ex.ReadBody(context); if (_ignoreExtensions) { expectedResult.Extensions = null; var actualResult = actualResultJson.ToDictionary(); if (actualResult.ContainsKey(extensionsKey)) { actualResult.Remove(extensionsKey); } actualResultJson = _writer.WriteToStringAsync(actualResult).GetAwaiter().GetResult(); } var expectedResultJson = _writer.WriteToStringAsync(expectedResult).GetAwaiter().GetResult(); if (!actualResultJson.Equals(expectedResultJson)) { ex.Add($"Expected '{expectedResult}' but got '{actualResultJson}'"); } }