Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions RestAssured.Net.Tests/JsonSchemaValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// </copyright>
namespace RestAssured.Tests
{
using System.Threading.Tasks;
using NJsonSchema;
using NUnit.Framework;
using RestAssured.Response.Exceptions;
Expand Down Expand Up @@ -70,11 +71,11 @@ public void JsonSchemaCanBeSuppliedAndVerifiedAsStringPointingToFile()
/// against a JSON schema supplied as a JsonSchema.
/// </summary>
[Test]
public void JsonSchemaCanBeSuppliedAndVerifiedAsJsonSchema()
public async Task JsonSchemaCanBeSuppliedAndVerifiedAsJsonSchema()
{
this.CreateStubForJsonSchemaValidation();

JsonSchema parsedSchema = JsonSchema.FromJsonAsync(JsonSchemaDefinitions.MatchingJsonSchema).Result;
JsonSchema parsedSchema = await JsonSchema.FromJsonAsync(JsonSchemaDefinitions.MatchingJsonSchema);

Given()
.When()
Expand Down
4 changes: 2 additions & 2 deletions RestAssured.Net/Logging/RequestResponseLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private static void LogRequestBody(HttpRequestMessage request)
return;
}

string requestBodyAsString = request.Content.ReadAsStringAsync().Result;
string requestBodyAsString = request.Content.ReadAsStringAsync().GetAwaiter().GetResult();

if (requestBodyAsString.Equals(string.Empty))
{
Expand Down Expand Up @@ -250,7 +250,7 @@ private static void LogResponseBody(HttpResponseMessage response)
return;
}

string responseBodyAsString = response.Content.ReadAsStringAsync().Result;
string responseBodyAsString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();

if (responseBodyAsString.Equals(string.Empty))
{
Expand Down
16 changes: 7 additions & 9 deletions RestAssured.Net/Request/ExecutableRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@
/// <summary>
/// The request logging level for this request.
/// </summary>
internal Logging.RequestLogLevel RequestLoggingLevel { get; set; }

Check warning on line 69 in RestAssured.Net/Request/ExecutableRequest.cs

View workflow job for this annotation

GitHub Actions / build (9.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 69 in RestAssured.Net/Request/ExecutableRequest.cs

View workflow job for this annotation

GitHub Actions / build (10.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 69 in RestAssured.Net/Request/ExecutableRequest.cs

View workflow job for this annotation

GitHub Actions / build (6.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 69 in RestAssured.Net/Request/ExecutableRequest.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 69 in RestAssured.Net/Request/ExecutableRequest.cs

View workflow job for this annotation

GitHub Actions / build (7.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

/// <summary>
/// The response logging level for this request.
/// </summary>
internal Response.Logging.ResponseLogLevel ResponseLoggingLevel { get; set; }

Check warning on line 74 in RestAssured.Net/Request/ExecutableRequest.cs

View workflow job for this annotation

GitHub Actions / build (9.0.x)

'ResponseLogLevel' is obsolete: 'Use the ResponseLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 74 in RestAssured.Net/Request/ExecutableRequest.cs

View workflow job for this annotation

GitHub Actions / build (10.0.x)

'ResponseLogLevel' is obsolete: 'Use the ResponseLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 74 in RestAssured.Net/Request/ExecutableRequest.cs

View workflow job for this annotation

GitHub Actions / build (6.0.x)

'ResponseLogLevel' is obsolete: 'Use the ResponseLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 74 in RestAssured.Net/Request/ExecutableRequest.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

'ResponseLogLevel' is obsolete: 'Use the ResponseLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 74 in RestAssured.Net/Request/ExecutableRequest.cs

View workflow job for this annotation

GitHub Actions / build (7.0.x)

'ResponseLogLevel' is obsolete: 'Use the ResponseLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

/// <summary>
/// The configuration settings to use when logging request and response details.
Expand Down Expand Up @@ -774,19 +774,17 @@

try
{
Task<VerifiableResponse> task = httpRequestProcessor.Send(this.request, this.cookieCollection, this.httpCompletionOption);
VerifiableResponse verifiableResponse = task.Result;
VerifiableResponse verifiableResponse = httpRequestProcessor.Send(this.request, this.cookieCollection, this.httpCompletionOption).GetAwaiter().GetResult();
verifiableResponse = logger.LogResponse(verifiableResponse);
return verifiableResponse;
}
catch (AggregateException ae)
catch (TaskCanceledException)
{
if (ae.InnerException?.GetType() == typeof(TaskCanceledException))
{
throw new HttpRequestProcessorException($"Request timeout of {this.timeout ?? this.requestSpecification?.Timeout ?? TimeSpan.FromSeconds(100)} exceeded.");
}

throw new HttpRequestProcessorException($"Unhandled exception {ae.Message}");
throw new HttpRequestProcessorException($"Request timeout of {this.timeout ?? this.requestSpecification?.Timeout ?? TimeSpan.FromSeconds(100)} exceeded.");
}
catch (Exception ex)
{
throw new HttpRequestProcessorException($"Unhandled exception {ex.Message}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion RestAssured.Net/Request/Logging/RequestLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@
/// <param name="requestLogLevel">The <see cref="RequestLogLevel"/> to use when logging request details.</param>
/// <param name="cookieCollection">The <see cref="CookieCollection"/> associated with this request.</param>
/// <param name="sensitiveRequestHeadersAndCookies">A list of sensitive request headers and cookies to be masked when logging.</param>
internal static void LogToConsole(HttpRequestMessage request, RequestLogLevel requestLogLevel, CookieCollection cookieCollection, List<string> sensitiveRequestHeadersAndCookies)

Check warning on line 38 in RestAssured.Net/Request/Logging/RequestLogger.cs

View workflow job for this annotation

GitHub Actions / build (9.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 38 in RestAssured.Net/Request/Logging/RequestLogger.cs

View workflow job for this annotation

GitHub Actions / build (10.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 38 in RestAssured.Net/Request/Logging/RequestLogger.cs

View workflow job for this annotation

GitHub Actions / build (6.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 38 in RestAssured.Net/Request/Logging/RequestLogger.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 38 in RestAssured.Net/Request/Logging/RequestLogger.cs

View workflow job for this annotation

GitHub Actions / build (7.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'
{
if (requestLogLevel >= RequestLogLevel.Endpoint)

Check warning on line 40 in RestAssured.Net/Request/Logging/RequestLogger.cs

View workflow job for this annotation

GitHub Actions / build (9.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 40 in RestAssured.Net/Request/Logging/RequestLogger.cs

View workflow job for this annotation

GitHub Actions / build (6.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 40 in RestAssured.Net/Request/Logging/RequestLogger.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 40 in RestAssured.Net/Request/Logging/RequestLogger.cs

View workflow job for this annotation

GitHub Actions / build (7.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'
{
Console.WriteLine($"{request.Method} {request.RequestUri}");
}

if (requestLogLevel == RequestLogLevel.Headers)

Check warning on line 45 in RestAssured.Net/Request/Logging/RequestLogger.cs

View workflow job for this annotation

GitHub Actions / build (9.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 45 in RestAssured.Net/Request/Logging/RequestLogger.cs

View workflow job for this annotation

GitHub Actions / build (6.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 45 in RestAssured.Net/Request/Logging/RequestLogger.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 45 in RestAssured.Net/Request/Logging/RequestLogger.cs

View workflow job for this annotation

GitHub Actions / build (7.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'
{
LogHeaders(request, sensitiveRequestHeadersAndCookies);
LogCookies(cookieCollection, sensitiveRequestHeadersAndCookies);
}

if (requestLogLevel == RequestLogLevel.Body)

Check warning on line 51 in RestAssured.Net/Request/Logging/RequestLogger.cs

View workflow job for this annotation

GitHub Actions / build (9.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 51 in RestAssured.Net/Request/Logging/RequestLogger.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

'RequestLogLevel' is obsolete: 'Use the RequestLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'
{
LogBody(request);
}
Expand Down Expand Up @@ -104,7 +104,7 @@
return;
}

string requestBodyAsString = request.Content.ReadAsStringAsync().Result;
string requestBodyAsString = request.Content.ReadAsStringAsync().GetAwaiter().GetResult();

if (requestBodyAsString.Equals(string.Empty))
{
Expand Down
10 changes: 5 additions & 5 deletions RestAssured.Net/Response/ExtractableResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ExtractableResponse(HttpResponseMessage response, CookieContainer cookieC
[Obsolete("Please use BodyAsString(), BodyAsByteArray() or BodyAsStream() instead. This method is obsolete and will be removed in RestAssured.Net 5.0.0")]
public string Body()
{
return this.response.Content.ReadAsStringAsync().Result;
return this.response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
}

/// <summary>
Expand All @@ -65,7 +65,7 @@ public string Body()
/// <returns>The response body as a string.</returns>
public string BodyAsString()
{
return this.response.Content.ReadAsStringAsync().Result;
return this.response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
}

/// <summary>
Expand All @@ -74,7 +74,7 @@ public string BodyAsString()
/// <returns>The response body as a byte array.</returns>
public byte[] BodyAsByteArray()
{
return this.response.Content.ReadAsByteArrayAsync().Result;
return this.response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult();
}

/// <summary>
Expand All @@ -83,7 +83,7 @@ public byte[] BodyAsByteArray()
/// <returns>The response body as a <see cref="Stream"/>.</returns>
public Stream BodyAsStream()
{
return this.response.Content.ReadAsStreamAsync().Result;
return this.response.Content.ReadAsStreamAsync().GetAwaiter().GetResult();
}

/// <summary>
Expand All @@ -96,7 +96,7 @@ public Stream BodyAsStream()
/// <exception cref="ExtractionException">Thrown when evaluating the JsonPath did not yield any results.</exception>
public object Body(string path, ExtractAs extractAs = ExtractAs.UseResponseContentTypeHeaderValue, ReturnAs returnAs = ReturnAs.Singular)
{
string responseBodyAsString = this.response.Content.ReadAsStringAsync().Result;
string responseBodyAsString = this.response.Content.ReadAsStringAsync().GetAwaiter().GetResult();

string responseMediaType = this.response.Content.Headers.ContentType?.MediaType ?? string.Empty;

Expand Down
2 changes: 1 addition & 1 deletion RestAssured.Net/Response/Logging/ResponseLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/// <param name="responseLogLevel">The <see cref="ResponseLogLevel"/> to use.</param>
/// <param name="sensitiveResponseHeadersAndCookies">A list of sensitive response headers and cookies to be masked when logging.</param>
/// <param name="elapsedTime">The time elapsed between sending a request and returning a response.</param>
internal static void Log(HttpResponseMessage response, CookieContainer cookieContainer, ResponseLogLevel responseLogLevel, List<string> sensitiveResponseHeadersAndCookies, TimeSpan elapsedTime)

Check warning on line 39 in RestAssured.Net/Response/Logging/ResponseLogger.cs

View workflow job for this annotation

GitHub Actions / build (9.0.x)

'ResponseLogLevel' is obsolete: 'Use the ResponseLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 39 in RestAssured.Net/Response/Logging/ResponseLogger.cs

View workflow job for this annotation

GitHub Actions / build (10.0.x)

'ResponseLogLevel' is obsolete: 'Use the ResponseLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 39 in RestAssured.Net/Response/Logging/ResponseLogger.cs

View workflow job for this annotation

GitHub Actions / build (6.0.x)

'ResponseLogLevel' is obsolete: 'Use the ResponseLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 39 in RestAssured.Net/Response/Logging/ResponseLogger.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

'ResponseLogLevel' is obsolete: 'Use the ResponseLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'

Check warning on line 39 in RestAssured.Net/Response/Logging/ResponseLogger.cs

View workflow job for this annotation

GitHub Actions / build (7.0.x)

'ResponseLogLevel' is obsolete: 'Use the ResponseLogLevel enum in the RestAssured.Logging namespace instead. This enum will be removed in RestAssured.Net 5.0.0'
{
if (responseLogLevel == ResponseLogLevel.OnVerificationFailure)
{
Expand Down Expand Up @@ -139,7 +139,7 @@
return;
}

string responseBodyAsString = response.Content.ReadAsStringAsync().Result;
string responseBodyAsString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();

if (responseBodyAsString.Equals(string.Empty))
{
Expand Down
25 changes: 11 additions & 14 deletions RestAssured.Net/Response/VerifiableResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public VerifiableResponse Cookie(string name, IMatcher<string> matcher)
/// <exception cref="ResponseVerificationException">Thrown when the actual response body does not match the expected one.</exception>
public VerifiableResponse Body(string expectedResponseBody)
{
string actualResponseBody = this.Response.Content.ReadAsStringAsync().Result;
string actualResponseBody = this.Response.Content.ReadAsStringAsync().GetAwaiter().GetResult();

if (!actualResponseBody.Equals(expectedResponseBody))
{
Expand All @@ -302,7 +302,7 @@ public VerifiableResponse Body(string expectedResponseBody)
/// <exception cref="ResponseVerificationException">Thrown when the actual response body does not match the expected one.</exception>
public VerifiableResponse Body(IMatcher<string> matcher)
{
string actualResponseBody = this.Response.Content.ReadAsStringAsync().Result;
string actualResponseBody = this.Response.Content.ReadAsStringAsync().GetAwaiter().GetResult();

if (!matcher.Matches(actualResponseBody))
{
Expand All @@ -322,7 +322,7 @@ public VerifiableResponse Body(IMatcher<string> matcher)
/// <returns>The current <see cref="VerifiableResponse"/> object.</returns>
public VerifiableResponse Body<T>(string path, IMatcher<T> matcher, VerifyAs verifyAs = VerifyAs.UseResponseContentTypeHeaderValue)
{
string responseBodyAsString = this.Response.Content.ReadAsStringAsync().Result;
string responseBodyAsString = this.Response.Content.ReadAsStringAsync().GetAwaiter().GetResult();

string? responseMediaType = string.Empty;

Expand Down Expand Up @@ -449,7 +449,7 @@ public VerifiableResponse Body<T>(string path, IMatcher<IEnumerable<T>> matcher,
{
List<T> elementValues = new List<T>();

string responseBodyAsString = this.Response.Content.ReadAsStringAsync().Result;
string responseBodyAsString = this.Response.Content.ReadAsStringAsync().GetAwaiter().GetResult();

string responseMediaType = this.Response.Content.Headers.ContentType?.MediaType ?? string.Empty;

Expand Down Expand Up @@ -538,15 +538,12 @@ public VerifiableResponse MatchesJsonSchema(string jsonSchema)

try
{
JsonSchema parsedSchema = JsonSchema.FromJsonAsync(jsonSchema).Result;
JsonSchema parsedSchema = JsonSchema.FromJsonAsync(jsonSchema).GetAwaiter().GetResult();
return this.MatchesJsonSchema(parsedSchema);
}
catch (AggregateException ae)
catch (JsonException je)
{
foreach (Exception ex in ae.InnerExceptions)
{
this.FailVerification($"Could not parse supplied JSON schema. Error: {ex.Message}");
}
this.FailVerification($"Could not parse supplied JSON schema. Error: {je.Message}");
}

return this;
Expand All @@ -567,7 +564,7 @@ public VerifiableResponse MatchesJsonSchema(JsonSchema jsonSchema)
this.FailVerification($"Expected response Content-Type header to contain 'json', but was '{responseMediaType}'");
}

string responseBodyAsString = this.Response.Content.ReadAsStringAsync().Result;
string responseBodyAsString = this.Response.Content.ReadAsStringAsync().GetAwaiter().GetResult();

ICollection<ValidationError> schemaValidationErrors = jsonSchema.Validate(responseBodyAsString);

Expand Down Expand Up @@ -618,7 +615,7 @@ public VerifiableResponse MatchesXsd(XmlSchemaSet schemas)
settings.ValidationType = ValidationType.Schema;
settings.Schemas = schemas;

string responseXmlAsString = this.Response.Content.ReadAsStringAsync().Result;
string responseXmlAsString = this.Response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
XmlReader reader = XmlReader.Create(new StringReader(responseXmlAsString), settings);

try
Expand Down Expand Up @@ -652,7 +649,7 @@ public VerifiableResponse MatchesInlineDtd()
settings.DtdProcessing = DtdProcessing.Parse;
settings.ValidationType = ValidationType.DTD;

string responseXmlAsString = this.Response.Content.ReadAsStringAsync().Result;
string responseXmlAsString = this.Response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
XmlReader reader = XmlReader.Create(new StringReader(responseXmlAsString), settings);

try
Expand Down Expand Up @@ -691,7 +688,7 @@ public VerifiableResponse ResponseTime(IMatcher<TimeSpan> matcher)
/// <returns>The current <see cref="VerifiableResponse"/> object.</returns>
public VerifiableResponse ResponseBodyLength(IMatcher<int> matcher)
{
string responseContentAsString = this.Response.Content.ReadAsStringAsync().Result;
string responseContentAsString = this.Response.Content.ReadAsStringAsync().GetAwaiter().GetResult();

if (!matcher.Matches(responseContentAsString.Length))
{
Expand Down
Loading