本文整理汇总了C#中HttpResponse.IsResponseValid方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse.IsResponseValid方法的具体用法?C# HttpResponse.IsResponseValid怎么用?C# HttpResponse.IsResponseValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.IsResponseValid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyResponseBody
/// <summary>
/// Verify that the body of the actual response is consistent with the method definition and expected response parameters
/// </summary>
/// <param name="method">The MethodDefinition that generated the response.</param>
/// <param name="actualResponse">The actual response from the service to validate.</param>
/// <param name="expectedResponse">The prototype expected response from the service.</param>
/// <param name="detectedErrors">A collection of errors that will be appended with any detected errors</param>
private void VerifyResponseBody(HttpResponse actualResponse, HttpResponse expectedResponse, out ValidationError[] errors, ValidationOptions options = null)
{
List<ValidationError> detectedErrors = new List<ValidationError>();
if (string.IsNullOrEmpty(actualResponse.Body) &&
(expectedResponse != null && !string.IsNullOrEmpty(expectedResponse.Body)))
{
detectedErrors.Add(new ValidationError(ValidationErrorCode.HttpBodyExpected, null, "Body missing from response (expected response includes a body or a response type was provided)."));
}
else if (!string.IsNullOrEmpty(actualResponse.Body))
{
ValidationError[] schemaErrors;
if (this.ExpectedResponseMetadata == null ||
(string.IsNullOrEmpty(this.ExpectedResponseMetadata.ResourceType) &&
(expectedResponse != null && !string.IsNullOrEmpty(expectedResponse.Body))))
{
detectedErrors.Add(new ValidationError(ValidationErrorCode.ResponseResourceTypeMissing, null, "Expected a response, but resource type on method is missing: {0}", this.Identifier));
}
else
{
var otherResources = this.SourceFile.Parent.ResourceCollection;
if (
!otherResources.ValidateResponseMatchesSchema(
this,
actualResponse,
expectedResponse,
out schemaErrors,
options))
{
detectedErrors.AddRange(schemaErrors);
}
}
var responseValidation = actualResponse.IsResponseValid(
this.SourceFile.DisplayName,
this.SourceFile.Parent.Requirements);
detectedErrors.AddRange(responseValidation.Messages);
}
errors = detectedErrors.ToArray();
}