public virtual Response GetPet(string id, RequestOptions options = null)
#pragma warning restore AZC0002
        {
            options ??= new RequestOptions();
            using HttpMessage message = CreateGetPetRequest(id, options);
            RequestOptions.Apply(options, message);
            using var scope = _clientDiagnostics.CreateScope("PetStoreClient.GetPet");
            scope.Start();
            try
            {
                Pipeline.Send(message, options.CancellationToken);
                if (options.StatusOption == ResponseStatusOption.Default)
                {
                    switch (message.Response.Status)
                    {
                    case 200:
                        return(message.Response);

                    default:
                        throw _clientDiagnostics.CreateRequestFailedException(message.Response);
                    }
                }
                else
                {
                    return(message.Response);
                }
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
Beispiel #2
0
        public void CanOverrideDefaultClassificationNoRetry()
        {
            var m = CreateTestMessage(500);

            var options = new RequestOptions();

            options.AddClassifier(new[] { 500 }, ResponseClassification.DontRetry);

            RequestOptions.Apply(options, m);

            Assert.False(m.ResponseClassifier.IsRetriableResponse(m));
        }
Beispiel #3
0
        public void CanOverrideDefaultClassificationThrow()
        {
            var m = CreateTestMessage(200);

            var options = new RequestOptions();

            options.AddClassifier(new[] { 200 }, ResponseClassification.Throw);

            RequestOptions.Apply(options, m);

            Assert.True(m.ResponseClassifier.IsErrorResponse(m));
        }
Beispiel #4
0
        public void CanOverrideDefaultClassificationSuccess()
        {
            var m = CreateTestMessage(404);

            var options = new RequestOptions();

            options.AddClassifier(new[] { 404 }, ResponseClassification.Success);

            RequestOptions.Apply(options, m);

            Assert.False(m.ResponseClassifier.IsErrorResponse(m));
        }
Beispiel #5
0
        public void CanOverrideDefaultClassificationWithFunc()
        {
            HttpMessage m = new HttpMessage(new MockRequest(), new ResponseClassifier())
            {
                Response = new MockResponse(500)
            };

            var options = new RequestOptions();

            options.AddClassifier(_ => ResponseClassification.Success);

            RequestOptions.Apply(options, m);

            Assert.False(m.ResponseClassifier.IsErrorResponse(m));
        }