Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ExchangeRateAPI\ExchangeRateAPI.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using ExchangeRateAPI.Controllers;
using ExchangeRateAPI.Models;
using ExchangeRateUpdater.Business;

namespace ExchangeRateAPIIntegrationTest
{
public class ExchangeRateControllerTest
{
private readonly ExchangeRateController __ExchangeRateController;

public ExchangeRateControllerTest()
{
__ExchangeRateController = new ExchangeRateController(new ExchangeRateProvider());
}

[Fact]
public async Task ExchangeRateController_GetAsync_ShouldReturnResultsAsync()
{
List<ExchangeRateResponse> _Response = await __ExchangeRateController.GetAsync();

Assert.NotNull(_Response);
Assert.Equal(6, _Response.Count);
}
}
}
25 changes: 25 additions & 0 deletions jobs/Backend/ExchangeRateAPI/Adapters/ExchangeRateAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using ExchangeRateAPI.Models;
using ExchangeRateUpdater.Business;

namespace ExchangeRateAPI.Adapters
{
public static class ExchangeRateAdapter
{
public static List<Currency> ConvertToCurrencyList(List<string> currencyCodes)
=> currencyCodes.Select(currencyCode => new Currency(currencyCode)).ToList();

private static ExchangeRateResponse ToExchangeRateResponse(this ExchangeRate exchangeRate)
{
return new ExchangeRateResponse
{
SourceCurrency = exchangeRate.SourceCurrency.Code,
TargetCurrency = exchangeRate.TargetCurrency.Code,
Value = exchangeRate.Value
};
}

public static List<ExchangeRateResponse> ToExchangeRateResponses(this List<ExchangeRate> exchangeRates)
=> exchangeRates.Select(exchangeRate => exchangeRate.ToExchangeRateResponse()).ToList();

}
}
40 changes: 40 additions & 0 deletions jobs/Backend/ExchangeRateAPI/Controllers/ExchangeRateController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using ExchangeRateAPI.Adapters;
using ExchangeRateAPI.Models;
using ExchangeRateUpdater.Business;
using Microsoft.AspNetCore.Mvc;

namespace ExchangeRateAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class ExchangeRateController : ControllerBase
{
private readonly IExchangeRateProvider __ExchangeRateProvider;

private readonly List<string> __Currencies =
[
"AUD",
"USD",
"EUR",
"CZK",
"JPY",
"KES",
"RUB",
"THB",
"TRY",
"XYZ"
];

public ExchangeRateController(IExchangeRateProvider exchangeRateProvider)
{
__ExchangeRateProvider = exchangeRateProvider;
}

[HttpGet(Name = "GetExchangeRates")]
public async Task<List<ExchangeRateResponse>> GetAsync()
{
List<ExchangeRateResponse> _Response = (await __ExchangeRateProvider.GetExchangeRatesAsync(ExchangeRateAdapter.ConvertToCurrencyList(__Currencies))).ToExchangeRateResponses();
return _Response;
}
}
}
20 changes: 20 additions & 0 deletions jobs/Backend/ExchangeRateAPI/ExchangeRateAPI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="10.1.2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="10.1.2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.1.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Task\ExchangeRateUpdater.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions jobs/Backend/ExchangeRateAPI/ExchangeRateAPI.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@ExchangeRateAPI_HostAddress = http://localhost:5164

GET {{ExchangeRateAPI_HostAddress}}/exchangerate/
Accept: application/json

###
16 changes: 16 additions & 0 deletions jobs/Backend/ExchangeRateAPI/Models/ExchangeRateResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Text.Json.Serialization;

namespace ExchangeRateAPI.Models
{
public class ExchangeRateResponse
{
[JsonPropertyName("sourceCurrency")]
public string SourceCurrency { get; set; }

[JsonPropertyName("targetCurrency")]
public string TargetCurrency { get; set; }

[JsonPropertyName("value")]
public decimal Value { get; set; }
}
}
31 changes: 31 additions & 0 deletions jobs/Backend/ExchangeRateAPI/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using ExchangeRateUpdater.Business;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
builder.Services.AddSingleton<IExchangeRateProvider, ExchangeRateProvider>();

// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
38 changes: 38 additions & 0 deletions jobs/Backend/ExchangeRateAPI/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"profiles": {
"http": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5164"
},
"https": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7099;http://localhost:5164"
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
},
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:62116/",
"sslPort": 44304
}
}
}
8 changes: 8 additions & 0 deletions jobs/Backend/ExchangeRateAPI/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions jobs/Backend/ExchangeRateAPI/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
26 changes: 26 additions & 0 deletions jobs/Backend/ExchangeRateAPITest/ExchangeRateAPIUnitTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ExchangeRateAPI\ExchangeRateAPI.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

</Project>
38 changes: 38 additions & 0 deletions jobs/Backend/ExchangeRateAPITest/ExchangeRateControllerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using ExchangeRateAPI.Controllers;
using ExchangeRateAPI.Models;
using ExchangeRateUpdater.Business;
using Moq;

namespace ExchangeRateAPIUnitTest
{
public class ExchangeRateControllerTest
{
private readonly ExchangeRateController __ExchangeRateController;
private readonly Mock<IExchangeRateProvider> __ExchangeRateProviderMock;

public ExchangeRateControllerTest()
{
__ExchangeRateProviderMock = new Mock<IExchangeRateProvider>();
__ExchangeRateController = new ExchangeRateController(__ExchangeRateProviderMock.Object);
}

[Fact]
public async Task ExchangeRateControllerTest_GetAsync_ShouldReturnResultsAsync()
{
List<ExchangeRate> _ExchangeRateMock =
[
new ExchangeRate(new Currency("USD"), new Currency("CZK"), 20.43m),
new ExchangeRate(new Currency("AUD"), new Currency("CZK"), 14.48m),
];

__ExchangeRateProviderMock
.Setup(mock => mock.GetExchangeRatesAsync(It.IsAny<IEnumerable<Currency>>()))
.Returns(Task.FromResult(_ExchangeRateMock));

List<ExchangeRateResponse> _Response = await __ExchangeRateController.GetAsync();

Assert.NotNull(_Response);
Assert.Equal(2, _Response.Count);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using ExchangeRateUpdater.Business;
using ExchangeRateUpdater.Business.Models;
using ExchangeRateUpdater.Business.Services;
using Moq;

namespace ExchangeRateUpdaterUnitTest
{
public class ExchangeRateProviderTest
{
private readonly IExchangeRateProvider __ExchangeRateProvider;
private readonly Mock<IExchangeRateService> __ExchangeRateServiceMock;

public ExchangeRateProviderTest()
{
__ExchangeRateServiceMock = new Mock<IExchangeRateService>();
__ExchangeRateProvider = new ExchangeRateProvider(__ExchangeRateServiceMock.Object);
}

[Fact]
public async Task ExchangeRateProvider_GetExchangeRatesAsync_ShouldReturnResultsAsync()
{
List<ExchangeRateModel> _ExchangeRateModels =
[
new ExchangeRateModel() { CurrencyCode = "USD", Rate = 20.43m },
new ExchangeRateModel() { CurrencyCode = "AUD", Rate = 14.48m },
new ExchangeRateModel() { CurrencyCode = "BRL", Rate = 3.92m },
];

__ExchangeRateServiceMock
.Setup(mock => mock.GetExchangeRatesAsync())
.Returns(Task.FromResult(_ExchangeRateModels))
.Verifiable();

List<Currency> _Currencies =
[
new Currency("AUD"),
new Currency("USD")
];

List<ExchangeRate> _Results = await __ExchangeRateProvider.GetExchangeRatesAsync(_Currencies);

Assert.NotNull(_Results);
Assert.Equal(2, _Results.Count);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Task\ExchangeRateUpdater.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

</Project>
Loading