-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Versão com wiremock.net funcionando !
- Loading branch information
1 parent
0eafca3
commit 038c92c
Showing
51 changed files
with
472 additions
and
66 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
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 PoC.TestesServicos.API.Configs | ||
{ | ||
public class CepApiOptions | ||
{ | ||
public string Url { get; set; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/PoC.TestesServicos.Core/Interfaces/ICepClientApiService.cs
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,12 @@ | ||
using Refit; | ||
using System.Threading.Tasks; | ||
using PoC.TestesServicos.Data.Models; | ||
|
||
namespace PoC.TestesServicos.Core.Interfaces | ||
{ | ||
public interface ICepClientApiService | ||
{ | ||
[Get("/ws/{cep}/json")] | ||
Task<CepModel> GetAddressAsync(string cep); | ||
} | ||
} |
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,10 @@ | ||
using System.Threading.Tasks; | ||
using PoC.TestesServicos.Data.Models; | ||
|
||
namespace PoC.TestesServicos.Core.Interfaces | ||
{ | ||
public interface ICepService | ||
{ | ||
Task<CepModel> GetCepDetails(string cep); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/PoC.TestesServicos.Core/Interfaces/ICustomerService.cs
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,10 @@ | ||
using System.Threading.Tasks; | ||
using PoC.TestesServicos.Data.Models; | ||
|
||
namespace PoC.TestesServicos.Core.Interfaces | ||
{ | ||
public interface ICustomerService | ||
{ | ||
Task<Customer> GetCustomerByCode(int code); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/PoC.TestesServicos.Core/PoC.TestesServicos.Core.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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.7" /> | ||
<PackageReference Include="Microsoft.OpenApi" Version="1.1.4" /> | ||
<PackageReference Include="refit" Version="5.1.67" /> | ||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\PoC.TestesServicos.Data\PoC.TestesServicos.Data.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,33 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Options; | ||
using System.Configuration; | ||
using PoC.TestesServicos.Core.Interfaces; | ||
using PoC.TestesServicos.API.Configs; | ||
using PoC.TestesServicos.Data.Models; | ||
using Refit; | ||
|
||
|
||
namespace PoC.TestesServicos.Core.Services | ||
{ | ||
public class CepService : ICepService | ||
{ | ||
private readonly CepApiOptions _cepApiOptions; | ||
|
||
public CepService(IOptions<CepApiOptions> cepApiOptions) | ||
{ | ||
_cepApiOptions = cepApiOptions.Value; | ||
} | ||
|
||
public async Task<CepModel> GetCepDetails(string cep) | ||
{ | ||
if (_cepApiOptions == null) | ||
throw new ConfigurationErrorsException("Cep API Url setting must be configured!"); | ||
|
||
ICepClientApiService client = RestService.For<ICepClientApiService>(_cepApiOptions.Url); | ||
|
||
CepModel cepDetails = await client.GetAddressAsync(cep); | ||
|
||
return cepDetails; | ||
} | ||
} | ||
} |
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,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using PoC.TestesServicos.Core.Interfaces; | ||
using PoC.TestesServicos.Data.Models; | ||
|
||
namespace PoC.TestesServicos.Core.Services | ||
{ | ||
public class CustomerService : ICustomerService | ||
{ | ||
private readonly ICepService _cepService; | ||
|
||
public CustomerService(ICepService cepService) | ||
{ | ||
_cepService = cepService; | ||
} | ||
|
||
public async Task<Customer> GetCustomerByCode(int code) | ||
{ | ||
Customer customerResponse = CustomerFakeRepository(c => c.Code == code) | ||
.FirstOrDefault(); | ||
|
||
if(customerResponse != null && !string.IsNullOrEmpty(customerResponse.Cep)) | ||
customerResponse.CepDetails = await _cepService.GetCepDetails(customerResponse.Cep); | ||
|
||
return customerResponse; | ||
} | ||
|
||
private IEnumerable<Customer> CustomerFakeRepository(Func<Customer, bool> predicate) | ||
{ | ||
IList<Customer> customers = new List<Customer> | ||
{ | ||
new Customer { Code = 1, Name = "Customer 01", Cep = "95600106" }, | ||
new Customer { Code = 2, Name = "Customer 02", Cep = "95600104" } | ||
}; | ||
|
||
return customers.Where(predicate); | ||
} | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,27 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace PoC.TestesServicos.Data.Models | ||
{ | ||
public class CepModel | ||
{ | ||
[JsonProperty("cep")] | ||
public string Cep { get; set; } | ||
[JsonProperty("logradouro")] | ||
public string Logradouro { get; set; } | ||
[JsonProperty("complemento")] | ||
public string Complemento { get; set; } | ||
[JsonProperty("bairro")] | ||
public string Bairro { get; set; } | ||
[JsonProperty("localidade")] | ||
public string Localidade { get; set; } | ||
[JsonProperty("uf")] | ||
public string Uf { get; set; } | ||
[JsonProperty("unidade")] | ||
public string Unidade { get; set; } | ||
[JsonProperty("ibge")] | ||
public string Ibge { get; set; } | ||
[JsonProperty("gia")] | ||
public string Gia { get; set; } | ||
|
||
} | ||
} |
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,10 @@ | ||
namespace PoC.TestesServicos.Data.Models | ||
{ | ||
public class Customer | ||
{ | ||
public int Code { get; set; } | ||
public string Name { get; set; } | ||
public string Cep { get; set; } | ||
public CepModel CepDetails { get; set; } | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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,39 @@ | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
using PoC.TestesServicos.Data.Models; | ||
using PoC.TestesServicos.Tests.Fixtures; | ||
using Xunit; | ||
|
||
namespace PoC.TestesServicos.Tests | ||
{ | ||
[Collection("Integration containers collection")] | ||
public class CustomerClientTests : ControllerTestsBase | ||
{ | ||
public CustomerClientTests(IntegrationContainersAppFactory integrationContainersFixture) | ||
: base(integrationContainersFixture) | ||
{ | ||
} | ||
|
||
[Theory] | ||
[Trait("Categoria", "Componente")] | ||
[InlineData("1")] | ||
[InlineData("2")] | ||
public async Task Should_Get_A_Valid_Customer_With_CepDetails_For_Customer_Code(string customerCode) | ||
{ | ||
string actualResponseContent; | ||
HttpResponseMessage response; | ||
Customer customerResponse; | ||
|
||
response = await Client.GetAsync($"/api/Customer/{customerCode}"); | ||
response.EnsureSuccessStatusCode(); | ||
|
||
actualResponseContent = await response.Content.ReadAsStringAsync(); | ||
customerResponse = JsonConvert.DeserializeObject<Customer>(actualResponseContent); | ||
|
||
Assert.Equal("Mocked", customerResponse.CepDetails.Localidade); | ||
} | ||
|
||
|
||
} | ||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.