示例#1
0
        private async Task <ITestCommandResult> ProcessResponse(HttpResponseMessage response)
        {
            string responseContent = await response.Content.ReadAsStringAsync();

            if (!response.IsSuccessStatusCode)
            {
                var failedResult = new HttpFailedRequestResult(this.testCommand.Url, response.StatusCode, response.ReasonPhrase, responseContent);
                this.logger.LogWarning($"{Logging.COMMAND_FAILURE}: IsSuccessStatusCode: false; {failedResult}");
                return(failedResult);
            }

            if (this.testCommand.ExpectedResult != null)
            {
                ITestContent           jsonContent      = JsonContent.LoadFromString(responseContent);
                ITestContentComparison comparisonResult = jsonContent.CompareTo(this.testCommand.ExpectedResult, this.testCommand.ExpectedResultComparisonType);
                if (comparisonResult == null)
                {
                    throw new ApplicationException("Comparison result is NULL");
                }

                if (comparisonResult.AreEqual)
                {
                    this.logger.LogInformation($"{Logging.COMMAND_PASS}: ComparisonResult");
                }
                else
                {
                    this.logger.LogWarning($"{Logging.COMMAND_FAILURE}: ComparisonResult; {comparisonResult}");
                }

                return(new TestContentComparisonResult(comparisonResult));
            }

            this.logger.LogInformation($"{Logging.COMMAND_PASS}: TestNoContentResult");
            return(new TestNoContentResult());
        }
示例#2
0
        public ITestContentComparison CompareTo(ITestContent compareTo, ContentComparisonType contentComparisonType)
        {
            if (contentComparisonType == ContentComparisonType.Exactly)
            {
                bool areEqual = JToken.DeepEquals(this.JsonObject, compareTo.JsonObject);
                return(new TestContentComparison(areEqual));
            }

            throw new NotSupportedException($"Unknown ContentComparisonType: {contentComparisonType}");
        }