diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..50bf6c3 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "csharpier": { + "version": "0.25.0", + "commands": [ + "dotnet-csharpier" + ] + } + } +} diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 0000000..9a88a97 --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,8 @@ +version = 1 + +[[analyzers]] +name = "csharp" + +[[analyzers]] +name = "test-coverage" +enabled = true diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100644 index 0000000..4a3fd89 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +LC_ALL=C + +local_branch="$(git rev-parse --abbrev-ref HEAD)" + +valid_branch_regex="^(feature|fix|docs|style|refactor|perf|hotfix|test|chore|create)\/[a-zA-Z0-9._-]+$" + +message="There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_regex. Your commit will be rejected. You should rename your branch to a valid name and try again." + +if [[ ! $local_branch =~ $valid_branch_regex ]] +then + echo "$message" + exit 1 +fi + +dotnet tool restore + +dotnet csharpier . --check \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..3046abd --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,41 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: + +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + +* OS: \[e.g. iOS] +* Browser \[e.g. chrome, safari] +* Version \[e.g. 22] + +**Smartphone (please complete the following information):** + +* Device: \[e.g. iPhone6] +* OS: \[e.g. iOS8.1] +* Browser \[e.g. stock browser, safari] +* Version \[e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..5f43738 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when (...) + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 3d3fd5a..c4a1c9a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,19 +1,31 @@ version: 2 + updates: -- package-ecosystem: "docker" - directory: "/" - schedule: - interval: weekly - open-pull-requests-limit: 10 - + - package-ecosystem: "nuget" directory: "/" schedule: interval: weekly - open-pull-requests-limit: 10 - + open-pull-requests-limit: 50 + assignees: + - "guibranco" + reviewers: + - "guibranco" + labels: + - "nuget" + - "packages" + - ".NET" + - "dependencies" + - package-ecosystem: "github-actions" directory: "/" schedule: interval: weekly - open-pull-requests-limit: 10 + open-pull-requests-limit: 50 + assignees: + - "guibranco" + reviewers: + - "guibranco" + labels: + - "github-actions" + - "dependencies" \ No newline at end of file diff --git a/.github/workflows/deep-source.yml b/.github/workflows/deep-source.yml new file mode 100644 index 0000000..743c3fd --- /dev/null +++ b/.github/workflows/deep-source.yml @@ -0,0 +1,45 @@ +name: Deep Source + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + pull_request_target: + types: [opened, synchronize, reopened] + +jobs: + DeepSource: + name: Deep Source Coverage report + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Install DeepSource scanner + run: curl https://deepsource.io/cli | sh + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '7.0.x' + + - name: Build and analyze + if: >- + ( + github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name == github.repository + ) || ( + github.event_name == 'pull_request_target' && + github.event.pull_request.head.repo.full_name != github.repository + ) || ( + github.event_name == 'workflow_dispatch' + ) + env: + DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }} + run: | + dotnet build -c Debug --verbosity minimal + dotnet test -c Debug --verbosity minimal --no-build --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat="cobertura" + ./bin/deepsource report --analyzer test-coverage --key csharp --value-file ./Tests/ViaCep.Tests/coverage.cobertura.xml diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..7d9127f --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,24 @@ +name: Linter check + +on: + workflow_dispatch: + pull_request: + +jobs: + linter-check: + runs-on: ubuntu-latest + steps: + + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + + - name: Dotnet restore + run: dotnet tool restore + + - name: CSharpier format check + run: | + dotnet csharpier . --check + echo "run 'dotnet build' to fix the formatting of the code automatically" diff --git a/.github/workflows/size-label.yml b/.github/workflows/size-label.yml index 22bce94..90bd95b 100644 --- a/.github/workflows/size-label.yml +++ b/.github/workflows/size-label.yml @@ -2,6 +2,7 @@ name: Label based on PR size on: pull_request: + pull_request_target: workflow_dispatch: jobs: @@ -12,6 +13,16 @@ jobs: steps: - name: size-label + if: >- + ( + github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name == github.repository + ) || ( + github.event_name == 'pull_request_target' && + github.event.pull_request.head.repo.full_name != github.repository + ) || ( + github.event_name == 'workflow_dispatch' + ) uses: "pascalgn/size-label-action@v0.5.0" env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/README.md b/README.md index 7a99c3a..60d610c 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,12 @@ A .NET client wrapper for both .NET Core & .NET Framework projects of [Via CEP A | Build status | Last commit | Tests | Coverage | Code Smells | LOC | |--------------|-------------|-------|----------|-------------|-----| -| [![Build status](https://ci.appveyor.com/api/projects/status/9jnsy1e08jhyxl7j/branch/main?svg=true)](https://ci.appveyor.com/project/guibranco/ViaCEP) | [![GitHub last commit](https://img.shields.io/github/last-commit/guibranco/ViaCEP/main)](https://github.com/guibranco/ViaCEP) | [![AppVeyor tests (branch)](https://img.shields.io/appveyor/tests/guibranco/ViaCEP/main?compact_message)](https://ci.appveyor.com/project/guibranco/ViaCEP) | [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP&metric=coverage)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) | [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP&metric=code_smells)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) | [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP&metric=ncloc)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) +| [![Build status](https://ci.appveyor.com/api/projects/status/9jnsy1e08jhyxl7j/branch/main?svg=true)](https://ci.appveyor.com/project/guibranco/ViaCEP) | [![GitHub last commit](https://img.shields.io/github/last-commit/guibranco/ViaCEP/main)](https://github.com/guibranco/ViaCEP) | [![AppVeyor tests (branch)](https://img.shields.io/appveyor/tests/guibranco/ViaCEP/main?compact_message)](https://ci.appveyor.com/project/guibranco/ViaCEP) | [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP\&metric=coverage)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) | [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP\&metric=code_smells)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) | [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP\&metric=ncloc)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) ## Code Quality -[![Codacy Badge](https://app.codacy.com/project/badge/Grade/483c4901f0ea4a0d99e69be931ced362)](https://www.codacy.com/gh/guibranco/ViaCEP/dashboard?utm_source=github.com&utm_medium=referral&utm_content=guibranco/ViaCEP&utm_campaign=Badge_Grade) -[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/483c4901f0ea4a0d99e69be931ced362)](https://www.codacy.com/gh/guibranco/ViaCEP/dashboard?utm_source=github.com&utm_medium=referral&utm_content=guibranco/ViaCEP&utm_campaign=Badge_Grade) +[![Codacy Badge](https://app.codacy.com/project/badge/Grade/483c4901f0ea4a0d99e69be931ced362)](https://www.codacy.com/gh/guibranco/ViaCEP/dashboard?utm_source=github.com\&utm_medium=referral\&utm_content=guibranco/ViaCEP\&utm_campaign=Badge_Grade) +[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/483c4901f0ea4a0d99e69be931ced362)](https://www.codacy.com/gh/guibranco/ViaCEP/dashboard?utm_source=github.com\&utm_medium=referral\&utm_content=guibranco/ViaCEP\&utm_campaign=Badge_Grade) [![codecov](https://codecov.io/gh/guibranco/ViaCEP/branch/main/graph/badge.svg)](https://codecov.io/gh/guibranco/ViaCEP) [![CodeFactor](https://www.codefactor.io/repository/github/guibranco/ViaCEP/badge)](https://www.codefactor.io/repository/github/guibranco/ViaCEP) @@ -24,17 +24,19 @@ A .NET client wrapper for both .NET Core & .NET Framework projects of [Via CEP A [![Maintainability](https://api.codeclimate.com/v1/badges/93ba8c7ae3e86ca7e2a7/maintainability)](https://codeclimate.com/github/guibranco/ViaCEP/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/93ba8c7ae3e86ca7e2a7/test_coverage)](https://codeclimate.com/github/guibranco/ViaCEP/test_coverage) -[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP&metric=alert_status)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) -[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) +[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP\&metric=alert_status)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) +[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP\&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) -[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP&metric=sqale_index)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) -[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) +[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP\&metric=sqale_index)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) +[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP\&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) -[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) -[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP&metric=security_rating)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) +[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP\&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) +[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP\&metric=security_rating)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) -[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP&metric=bugs)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) -[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) +[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP\&metric=bugs)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) +[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=guibranco_ViaCEP\&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=guibranco_ViaCEP) + +[![DeepSource](https://app.deepsource.com/gh/guibranco/ViaCEP.svg/?label=active+issues\&show_trend=true\&token=84Hhxk-J1hIHiVC_ojm17J3q)](https://app.deepsource.com/gh/guibranco/ViaCEP/?ref=repository-badge) --- @@ -58,8 +60,8 @@ Download the latest zip file from the [Release](https://github.com/GuiBranco/Via The package has two classes: -- [ViaCepClient](https://github.com/guibranco/ViaCEP/blob/main/ViaCEP/ViaCepClient.cs): The main class (methods). -- [ViaCepResult](https://github.com/guibranco/ViaCEP/blob/main/ViaCEP/ViaCepResult.cs): The result class (data). +* [ViaCepClient](https://github.com/guibranco/ViaCEP/blob/main/ViaCEP/ViaCepClient.cs): The main class (methods). +* [ViaCepResult](https://github.com/guibranco/ViaCEP/blob/main/ViaCEP/ViaCepResult.cs): The result class (data). This package is fully compatible with Dependency Injection. Use the interface *IViaCepClient* and the constructor with HttpClient parameter with a IHttpClientFactory instance. @@ -97,6 +99,6 @@ foreach(var result in results){ ## Changelog -- 2023-03-03: Update dependencies, change branch name, update logo. [@guibranco](https://github.com/guibranco) -- 2021-06-21: Update dependencies version. [@guibranco](https://github.com/guibranco) -- 2020-10-23: Add support to .NET Standard 2.0 and .NET Framework v4.6.1 and above. [@guibranco](https://github.com/guibranco) +* 2023-03-03: Update dependencies, change branch name, update logo. [@guibranco](https://github.com/guibranco) +* 2021-06-21: Update dependencies version. [@guibranco](https://github.com/guibranco) +* 2020-10-23: Add support to .NET Standard 2.0 and .NET Framework v4.6.1 and above. [@guibranco](https://github.com/guibranco) diff --git a/Src/ViaCep/IViaCepClient.cs b/Src/ViaCep/IViaCepClient.cs index 1f9627b..0b086fe 100644 --- a/Src/ViaCep/IViaCepClient.cs +++ b/Src/ViaCep/IViaCepClient.cs @@ -41,6 +41,11 @@ public interface IViaCepClient /// The address. /// The cancellation token. /// - Task> SearchAsync(string stateInitials, string city, string address, CancellationToken cancellationToken); + Task> SearchAsync( + string stateInitials, + string city, + string address, + CancellationToken cancellationToken + ); } } diff --git a/Src/ViaCep/ViaCepClient.cs b/Src/ViaCep/ViaCepClient.cs index a812f0d..77f1e98 100644 --- a/Src/ViaCep/ViaCepClient.cs +++ b/Src/ViaCep/ViaCepClient.cs @@ -77,11 +77,18 @@ public IEnumerable Search(string stateInitials, string city, strin /// The zip code. /// The token. /// - public async Task SearchAsync(string zipCode, CancellationToken cancellationToken) + public async Task SearchAsync( + string zipCode, + CancellationToken cancellationToken + ) { - var response = await _httpClient.GetAsync($"/ws/{zipCode}/json", cancellationToken).ConfigureAwait(false); + var response = await _httpClient + .GetAsync($"/ws/{zipCode}/json", cancellationToken) + .ConfigureAwait(false); response.EnsureSuccessStatusCode(); - return await response.Content.ReadAsAsync(cancellationToken).ConfigureAwait(false); + return await response.Content + .ReadAsAsync(cancellationToken) + .ConfigureAwait(false); } /// @@ -93,11 +100,19 @@ public async Task SearchAsync(string zipCode, CancellationToken ca /// The token. /// public async Task> SearchAsync( - string stateInitials, string city, string address, CancellationToken cancellationToken) + string stateInitials, + string city, + string address, + CancellationToken cancellationToken + ) { - var response = await _httpClient.GetAsync($"/ws/{stateInitials}/{city}/{address}/json", cancellationToken).ConfigureAwait(false); + var response = await _httpClient + .GetAsync($"/ws/{stateInitials}/{city}/{address}/json", cancellationToken) + .ConfigureAwait(false); response.EnsureSuccessStatusCode(); - return await response.Content.ReadAsAsync>(cancellationToken).ConfigureAwait(false); + return await response.Content + .ReadAsAsync>(cancellationToken) + .ConfigureAwait(false); } #endregion diff --git a/Tests/ViaCep.Tests/AddressTests.cs b/Tests/ViaCep.Tests/AddressTests.cs index 71e2c5b..13ed75f 100644 --- a/Tests/ViaCep.Tests/AddressTests.cs +++ b/Tests/ViaCep.Tests/AddressTests.cs @@ -24,13 +24,23 @@ public void ValidateSearchByFullAddress() .Setup(c => c.Search(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(fixtureResults); - var results = clientMock.Object.Search(fixtureResults.First().StateInitials, fixtureResults.First().City, fixtureResults.First().Street); + var results = clientMock.Object.Search( + fixtureResults.First().StateInitials, + fixtureResults.First().City, + fixtureResults.First().Street + ); Assert.NotNull(results); var list = results.ToList(); Assert.True(list.Any()); - Assert.Contains(list, r => r.ZipCode.Equals("12345-678", StringComparison.InvariantCultureIgnoreCase)); - Assert.Contains(list, r => r.ZipCode.Equals("98765-432", StringComparison.InvariantCultureIgnoreCase)); + Assert.Contains( + list, + r => r.ZipCode.Equals("12345-678", StringComparison.InvariantCultureIgnoreCase) + ); + Assert.Contains( + list, + r => r.ZipCode.Equals("98765-432", StringComparison.InvariantCultureIgnoreCase) + ); } /// @@ -42,16 +52,35 @@ public async Task ValidateSearchByFullAddressAsync() var fixtureResults = ResultsFixture.GetSampleResults(); var clientMock = new Mock(); clientMock - .Setup(c => c.SearchAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Setup( + c => + c.SearchAsync( + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny() + ) + ) .ReturnsAsync(fixtureResults); - var results = await clientMock.Object.SearchAsync(fixtureResults.First().StateInitials, fixtureResults.First().City, fixtureResults.First().Street, CancellationToken.None); + var results = await clientMock.Object.SearchAsync( + fixtureResults.First().StateInitials, + fixtureResults.First().City, + fixtureResults.First().Street, + CancellationToken.None + ); Assert.NotNull(results); var list = results.ToList(); Assert.True(list.Any()); - Assert.Contains(list, r => r.ZipCode.Equals("12345-678", StringComparison.InvariantCultureIgnoreCase)); - Assert.Contains(list, r => r.ZipCode.Equals("98765-432", StringComparison.InvariantCultureIgnoreCase)); + Assert.Contains( + list, + r => r.ZipCode.Equals("12345-678", StringComparison.InvariantCultureIgnoreCase) + ); + Assert.Contains( + list, + r => r.ZipCode.Equals("98765-432", StringComparison.InvariantCultureIgnoreCase) + ); } } -} \ No newline at end of file +} diff --git a/Tests/ViaCep.Tests/CoverageTests.cs b/Tests/ViaCep.Tests/CoverageTests.cs index 4555e11..f5a48a1 100644 --- a/Tests/ViaCep.Tests/CoverageTests.cs +++ b/Tests/ViaCep.Tests/CoverageTests.cs @@ -32,12 +32,14 @@ public void ValidateCreateNewInstance() [Fact] public void ValidateSearchByZipCodeCoverage() { - const string resultData = "{'cep': '01001-000','logradouro': 'Praça da Sé','complemento': 'lado ímpar','bairro': 'Sé','localidade': 'São Paulo','uf': 'SP','unidade': '','ibge': '3550308','gia': '1004'}"; + const string resultData = + "{'cep': '01001-000','logradouro': 'Praça da Sé','complemento': 'lado ímpar','bairro': 'Sé','localidade': 'São Paulo','uf': 'SP','unidade': '','ibge': '3550308','gia': '1004'}"; var httpClientMock = new MockHttpMessageHandler(); - httpClientMock.When("https://viacep.com.br/ws/*/json") - .Respond("application/json", resultData); - - var httpClient = new HttpClient(httpClientMock) {BaseAddress = _baseUrl}; + httpClientMock + .When("https://viacep.com.br/ws/*/json") + .Respond("application/json", resultData); + + var httpClient = new HttpClient(httpClientMock) { BaseAddress = _baseUrl }; var client = new ViaCepClient(httpClient); var result = client.Search("01001000"); @@ -63,8 +65,9 @@ public void ValidateSearchByAddressCoverage() const string resultData = "[ { 'cep': '91790-072', 'logradouro': 'Rua Domingos José Poli', 'complemento': '', 'bairro': 'Restinga', 'localidade': 'Porto Alegre', 'uf': 'RS', 'unidade': '', 'ibge': '4314902', 'gia': '' }, { 'cep': '91910-420', 'logradouro': 'Rua José Domingos Varella', 'complemento': '', 'bairro': 'Cavalhada', 'localidade': 'Porto Alegre', 'uf': 'RS', 'unidade': '', 'ibge': '4314902', 'gia': '' }, { 'cep': '90420-200', 'logradouro': 'Rua Domingos José de Almeida', 'complemento': '', 'bairro': 'Rio Branco', 'localidade': 'Porto Alegre', 'uf': 'RS', 'unidade': '', 'ibge': '4314902', 'gia': '' } ]"; var httpClientMock = new MockHttpMessageHandler(); - httpClientMock.When("https://viacep.com.br/ws/*/*/*/json") - .Respond("application/json", resultData); + httpClientMock + .When("https://viacep.com.br/ws/*/*/*/json") + .Respond("application/json", resultData); var httpClient = new HttpClient(httpClientMock) { BaseAddress = _baseUrl }; var client = new ViaCepClient(httpClient); @@ -79,8 +82,6 @@ public void ValidateSearchByAddressCoverage() Assert.All(list, result => Assert.Equal("Porto Alegre", result.City)); Assert.All(list, result => Assert.Equal("RS", result.StateInitials)); Assert.All(list, result => Assert.Equal(4314902, result.IBGECode)); - } - } } diff --git a/Tests/ViaCep.Tests/ResultsFixture.cs b/Tests/ViaCep.Tests/ResultsFixture.cs index a3a7ec1..7f3e17a 100644 --- a/Tests/ViaCep.Tests/ResultsFixture.cs +++ b/Tests/ViaCep.Tests/ResultsFixture.cs @@ -52,4 +52,4 @@ public static ICollection GetSampleResults() => } }; } -} \ No newline at end of file +} diff --git a/Tests/ViaCep.Tests/ZipCodeTests.cs b/Tests/ViaCep.Tests/ZipCodeTests.cs index e62d03a..8cedade 100644 --- a/Tests/ViaCep.Tests/ZipCodeTests.cs +++ b/Tests/ViaCep.Tests/ZipCodeTests.cs @@ -60,9 +60,8 @@ public async Task ValidateSearchByZipCodeAsync() Assert.Equal("SP", result.StateInitials); } - /// - /// Validates if the search by zip code don't throw a exception if the address doesn't have a gia code + /// Validates if the search by zip code don't throw a exception if the address doesn't have a gia code /// /// [Fact] @@ -110,4 +109,4 @@ public async Task ValidateSearchByZipCodeWithoutGiaCodeAsync() Assert.Equal("SP", result.StateInitials); } } -} \ No newline at end of file +} diff --git a/appveyor.yml b/appveyor.yml index 6c7d20a..06ed646 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,7 +19,7 @@ dotnet_csproj: assembly_version: '{version}' file_version: '{version}' informational_version: '{version}' - + init: - SET JAVA_HOME=C:\Program Files\Java\jdk19 - SET PATH=%JAVA_HOME%\bin;%PATH% @@ -28,6 +28,9 @@ before_build: - ps: $env:SOLUTION_NAME = $([io.path]::GetFileNameWithoutExtension($(Get-ChildItem -Path .\* -Include *.sln))) - ps: $env:SONAR_PROJECT = "$env:APPVEYOR_REPO_NAME" -replace "/","_" - ps: $env:SONAR_ORGANIZATION = "$env:APPVEYOR_REPO_NAME" -replace "/.*$","-github" +- ps: $env:LOCAL_PR = 0 +- ps: if(-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { $env:LOCAL_PR = 1 } +- ps: if($env:APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME -Eq $env:APPVEYOR_REPO_NAME) { $env:LOCAL_PR = 1 } - cmd: nuget restore - cmd: choco install opencover.portable - cmd: choco install codecov @@ -43,40 +46,42 @@ build: build_script: - ps: $Params = "/k:`"$env:SONAR_PROJECT`"", "/o:`"$env:SONAR_ORGANIZATION`"", "/v:`"$env:APPVEYOR_BUILD_NUMBER`"" -- ps: $Params += "/d:sonar.host.url=`"https://sonarcloud.io`"", "/d:sonar.login=`"$env:SONAR_TOKEN`"" +- ps: $Params += "/d:sonar.host.url=`"https://sonarcloud.io`"" +- ps: if($env:LOCAL_PR -Eq 1) { $Params += "/d:sonar.token=`"$env:SONAR_TOKEN`"" } - ps: $Params += "/d:sonar.exclusions=`"**/bin/**/*,**/obj/**/*`"", "/d:sonar.coverage.exclusions=`"**/$env:SOLUTION_NAME.Tests/**,**/*Tests.cs`"" -- ps: $Params += "/d:sonar.cs.opencover.reportsPaths=`"$env:CD\Tests\$env:SOLUTION_NAME.Tests\coverage.opencover.xml`"" +- ps: $Params += "/d:sonar.cs.opencover.reportsPaths=`"Tests\$env:SOLUTION_NAME.Tests\coverage.opencover.xml`"" - ps: if(-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { $Params += "/d:sonar.branch.name=`"$env:APPVEYOR_REPO_BRANCH`"" } - ps: if($env:APPVEYOR_PULL_REQUEST_NUMBER) { $Params += "/d:sonar.pullrequest.key=$env:APPVEYOR_PULL_REQUEST_NUMBER", "/d:sonar.pullrequest.branch=`"$env:APPVEYOR_REPO_BRANCH`"" } - ps: Start-process "dotnet" "sonarscanner begin $($Params -join ' ')" - codeclimate-test-reporter before-build - dotnet build %SOLUTION_NAME%.sln -- ps: $testProjects = (Get-ChildItem -Path .\Tests\**\ -Recurse -Include *.csproj).Fullname -- ps: $coverletFormats = @('cobertura', 'lcov', 'opencover') +- ps: $TEST_PROJECTS = (Get-ChildItem -Path .\Tests\**\ -Recurse -Include *.csproj).Fullname +- ps: $COVERLET_FORMATS = @('cobertura', 'lcov', 'opencover') - ps: | - foreach($testProject in $testProjects) + foreach($testProject in $TEST_PROJECTS) { - foreach($coverletFormat in $coverletFormats) + foreach($coverletFormat in $COVERLET_FORMATS) { dotnet test $testProject /p:CollectCoverage=true /p:CoverletOutputFormat="$coverletFormat" } } -- codeclimate-test-reporter format-coverage -t lcov -o "%CD%\Tests\%SOLUTION_NAME%.Tests\code-climate.json" "%CD%\Tests\%SOLUTION_NAME%.Tests\coverage.info" -- codeclimate-test-reporter upload-coverage -i "%CD%\Tests\%SOLUTION_NAME%.Tests\code-climate.json" -r %CODECLIMATE_TOKEN% -- codecov -f "%CD%\Tests\%SOLUTION_NAME%.Tests\coverage.opencover.xml" -- java -jar ./codacy-test-reporter.jar report -l CSharp -t %CODACY_PROJECT_TOKEN% -r "%CD%\Tests\%SOLUTION_NAME%.Tests\coverage.opencover.xml" -- dotnet sonarscanner end /d:sonar.login="%SONAR_TOKEN%" +- if %LOCAL_PR% EQU 1 codecov -f "Tests\%SOLUTION_NAME%.Tests\coverage.opencover.xml" +- if %LOCAL_PR% EQU 1 codeclimate-test-reporter format-coverage -t lcov -o "Tests\%SOLUTION_NAME%.Tests\code-climate.json" "Tests\%SOLUTION_NAME%.Tests\coverage.info" +- if %LOCAL_PR% EQU 1 codeclimate-test-reporter upload-coverage -i "Tests\%SOLUTION_NAME%.Tests\code-climate.json" -r %CODECLIMATE_TOKEN% +- if %LOCAL_PR% EQU 1 java -jar ./codacy-test-reporter.jar report -l CSharp -t %CODACY_PROJECT_TOKEN% -r "Tests\%SOLUTION_NAME%.Tests\coverage.opencover.xml" +- if %LOCAL_PR% EQU 1 dotnet sonarscanner end /d:sonar.token="%SONAR_TOKEN%" after_build: -- xcopy %CD%\Src\%SOLUTION_NAME%\bin\Release\netstandard2.0\*.* %CD%\Build\ +- xcopy Src\%SOLUTION_NAME%\bin\Release\netstandard2.0\*.* Build\.netstandard2.0\ +- xcopy Src\%SOLUTION_NAME%\bin\Release\netstandard2.1\*.* Build\.netstandard2.1\ -- copy %CD%\Src\%SOLUTION_NAME%\bin\Release\%SOLUTION_NAME%.%APPVEYOR_BUILD_VERSION%.nupkg %SOLUTION_NAME%.%APPVEYOR_BUILD_VERSION%.nupkg +- copy Src\%SOLUTION_NAME%\bin\Release\%SOLUTION_NAME%.%APPVEYOR_BUILD_VERSION%.nupkg %SOLUTION_NAME%.%APPVEYOR_BUILD_VERSION%.nupkg - rd /s /q %CD%\Src\%SOLUTION_NAME%\bin\Release\ -- xcopy %CD%\Tests\%SOLUTION_NAME%.Tests\*.xml %CD%\Coverage\ -- xcopy %CD%\Tests\%SOLUTION_NAME%.Tests\*.json %CD%\Coverage\ -- xcopy %CD%\Tests\%SOLUTION_NAME%.Tests\*.info %CD%\Coverage\ +- xcopy Tests\%SOLUTION_NAME%.Tests\*.xml Coverage\ +- xcopy Tests\%SOLUTION_NAME%.Tests\*.json Coverage\ +- xcopy Tests\%SOLUTION_NAME%.Tests\*.info Coverage\ - cd %CD%