Пример #1
0
        public void TestArgumentExceptionOnNullOrEmptyApiKey()
        {
            var unit = new RestClientFactory();

            try
            {
                unit.Create(null);
                Assert.Fail("Expected ArgumentException not thrown.");
            }
            catch (ArgumentException)
            {
                //expected
            }

            try
            {
                unit.Create(string.Empty);
                Assert.Fail("Expected ArgumentException not thrown.");
            }
            catch (ArgumentException)
            {
                //expected
            }

            unit.Create("not empty");
            //passes without exception
        }
        private void Given_a_rest_client()
        {
            var httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri("http://localhost:5000");
            restClient             = RestClientFactory.Create(httpClient);
        }
Пример #3
0
        static RestSharpServiceFactory()
        {
            JamaOptions           jamaOptions       = JamaOptionsFactory.Create();
            JsonSerializerOptions serializerOptions = JsonSerializerOptionsFactory.Create();

            Client = RestClientFactory.Create(jamaOptions, serializerOptions);
        }
Пример #4
0
        public void GetCustomiazeClient_BaseUriRightFact()
        {
            var restClientFactory = new RestClientFactory(productInfo);

            using var restClient = restClientFactory.Create(_serviceEndpoint);
            Assert.Equal(Endpoint, restClient.BaseUri.AbsoluteUri);
        }
Пример #5
0
        public void TestCreate()
        {
            var unit   = new RestClientFactory();
            var result = unit.Create("unit test");

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Authenticator, typeof(HttpBasicAuthenticator));
            Assert.IsNotNull(result.BaseUrl);
        }
Пример #6
0
        public async Task <ActionResult> BargainFinderMax(BargainFinderMaxPostRQ requestModel)
        {
            IActivity     activity      = new BargainFinderMaxActivity(RestClientFactory.Create(), requestModel);
            Workflow      workflow      = new Workflow(activity);
            SharedContext sharedContext = await workflow.RunAsync();

            BargainFinderMaxVM model = ViewModelFactory.CreateBargainFinderMaxVM(sharedContext);

            return(this.View(model));
        }
Пример #7
0
        private IRestResponse getCEP(object CEP)
        {
            var client = restClientFactory.Create("http://viacep.com.br/ws/" + CEP + "/json/");
            //var client = new RestClient(baseUrl);
            var restRequest = restRequestFactory.Create(Method.GET, DataFormat.Json);

            //var restRequest = new RestRequest(method) { RequestFormat = format };

            return(client.Execute(restRequest));
        }
Пример #8
0
        public static IRestClient Create()
        {
            var httpClient = new HttpClient {
                BaseAddress = new Uri("http://localhost:3000/")
            };

            var restClient = RestClientFactory.Create(httpClient);

            return(restClient);
        }
Пример #9
0
        public async Task <ActionResult> InstaFlightsSearch(InstaFlightsPostRQ requestModel)
        {
            RestClient    restClient    = RestClientFactory.Create();
            IActivity     activity      = new InstaFlightsActivity(restClient, requestModel);
            Workflow      workflow      = new Workflow(activity);
            SharedContext sharedContext = await workflow.RunAsync();

            InstaFlightsPostVM viewModel = ViewModelFactory.CreateInstaFlightsVM(sharedContext);

            return(this.View(viewModel));
        }
Пример #10
0
        public void ThenItShouldHaveTheCorrectBaseUrl()
        {
            //Arange
            var baseUrl = new Uri("http://www.google.co.uk");

            //Act
            var client = _factory.Create(baseUrl);

            //Assert
            Assert.AreEqual(baseUrl, client.BaseUrl);
        }
Пример #11
0
        public async Task <ActionResult> LeadPriceCalendar(LeadPriceCalendarPostRQ requestModel)
        {
            RestClient    restClient    = RestClientFactory.Create();
            IActivity     activity      = new LeadPriceCalendarActivity(requestModel, restClient);
            Workflow      workflow      = new Workflow(activity);
            SharedContext sharedContext = await workflow.RunAsync();

            LeadPriceCalendarPostVM viewModel = ViewModelFactory.CreateLeadPriceCalendarVM(sharedContext);

            return(this.View(viewModel));
        }
Пример #12
0
        public void Test1()
        {
            var policy = BuildTimeoutAndRetryPolicy(1, 1, 60);
            var client = RestClientFactory <IRestResponse> .Create(policy);

            client.BaseUrl = new Uri("https://httpstat.us/500");
            IRestRequest request  = new RestRequest(Method.GET);
            var          response = client.Execute(request);

            Assert.Equal(500, (int)response.StatusCode);
        }
Пример #13
0
        private static async Task Main(string[] args)
        {
            // To uncomment to try
            //async
            var asyncPolicy2 = BuildTimeoutAndRetryAsyncPolicy2(3, 2, 10);
            var client1      = RestClientFactory <IRestResponse> .Create(asyncPolicy2);

            IRestRequest request1 = new RestRequest(Method.GET);

            client1.BaseUrl = new Uri("https://httpstat.us/500");
            var response5 = await client1.ExecuteAsync(request1);

            Console.ReadKey();



            //async (no result)
            ////https://github.com/App-vNext/Polly/wiki/Non-generic-and-generic-policies
            var noResultaAyncPolicy = BuildTimeoutAndRetryAsyncPolicy(3, 2, 10);

            var client2Async = RestClientFactory.Create(noResultaAyncPolicy);

            client2Async.BaseUrl = new Uri("https://httpstat.us/500");
            IRestRequest request3 = new RestRequest(Method.GET);
            //if runtime have errors ,it will retry.
            var response2 = await client2Async.ExecuteAsync(null);

            Console.ReadKey();

            //sync (no result)  /// To uncomment to try
            //https://github.com/App-vNext/Polly/wiki/Non-generic-and-generic-policies
            var          syncPolicy2 = BuildTimeoutAndRetryPolicy(3, 2, 10);
            var          syncClient2 = RestClientFactory.Create(syncPolicy2);
            IRestRequest request2    = new RestRequest(Method.GET);

            syncClient2.BaseUrl = new Uri("https://httpstat.us/500");
            //if runtime have errors ,it will retry.
            var response4 = syncClient2.Execute(null);

            Console.ReadKey();

            ////sync
            /// To uncomment to try
            var syncPolicy3 = BuildTimeoutAndRetryPolicy2(3, 2, 10);
            var syncclient3 = RestClientFactory <IRestResponse> .Create(syncPolicy3);

            IRestRequest request4 = new RestRequest(Method.GET);

            syncclient3.BaseUrl = new Uri("https://httpstat.us/500");
            //if runtime have errors ,it will retry.
            var res = syncclient3.Execute(request4);

            Console.ReadKey();
        }
Пример #14
0
 private async Task CheckEndpointHealthAsync()
 {
     await Task.WhenAll(_serviceEndpointManager.GetEndpoints(_hubName).Select(async endpoint =>
     {
         var retry     = 0;
         var isHealthy = false;
         bool needRetry;
         do
         {
             try
             {
                 using var client = _clientFactory.Create(endpoint);
                 isHealthy        = await client.IsServiceHealthy(default);
Пример #15
0
        public virtual void Initialize()
        {
            _restClient = RestClientFactory.Create(AppEx.Config.ServiceUrl, AppEx.Config.UserKey, AppEx.Config.Password, TokenManager.Token);

            var attribute = typeof(TModel).GetCustomAttribute <UriAttribute>();

            if (attribute == null)
            {
                throw new InvalidOperationException("Uriattribute not found on the given dimension.");
            }

            _uriName = attribute.Name;
        }
Пример #16
0
        public void Test1()
        {
            var policy = BuildTimeoutAndRetryPolicy(3, 1, 60);
            var client = RestClientFactory.Create(policy);

            client.BaseUrl = new Uri("https://httpstat.us/500");
            IRestRequest request = new RestRequest(Method.GET);

            //if runtime have errors ,it will retry.

            Assert.Throws <AggregateException>(() => client.Execute(null));
            Assert.Equal(3, count);
        }
Пример #17
0
        private async Task <string> GetRawJSON(IRestRequest request)
        {
            var client = RestClientFactory.Create();

            client.BaseUrl = new Uri(BaseURL);
            var response = await Limiter.Perform(() => client.Execute(request));

            if (response.ErrorException != null)
            {
                throw new ApplicationException("Error during API request, see inner exception.", response.ErrorException);
            }

            return(response.Content);
        }
Пример #18
0
        private async Task <T> Execute <T>(IRestRequest request) where T : new()
        {
            request.JsonSerializer = new NewtonsoftJsonSerializer();
            var client = RestClientFactory.Create();

            client.BaseUrl = new Uri(BaseURL);
            var response = await Limiter.Perform(() => client.Execute <T>(request));

            if (response.ErrorException != null)
            {
                throw new ApplicationException("Error during API request, see inner exception.", response.ErrorException);
            }

            return(response.Data);
        }
Пример #19
0
        public static IRestClient Create()
        {
            var httpClient = new HttpClient {
                BaseAddress = new Uri("http://localhost:3000/")
            };
            var clientOptions = new ClientOptions
            {
                TIKA_ENABLE_MULTI_CLUSTER          = false,
                TIKA_API_ENDPOINT                  = "http://localhost:3000",
                TIKA_MULTI_CLUSTER_HOSTNAME_PREFIX = null
            };

            var restClient = RestClientFactory.Create(httpClient, clientOptions);

            return(restClient);
        }
Пример #20
0
        public async Task <bool> IsServiceHealthy(CancellationToken cancellationToken)
        {
            using var restClient = _restClientFactory.Create(_endpoint);
            try
            {
                var healthApi = restClient.HealthApi;
                using var response = await healthApi.GetHealthStatusWithHttpMessagesAsync(cancellationToken : cancellationToken);

                return(true);
            }
            catch (HttpOperationException e) when((int)e.Response.StatusCode >= 500 && (int)e.Response.StatusCode < 600)
            {
                return(false);
            }
            catch (Exception ex)
            {
                throw ex.WrapAsAzureSignalRException(restClient.BaseUri);
            }
        }
Пример #21
0
        private static async Task Main(string[] args)
        {
            var asyncPolicy  = BuildTimeoutAndRetryAsyncPolicy(3, 2, 10);
            var asyncPolicy2 = BuildTimeoutAndRetryAsyncPolicy2(3, 2, 10);
            var asyncPolicy3 = BuildTimeoutAndRetryAsyncPolicy3(3, 2, 10);
            var client       = RestClientFactory.Create(asyncPolicy); //TimeoutAndRetryPolicy.Build(1, 1, 1)
                                                                      // var client2 = RestClientFactory<IRestResponse>.Create(asyncPolicy2);
                                                                      // var client3 = RestClientFactory<IRestResponse<QueryResult>>.Create(asyncPolicy3);
            IRestRequest request = new RestRequest(Method.GET);

            client.BaseUrl = new Uri("https://httpstat.us/500");
            //client2.BaseUrl = new Uri("https://httpstat.us/500");//
            // client3.BaseUrl = new Uri("https://httpbin.org/anything");

            var response = await client.ExecuteTaskAsync(request);

            //var response2 = await client2.ExecuteTaskAsync(request);
            // var response3 = await client3.ExecuteTaskAsync<QueryResult>(request);
            Console.Read();
        }
Пример #22
0
 public override async Task <bool> IsServiceHealthy(CancellationToken cancellationToken)
 {
     using var restClient = _restClientFactory.Create(_endpoint);
     return(await restClient.IsServiceHealthy(cancellationToken));
 }
Пример #23
0
 public static NssRestApi Create() => new NssRestApi(RestClientFactory.Create());
        private void And_a_rest_client()
        {
            var testHttpClient = HostBuilderTestServerExtensions.GetTestClient(testHost);

            restClient = RestClientFactory.Create(testHttpClient);
        }
Пример #25
0
 public void OneTimeSetup()
 {
     RestClientFactory.Create("https://deckofcardsapi.com/api");
 }
Пример #26
0
 /// <summary>
 /// Creates a Rest client using the specified <paramref name="httpClient"/> and <paramref name="settings"/>.
 /// </summary>
 /// <typeparam name="T">The interface of the Rest client.</typeparam>
 /// <param name="httpClient">The http client.</param>
 /// <param name="settings">The optional settings.</param>
 /// <returns></returns>
 public static T For <T>(HttpClient httpClient, RestSettings settings = null)
     where T : class
 {
     return(RestClientFactory.Create <T>(httpClient, settings));
 }