コード例 #1
0
        private IViaCepClient CreateViaCepClientInstance()
        {
            var httpClient   = _viaCepFixture.Client;
            var options      = new ViaCepClientOptions();
            var builder      = new ViaCepRequestBuilder(options);
            var restClient   = new RestClient(httpClient);
            var viaCepClient = new Client.ViaCepClient(restClient, builder);

            return(viaCepClient);
        }
コード例 #2
0
        public void ViaCepRequestBuilder_WhenBuildingCepRequest_MustBuildExpectedUri(string cep, string expectedUrlAddress)
        {
            // Given
            ViaCepClientOptions   options = new ViaCepClientOptions();
            IViaCepRequestBuilder builder = new ViaCepRequestBuilder(options);

            Uri expectedUri = new Uri(expectedUrlAddress);

            // When
            Uri actualUri = builder.CreateRequestUri(new Cep(cep));

            // Then
            actualUri.Should().Be(expectedUri);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: sidneyflima/viacepclient
        private static async Task CallViaCepClientDirectly(string cep)
        {
            HttpClient            httpClient   = new HttpClient();
            ViaCepClientOptions   options      = new ViaCepClientOptions();
            IViaCepRequestBuilder builder      = new ViaCepRequestBuilder(options);
            IRestClient           restClient   = new RestClient(httpClient);
            IViaCepClient         viaCepClient = new Client.ViaCepClient(restClient, builder);

            ResponseMessage <CepDetails> response = await viaCepClient.SendRequestAsync(new Cep(cep));

            CepDetails cepDetails = response.Content;

            string json = JsonSerializer.Serialize(cepDetails, new JsonSerializerOptions
            {
                WriteIndented = true,
                Encoder       = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
            });

            Console.WriteLine(json);
        }