Пример #1
0
        /// <summary>
        /// Runs the test with the specified name.
        /// </summary>
        public async Task <ConformanceTestResult> RunTestAsync(ConformanceTestInfo test, CancellationToken cancellationToken = default)
        {
            string testName = test.Test !;

            ConformanceTestResult Failure(string message) => new ConformanceTestResult(testName, ConformanceTestStatus.Fail, message);

            try
            {
                if (m_httpClient != null && test.HttpRequest != null)
                {
                    if (test.HttpRequest.Method is null)
                    {
                        return(Failure("HTTP request missing method."));
                    }
                    if (test.HttpRequest.Path is null)
                    {
                        return(Failure("HTTP request missing path."));
                    }

                    var httpRequest  = new HttpRequestMessage(new HttpMethod(test.HttpRequest.Method), test.HttpRequest.Path);
                    var httpResponse = await m_httpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (!httpResponse.IsSuccessStatusCode)
                    {
                        return(Failure($"Got {(int) httpResponse.StatusCode} {httpResponse.ReasonPhrase}: {await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)}"));
                    }

                    return(new ConformanceTestResult(testName, ConformanceTestStatus.Pass));
                }
 /// <summary>
 /// Creates a service for the specified test.
 /// </summary>
 public ConformanceApiService(ConformanceTestInfo testInfo)
 {
     m_testInfo = testInfo;
 }