diff --git a/STX.REST.RESTFulSense.Clients/Services/Foundations/HttpExchanges/HttpExchangeService.Exceptions.cs b/STX.REST.RESTFulSense.Clients/Services/Foundations/HttpExchanges/HttpExchangeService.Exceptions.cs index 9cec33e..4f2b69b 100644 --- a/STX.REST.RESTFulSense.Clients/Services/Foundations/HttpExchanges/HttpExchangeService.Exceptions.cs +++ b/STX.REST.RESTFulSense.Clients/Services/Foundations/HttpExchanges/HttpExchangeService.Exceptions.cs @@ -24,22 +24,22 @@ private static async ValueTask TryCatch( } catch (InvalidHttpExchangeException invalidHttpExchangeException) { - throw CreateHttpExchangeValidationException( + throw await CreateHttpExchangeValidationExceptionAsync( exception: invalidHttpExchangeException); } catch (NullHttpExchangeRequestException nullHttpExchangeRequestException) { - throw CreateHttpExchangeValidationException( + throw await CreateHttpExchangeValidationExceptionAsync( exception: nullHttpExchangeRequestException); } catch (InvalidHttpExchangeRequestException invalidHttpExchangeRequestException) { - throw CreateHttpExchangeValidationException( + throw await CreateHttpExchangeValidationExceptionAsync( invalidHttpExchangeRequestException); } catch (InvalidHttpExchangeRequestHeaderException invalidHttpExchangeHeaderException) { - throw CreateHttpExchangeValidationException( + throw await CreateHttpExchangeValidationExceptionAsync( invalidHttpExchangeHeaderException); } catch (HttpRequestException httpRequestException) @@ -49,7 +49,7 @@ private static async ValueTask TryCatch( message: "Failed http request error occurred, contact support.", innerException: httpRequestException); - throw CreateHttpExchangeDependencyException( + throw await CreateHttpExchangeDependencyExceptionAsync( failedHttpExchangeRequestException); } catch (TaskCanceledException taskCanceledException) @@ -59,7 +59,7 @@ private static async ValueTask TryCatch( message: "Request timeout error occurred, please contact support.", innerException: taskCanceledException); - throw CreateHttpExchangeDependencyException( + throw await CreateHttpExchangeDependencyExceptionAsync( taskCanceledHttpExchangeException); } catch (ObjectDisposedException objectDisposedException) @@ -69,7 +69,7 @@ private static async ValueTask TryCatch( message: "Object already disposed error occurred, please fix errors and try again.", innerException: objectDisposedException); - throw CreateHttpExchangeDependencyException( + throw await CreateHttpExchangeDependencyExceptionAsync( objectDisposedHttpExchangeException); } catch (InvalidOperationException invalidOperationException) @@ -79,7 +79,7 @@ private static async ValueTask TryCatch( message: "Invalid http request operation error occurred, please contact support.", innerException: invalidOperationException); - throw CreateHttpExchangeDependencyException( + throw await CreateHttpExchangeDependencyExceptionAsync( invalidOperationHttpExchangeException); } catch (ArgumentException argumentException) @@ -89,7 +89,7 @@ private static async ValueTask TryCatch( message: "Invalid argument error occurred, contact support.", innerException: argumentException); - throw CreateHttpExchangeDependencyException( + throw await CreateHttpExchangeDependencyExceptionAsync( invalidArgumentHttpExchangeException); } catch (FormatException formatException) @@ -99,7 +99,7 @@ private static async ValueTask TryCatch( message: "Invalid format error occurred, contact support.", innerException: formatException); - throw CreateHttpExchangeDependencyException( + throw await CreateHttpExchangeDependencyExceptionAsync( invalidFormatHttpExchangeException); } catch (Exception serviceException) @@ -109,12 +109,12 @@ private static async ValueTask TryCatch( message: "Failed HttpExchange service error occurred, contact support.", innerException: serviceException); - throw CreateHttpExchangeServiceException( + throw await CreateHttpExchangeServiceExceptionAsync( failedHttpExchangeServiceException); } } - private static HttpExchangeValidationException CreateHttpExchangeValidationException( + private static async ValueTask CreateHttpExchangeValidationExceptionAsync( Xeption exception) { return new HttpExchangeValidationException( @@ -122,7 +122,7 @@ private static HttpExchangeValidationException CreateHttpExchangeValidationExcep innerException: exception); } - private static HttpExchangeDependencyException CreateHttpExchangeDependencyException( + private static async ValueTask CreateHttpExchangeDependencyExceptionAsync( Xeption exception) { return new HttpExchangeDependencyException( @@ -130,7 +130,7 @@ private static HttpExchangeDependencyException CreateHttpExchangeDependencyExcep innerException: exception); } - private static HttpExchangeServiceException CreateHttpExchangeServiceException( + private static async ValueTask CreateHttpExchangeServiceExceptionAsync( Xeption exception) { return new HttpExchangeServiceException( diff --git a/STX.REST.RESTFulSense.Clients/Services/Foundations/HttpExchanges/HttpExchangeService.Validations.Headers.cs b/STX.REST.RESTFulSense.Clients/Services/Foundations/HttpExchanges/HttpExchangeService.Validations.Headers.cs index bc0c93b..fafaca8 100644 --- a/STX.REST.RESTFulSense.Clients/Services/Foundations/HttpExchanges/HttpExchangeService.Validations.Headers.cs +++ b/STX.REST.RESTFulSense.Clients/Services/Foundations/HttpExchanges/HttpExchangeService.Validations.Headers.cs @@ -4,6 +4,7 @@ using System; using System.Linq; +using System.Threading.Tasks; using STX.REST.RESTFulSense.Clients.Models.Services.HttpExchanges; using STX.REST.RESTFulSense.Clients.Models.Services.HttpExchanges.Exceptions; using STX.REST.RESTFulSense.Clients.Models.Services.HttpExchanges.Headers; @@ -153,41 +154,41 @@ private static bool IsInvalidWarningHeader(WarningHeader warningHeader) || String.IsNullOrWhiteSpace(warningHeader.Text)); } - private static dynamic IsInvalidAcceptHeader(MediaTypeHeader[] mediaTypeHeaders) => new + private static async ValueTask IsInvalidAcceptHeaderAsync(MediaTypeHeader[] mediaTypeHeaders) => new { Condition = IsInvalidMediaTypeHeaderArray(mediaTypeHeaders), Message = "Accept header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidAcceptCharsetHeader( + private static async ValueTask IsInvalidAcceptCharsetHeaderAsync( StringWithQualityHeader[] stringWithQualityHeaders) => new { Condition = IsInvalidStringWithQualityHeaderArray(stringWithQualityHeaders), Message = "AcceptCharset header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidAcceptEncodingHeader( + private static async ValueTask IsInvalidAcceptEncodingHeaderAsync( StringWithQualityHeader[] stringWithQualityHeaders) => new { Condition = IsInvalidStringWithQualityHeaderArray(stringWithQualityHeaders), Message = "AcceptEncoding header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidAcceptLanguageHeader( + private static async ValueTask IsInvalidAcceptLanguageHeaderAsync( StringWithQualityHeader[] stringWithQualityHeaders) => new { Condition = IsInvalidStringWithQualityHeaderArray(stringWithQualityHeaders), Message = "AcceptLanguage header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidAuthorizationHeader( + private static async ValueTask IsInvalidAuthorizationHeaderAsync( AuthenticationHeader authenticationHeader) => new { Condition = IsInvalidAuthenticationHeader(authenticationHeader), Message = "Authorization header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidCacheControlHeader( + private static async ValueTask IsInvalidCacheControlHeaderAsync( CacheControlHeader cacheControlHeader) => new { Condition = cacheControlHeader is not null @@ -198,21 +199,21 @@ private static dynamic IsInvalidCacheControlHeader( Message = "CacheControl header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidConnectionHeader( + private static async ValueTask IsInvalidConnectionHeaderAsync( string[] connectionHeader) => new { Condition = IsInvalidStringArray(connectionHeader), Message = "Connection header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidExpectHeader( + private static async ValueTask IsInvalidExpectHeaderAsync( NameValueWithParametersHeader[] expectHeader) => new { Condition = IsInvalidNameValueWithParametersHeaderArray(expectHeader), Message = "Expect header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidFromHeader( + private static async ValueTask IsInvalidFromHeaderAsync( string fromHeader) => new { Condition = fromHeader is not null @@ -221,7 +222,7 @@ private static dynamic IsInvalidFromHeader( Message = "From header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidHostHeader( + private static async ValueTask IsInvalidHostHeaderAsync( string hostHeader) => new { Condition = hostHeader is not null @@ -230,21 +231,21 @@ private static dynamic IsInvalidHostHeader( Message = "Host header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidIfMatchHeader( + private static async ValueTask IsInvalidIfMatchHeaderAsync( string[] ifMatchHeader) => new { Condition = IsInvalidStringArray(ifMatchHeader), Message = "IfMatch header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidIfNoneMatchHeader( + private static async ValueTask IsInvalidIfNoneMatchHeaderAsync( string[] ifMatchHeader) => new { Condition = IsInvalidStringArray(ifMatchHeader), Message = "IfNoneMatch header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidIfRangeHeader(RangeConditionHeader rangeConditionHeader) => new + private static async ValueTask IsInvalidIfRangeHeaderAsync(RangeConditionHeader rangeConditionHeader) => new { Condition = rangeConditionHeader is not null @@ -257,13 +258,13 @@ rangeConditionHeader is not null "Only one of either date or entityTag can be set at a time. Please fix the errors and try again." }; - private static dynamic IsInvalidPragmaHeader(NameValueHeader[] nameValueHeaders) => new + private static async ValueTask IsInvalidPragmaHeaderAsync(NameValueHeader[] nameValueHeaders) => new { Condition = IsInvalidNameValueHeaderArray(nameValueHeaders), Message = "Pragma header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidProtocolHeader( + private static async ValueTask IsInvalidProtocolHeaderAsync( string protocolHeader) => new { Condition = protocolHeader is not null @@ -272,14 +273,14 @@ private static dynamic IsInvalidProtocolHeader( Message = "Protocol header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidProxyAuthorizationHeader( + private static async ValueTask IsInvalidProxyAuthorizationHeaderAsync( AuthenticationHeader authenticationHeader) => new { Condition = IsInvalidAuthenticationHeader(authenticationHeader), Message = "ProxyAuthorization header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidRangeHeader( + private static async ValueTask IsInvalidRangeHeaderAsync( RangeHeader rangeHeader) => new { Condition = rangeHeader is not null @@ -289,26 +290,28 @@ private static dynamic IsInvalidRangeHeader( Message = "Range header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidTEHeader(TransferCodingHeader[] transferCodingHeaders) => new + private static async ValueTask IsInvalidTEHeaderAsync( + TransferCodingHeader[] transferCodingHeaders) => new { Condition = IsInvalidTransferCodingHeaderArray(transferCodingHeaders), Message = "TE header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidTrailerHeader( + private static async ValueTask IsInvalidTrailerHeaderAsync( string[] trailerHeader) => new { Condition = IsInvalidStringArray(trailerHeader), Message = "Trailer header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidTransferEncodingHeaderArray(TransferCodingHeader[] transferCodingHeaders) => new + private static async ValueTask IsInvalidTransferEncodingHeaderArrayAsync( + TransferCodingHeader[] transferCodingHeaders) => new { Condition = IsInvalidTransferCodingHeaderArray(transferCodingHeaders), Message = "TransferEncoding header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidUpgradeHeaderArray(ProductHeader[] productHeaders) => new + private static async ValueTask IsInvalidUpgradeHeaderArrayAsync(ProductHeader[] productHeaders) => new { Condition = productHeaders is not null && productHeaders.Any(header => header is null @@ -317,7 +320,8 @@ private static dynamic IsInvalidTrailerHeader( Message = "Upgrade header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidUserAgentHeaderArray(ProductInfoHeader[] productInfoHeaders) => new + private static async ValueTask IsInvalidUserAgentHeaderArrayAsync( + ProductInfoHeader[] productInfoHeaders) => new { Condition = productInfoHeaders is not null && productInfoHeaders.Any(header => header is null @@ -326,7 +330,7 @@ private static dynamic IsInvalidTrailerHeader( Message = "UserAgent header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidViaHeaderArray(ViaHeader[] viaHeaders) => new + private static async ValueTask IsInvalidViaHeaderArrayAsync(ViaHeader[] viaHeaders) => new { Condition = viaHeaders is not null && viaHeaders.Any(header => header is null @@ -335,7 +339,8 @@ private static dynamic IsInvalidTrailerHeader( Message = "Via header has invalid configuration, fix errors and try again." }; - private static dynamic IsInvalidWarningHeaderArray(WarningHeader[] warningHeaders) => new + private static async ValueTask IsInvalidWarningHeaderArrayAsync( + WarningHeader[] warningHeaders) => new { Condition = warningHeaders is not null && warningHeaders.Any(header => header is null @@ -344,88 +349,88 @@ private static dynamic IsInvalidTrailerHeader( Message = "Warning header has invalid configuration, fix errors and try again." }; - private static void ValidateHttpExchangeRequestHeaders( + private static async ValueTask ValidateHttpExchangeRequestHeadersAsync( HttpExchangeRequestHeaders httpExchangeRequestHeaders) { if (httpExchangeRequestHeaders is null) return; - ValidateHttpRequestHeaders( - (Rule: IsInvalidAcceptHeader(httpExchangeRequestHeaders.Accept), + await ValidateHttpRequestHeadersAsync( + (Rule: await IsInvalidAcceptHeaderAsync(httpExchangeRequestHeaders.Accept), Parameter: nameof(HttpExchangeRequestHeaders.Accept)), - (Rule: IsInvalidAcceptCharsetHeader(httpExchangeRequestHeaders.AcceptCharset), + (Rule: await IsInvalidAcceptCharsetHeaderAsync(httpExchangeRequestHeaders.AcceptCharset), Parameter: nameof(HttpExchangeRequestHeaders.AcceptCharset)), - (Rule: IsInvalidAcceptEncodingHeader(httpExchangeRequestHeaders.AcceptEncoding), + (Rule: await IsInvalidAcceptEncodingHeaderAsync(httpExchangeRequestHeaders.AcceptEncoding), Parameter: nameof(HttpExchangeRequestHeaders.AcceptEncoding)), - (Rule: IsInvalidAcceptLanguageHeader(httpExchangeRequestHeaders.AcceptLanguage), + (Rule: await IsInvalidAcceptLanguageHeaderAsync(httpExchangeRequestHeaders.AcceptLanguage), Parameter: nameof(HttpExchangeRequestHeaders.AcceptLanguage)), - (Rule: IsInvalidAuthorizationHeader(httpExchangeRequestHeaders.Authorization), + (Rule: await IsInvalidAuthorizationHeaderAsync(httpExchangeRequestHeaders.Authorization), Parameter: nameof(HttpExchangeRequestHeaders.Authorization)), - (Rule: IsInvalidCacheControlHeader(httpExchangeRequestHeaders.CacheControl), + (Rule: await IsInvalidCacheControlHeaderAsync(httpExchangeRequestHeaders.CacheControl), Parameter: nameof(HttpExchangeRequestHeaders.CacheControl)), - (Rule: IsInvalidConnectionHeader(httpExchangeRequestHeaders.Connection), + (Rule: await IsInvalidConnectionHeaderAsync(httpExchangeRequestHeaders.Connection), Parameter: nameof(HttpExchangeRequestHeaders.Connection)), - (Rule: IsInvalidExpectHeader(httpExchangeRequestHeaders.Expect), + (Rule: await IsInvalidExpectHeaderAsync(httpExchangeRequestHeaders.Expect), Parameter: nameof(HttpExchangeRequestHeaders.Expect)), - (Rule: IsInvalidFromHeader(httpExchangeRequestHeaders.From), + (Rule: await IsInvalidFromHeaderAsync(httpExchangeRequestHeaders.From), Parameter: nameof(HttpExchangeRequestHeaders.From)), - (Rule: IsInvalidHostHeader(httpExchangeRequestHeaders.Host), + (Rule: await IsInvalidHostHeaderAsync(httpExchangeRequestHeaders.Host), Parameter: nameof(HttpExchangeRequestHeaders.Host)), - (Rule: IsInvalidIfMatchHeader(httpExchangeRequestHeaders.IfMatch), + (Rule: await IsInvalidIfMatchHeaderAsync(httpExchangeRequestHeaders.IfMatch), Parameter: nameof(HttpExchangeRequestHeaders.IfMatch)), - (Rule: IsInvalidIfNoneMatchHeader(httpExchangeRequestHeaders.IfNoneMatch), + (Rule: await IsInvalidIfNoneMatchHeaderAsync(httpExchangeRequestHeaders.IfNoneMatch), Parameter: nameof(HttpExchangeRequestHeaders.IfNoneMatch)), - (Rule: IsInvalidIfRangeHeader(httpExchangeRequestHeaders.IfRange), + (Rule: await IsInvalidIfRangeHeaderAsync(httpExchangeRequestHeaders.IfRange), Parameter: nameof(HttpExchangeRequestHeaders.IfRange)), - (Rule: IsInvalidPragmaHeader(httpExchangeRequestHeaders.Pragma), + (Rule: await IsInvalidPragmaHeaderAsync(httpExchangeRequestHeaders.Pragma), Parameter: nameof(HttpExchangeRequestHeaders.Pragma)), - (Rule: IsInvalidProtocolHeader(httpExchangeRequestHeaders.Protocol), + (Rule: await IsInvalidProtocolHeaderAsync(httpExchangeRequestHeaders.Protocol), Parameter: nameof(HttpExchangeRequestHeaders.Protocol)), - (Rule: IsInvalidProxyAuthorizationHeader(httpExchangeRequestHeaders.ProxyAuthorization), + (Rule: await IsInvalidProxyAuthorizationHeaderAsync(httpExchangeRequestHeaders.ProxyAuthorization), Parameter: nameof(HttpExchangeRequestHeaders.ProxyAuthorization)), - (Rule: IsInvalidRangeHeader(httpExchangeRequestHeaders.Range), + (Rule: await IsInvalidRangeHeaderAsync(httpExchangeRequestHeaders.Range), Parameter: nameof(HttpExchangeRequestHeaders.Range)), - (Rule: IsInvalidTEHeader(httpExchangeRequestHeaders.TE), + (Rule: await IsInvalidTEHeaderAsync(httpExchangeRequestHeaders.TE), Parameter: nameof(HttpExchangeRequestHeaders.TE)), - (Rule: IsInvalidTrailerHeader(httpExchangeRequestHeaders.Trailer), + (Rule: await IsInvalidTrailerHeaderAsync(httpExchangeRequestHeaders.Trailer), Parameter: nameof(HttpExchangeRequestHeaders.Trailer)), - (Rule: IsInvalidTransferEncodingHeaderArray(httpExchangeRequestHeaders.TransferEncoding), + (Rule: await IsInvalidTransferEncodingHeaderArrayAsync(httpExchangeRequestHeaders.TransferEncoding), Parameter: nameof(HttpExchangeRequestHeaders.TransferEncoding)), - (Rule: IsInvalidUpgradeHeaderArray(httpExchangeRequestHeaders.Upgrade), + (Rule: await IsInvalidUpgradeHeaderArrayAsync(httpExchangeRequestHeaders.Upgrade), Parameter: nameof(HttpExchangeRequestHeaders.Upgrade)), - (Rule: IsInvalidUserAgentHeaderArray(httpExchangeRequestHeaders.UserAgent), + (Rule: await IsInvalidUserAgentHeaderArrayAsync(httpExchangeRequestHeaders.UserAgent), Parameter: nameof(HttpExchangeRequestHeaders.UserAgent)), - (Rule: IsInvalidViaHeaderArray(httpExchangeRequestHeaders.Via), + (Rule: await IsInvalidViaHeaderArrayAsync(httpExchangeRequestHeaders.Via), Parameter: nameof(HttpExchangeRequestHeaders.Via)), - (Rule: IsInvalidWarningHeaderArray(httpExchangeRequestHeaders.Warning), - Parameter: nameof(HttpExchangeRequestHeaders.Warning)) - ); + (Rule: await IsInvalidWarningHeaderArrayAsync(httpExchangeRequestHeaders.Warning), + Parameter: nameof(HttpExchangeRequestHeaders.Warning))); } - private static void ValidateHttpRequestHeaders(params (dynamic Rule, string Parameter)[] validations) + private static async ValueTask ValidateHttpRequestHeadersAsync( + params (dynamic Rule, string Parameter)[] validations) { var invalidHttpExchangeHeaderException = new InvalidHttpExchangeRequestHeaderException( diff --git a/STX.REST.RESTFulSense.Clients/Services/Foundations/HttpExchanges/HttpExchangeService.Validations.cs b/STX.REST.RESTFulSense.Clients/Services/Foundations/HttpExchanges/HttpExchangeService.Validations.cs index a218f68..9d7057d 100644 --- a/STX.REST.RESTFulSense.Clients/Services/Foundations/HttpExchanges/HttpExchangeService.Validations.cs +++ b/STX.REST.RESTFulSense.Clients/Services/Foundations/HttpExchanges/HttpExchangeService.Validations.cs @@ -5,6 +5,7 @@ using System; using System.Net; using System.Net.Http; +using System.Threading.Tasks; using STX.REST.RESTFulSense.Clients.Models.Services.HttpExchanges; using STX.REST.RESTFulSense.Clients.Models.Services.HttpExchanges.Exceptions; @@ -12,66 +13,67 @@ namespace STX.REST.RESTFulSense.Clients.Services.Foundations.HttpExchanges { internal partial class HttpExchangeService { - private static void ValidateOnGet( + private static async ValueTask ValidateOnGetAsync( HttpExchange httpExchange, HttpMethod defaultHttpMethod, Version defaultHttpVersion, HttpVersionPolicy defaultHttpVersionPolicy) { - Validate( - (Rule: IsInvalid(httpExchange), Parameter: nameof(HttpExchange)), - (Rule: IsInvalid(defaultHttpMethod), Parameter: nameof(HttpMethod)), - (Rule: IsInvalid(defaultHttpVersion), Parameter: nameof(Version)), - (Rule: IsInvalid(defaultHttpVersionPolicy), Parameter: nameof(HttpVersionPolicy))); + await ValidateAsync( + (Rule: await IsInvalidAsync(httpExchange), Parameter: nameof(HttpExchange)), + (Rule: await IsInvalidAsync(defaultHttpMethod), Parameter: nameof(HttpMethod)), + (Rule: await IsInvalidAsync(defaultHttpVersion), Parameter: nameof(Version)), + (Rule: await IsInvalidAsync(defaultHttpVersionPolicy), Parameter: nameof(HttpVersionPolicy))); - ValidateHttpExchange( + await ValidateHttpExchangeAsync( httpExchange, defaultHttpMethod, defaultHttpVersion, defaultHttpVersionPolicy); } - private static void ValidateHttpExchange( + private static async ValueTask ValidateHttpExchangeAsync( HttpExchange httpExchange, HttpMethod httpMethod, Version httpVersion, HttpVersionPolicy httpVersionPolicy) { - ValidateHttpExchangeRequest( + await ValidateHttpExchangeRequestAsync( httpExchangeRequest: httpExchange.Request, httpMethod, httpVersion, httpVersionPolicy); } - private static void ValidateHttpExchangeRequest( + private static async ValueTask ValidateHttpExchangeRequestAsync( HttpExchangeRequest httpExchangeRequest, HttpMethod httpMethod, Version httpVersion, HttpVersionPolicy httpVersionPolicy) { - ValidateHttpExchangeRequestNotNull(httpExchangeRequest); + await ValidateHttpExchangeRequestNotNullAsync(httpExchangeRequest); - ValidateHttpExchangeRequestObject( - (Rule: IsInvalid(httpExchangeRequest.BaseAddress), + await ValidateHttpExchangeRequestObjectAsync( + (Rule: await IsInvalidAsync(httpExchangeRequest.BaseAddress), Parameter: nameof(HttpExchangeRequest.BaseAddress)), - (Rule: IsInvalid(httpExchangeRequest.RelativeUrl), + (Rule: await IsInvalidAsync(httpExchangeRequest.RelativeUrl), Parameter: nameof(HttpExchangeRequest.RelativeUrl)), - (Rule: IsInvalidHttpMethod(httpExchangeRequest.HttpMethod, httpMethod), + (Rule: await IsInvalidHttpMethodAsync(httpExchangeRequest.HttpMethod, httpMethod), Parameter: nameof(HttpExchangeRequest.HttpMethod)), - (Rule: IsInvalidHttpVersion(httpExchangeRequest.Version, httpVersion), + (Rule: await IsInvalidHttpVersionAsync(httpExchangeRequest.Version, httpVersion), Parameter: nameof(HttpExchangeRequest.Version)), - (Rule: IsInvalidHttpVersionPolicy(httpExchangeRequest.VersionPolicy, httpVersionPolicy), + (Rule: await IsInvalidHttpVersionPolicyAsync(httpExchangeRequest.VersionPolicy, httpVersionPolicy), Parameter: nameof(HttpExchangeRequest.VersionPolicy))); - ValidateHttpExchangeRequestHeaders(httpExchangeRequestHeaders: httpExchangeRequest.Headers); + await ValidateHttpExchangeRequestHeadersAsync(httpExchangeRequestHeaders: httpExchangeRequest.Headers); } - private static void ValidateHttpExchangeRequestNotNull(HttpExchangeRequest httpExchangeRequest) + private static async ValueTask ValidateHttpExchangeRequestNotNullAsync( + HttpExchangeRequest httpExchangeRequest) { if (httpExchangeRequest is null) { @@ -80,21 +82,22 @@ private static void ValidateHttpExchangeRequestNotNull(HttpExchangeRequest httpE } } - private static dynamic IsInvalid(object @object) => + private static async ValueTask IsInvalidAsync(object @object) => new { Condition = @object is null, Message = "Value is required" }; - private static dynamic IsInvalid(string text) => + private static async ValueTask IsInvalidAsync(string text) => new { Condition = String.IsNullOrWhiteSpace(text), Message = "Value is required" }; - private static dynamic IsInvalidHttpMethod(string customHttpMethod, HttpMethod defaultHttpMethod) => + private static async ValueTask IsInvalidHttpMethodAsync( + string customHttpMethod, HttpMethod defaultHttpMethod) => new { Condition = @@ -107,7 +110,8 @@ private static dynamic IsInvalidHttpMethod(string customHttpMethod, HttpMethod d Message = "HttpMethod is invalid" }; - private static dynamic IsInvalidHttpVersion(string customHttpVersion, Version defaultHttpVersion) => + private static async ValueTask IsInvalidHttpVersionAsync( + string customHttpVersion, Version defaultHttpVersion) => new { Condition = @@ -125,7 +129,7 @@ private static dynamic IsInvalidHttpVersion(string customHttpVersion, Version de Message = "HttpVersion is invalid" }; - private static dynamic IsInvalidHttpVersionPolicy( + private static async ValueTask IsInvalidHttpVersionPolicyAsync( int? customHttpVersionPolicy, HttpVersionPolicy defaultHttpVersionPolicy) => new @@ -143,7 +147,7 @@ private static dynamic IsInvalidHttpVersionPolicy( Message = "HttpVersionPolicy is invalid" }; - private static void Validate(params (dynamic Rule, string Parameter)[] validations) + private static async ValueTask ValidateAsync(params (dynamic Rule, string Parameter)[] validations) { var invalidHttpExchangeException = new InvalidHttpExchangeException( @@ -162,7 +166,8 @@ private static void Validate(params (dynamic Rule, string Parameter)[] validatio invalidHttpExchangeException.ThrowIfContainsErrors(); } - private static void ValidateHttpExchangeRequestObject(params (dynamic Rule, string Parameter)[] validations) + private static async ValueTask ValidateHttpExchangeRequestObjectAsync( + params (dynamic Rule, string Parameter)[] validations) { var invalidHttpExchangeRequestException = new InvalidHttpExchangeRequestException( diff --git a/STX.REST.RESTFulSense.Clients/Services/Foundations/HttpExchanges/HttpExchangeService.cs b/STX.REST.RESTFulSense.Clients/Services/Foundations/HttpExchanges/HttpExchangeService.cs index 803d180..0b66484 100644 --- a/STX.REST.RESTFulSense.Clients/Services/Foundations/HttpExchanges/HttpExchangeService.cs +++ b/STX.REST.RESTFulSense.Clients/Services/Foundations/HttpExchanges/HttpExchangeService.cs @@ -32,7 +32,7 @@ public ValueTask GetAsync( HttpVersionPolicy defaultHttpVersionPolicy = HttpVersionPolicy.RequestVersionOrLower; - ValidateOnGet( + await ValidateOnGetAsync( httpExchange, defaultHttpMethod, defaultHttpVersion,