-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Xunit; | ||
|
||
namespace ViaCep.IntegrationTests | ||
{ | ||
public class AddressTests : IntegrationTest | ||
{ | ||
[Fact] | ||
public async Task Search_WithValidAddress_ReturnsExpectedResult() | ||
{ | ||
//Arrange | ||
var validState = "SP"; | ||
var validCity = "São Paulo"; | ||
var validAddress = "Rua Direita"; | ||
var validZipCodeOne = "01002-902"; //Corresponds to the above city and state | ||
var validZipCodeTwo = "01002-000"; //Another valid zip code for the same city and state | ||
|
||
//Act | ||
var results = (await Client.SearchAsync(validState, validCity, validAddress, default)).ToList(); | ||
|
||
//Assert | ||
Assert.NotNull(results); | ||
Assert.Contains(results, r => r.ZipCode == validZipCodeOne); | ||
Assert.Contains(results, r => r.ZipCode == validZipCodeTwo); | ||
} | ||
|
||
[Fact] | ||
public async Task Search_WithNonexistentAddress_ReturnsEmptyResults() | ||
{ | ||
//Arrange | ||
var nonExistentAddress = "Non-existent Street"; | ||
var nonExistentCity = "Non-existent City"; | ||
|
||
//Act | ||
var results = await Client.SearchAsync("XX", nonExistentCity, nonExistentAddress, default); | ||
|
||
//Assert | ||
Assert.Empty(results); | ||
} | ||
|
||
[Fact] | ||
public async Task Search_WithCanceledToken_ThrowsTaskCanceledException() | ||
{ | ||
//Arrange | ||
var validState = "SP"; | ||
var validCity = "São Paulo"; | ||
var validAddress = "Rua Direita"; | ||
var cancellationTokenSource = new CancellationTokenSource(); | ||
cancellationTokenSource.Cancel(); | ||
|
||
//Act and Assert | ||
await Assert.ThrowsAsync<TaskCanceledException>(() => | ||
Client.SearchAsync(validState, validCity, validAddress, cancellationTokenSource.Token)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace ViaCep.IntegrationTests | ||
{ | ||
public class IntegrationTest | ||
{ | ||
protected readonly ViaCepClient Client = new ViaCepClient(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Tests/ViaCep.IntegrationTests/ViaCep.IntegrationTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Src\ViaCep\ViaCep.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Xunit; | ||
|
||
namespace ViaCep.IntegrationTests | ||
{ | ||
public class ZipCodeTests : IntegrationTest | ||
{ | ||
[Fact] | ||
public async Task Search_WithValidZipCode_ReturnsExpectedResult() | ||
{ | ||
//Arrange | ||
var validZipCode = "01001-000"; | ||
|
||
//Act | ||
var result = await Client.SearchAsync(validZipCode, default); | ||
|
||
//Assert | ||
Assert.NotNull(result); | ||
Assert.Equal(validZipCode, result.ZipCode); | ||
Assert.NotNull(result.City); | ||
Assert.NotNull(result.StateInitials); | ||
} | ||
|
||
[Fact] | ||
public async Task Search_WithInvalidZipCode_ThrowsHttpRequestException() | ||
{ | ||
//Arrange | ||
var invalidZipCode = "invalid"; | ||
|
||
//Act and Assert | ||
await Assert.ThrowsAsync<HttpRequestException>(() => Client.SearchAsync(invalidZipCode, default)); | ||
} | ||
|
||
[Fact] | ||
public async Task Search_WithCanceledToken_ThrowsTaskCanceledException() | ||
{ | ||
//Arrange | ||
var cancellationTokenSource = new CancellationTokenSource(); | ||
cancellationTokenSource.Cancel(); | ||
|
||
//Act and Assert | ||
await Assert.ThrowsAsync<TaskCanceledException>(() => | ||
Client.SearchAsync("01001-000", cancellationTokenSource.Token)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters