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,47 @@
using FluentAssertions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using paymentsense.geographic.business;
using paymentsense.utility;
using Paymentsense.Coding.Challenge.Api.Controllers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Xunit;

namespace Paymentsense.Coding.Challenge.Api.Tests.Controllers
{

public class GeographicControllerTests
{
private IServiceCollection services;
private IServiceProvider serviceProvider;
public GeographicControllerTests()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false, true);
var configuration = builder.Build();
services = new ServiceCollection();
services.UseGeoGraphicServices();
services.AddMemoryCache();
services.AddSingleton<IConfiguration>(configuration);
serviceProvider = services.BuildServiceProvider();

}

[Fact]
public void Get_OnInvoke_ReturnsExpectedMessage()
{
var controller = new GeographicController(serviceProvider.GetRequiredService<IGeographic>());

var result = controller.GetCountries().Result as OkObjectResult;

result.StatusCode.Should().Be(StatusCodes.Status200OK);
result.Value.Should().NotBeNull();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<None Remove="appsettings.Development.json" />
<None Remove="appsettings.json" />
</ItemGroup>

<ItemGroup>
<Content Include="appsettings.Development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.9.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"RestGetCountryBaseUrl": "https://restcountries.eu/rest/v2/all",
"AllowedHosts": "*"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Paymentsense.Coding.Challen
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Paymentsense.Coding.Challenge.Api.Tests", "Paymentsense.Coding.Challenge.Api.Tests\Paymentsense.Coding.Challenge.Api.Tests.csproj", "{29B33764-7D72-4940-90F9-28467B569288}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "paymentsense.geographic.business", "paymentsense.geographic.business\paymentsense.geographic.business.csproj", "{019F8FA6-93A7-4C67-B1F2-B94621C73375}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "paymentsense.common", "paymentsense.common\paymentsense.common.csproj", "{77EA15B9-720C-4BCA-BDF5-33911F73E179}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "paymentsense.utility", "paymentsense.utility\paymentsense.utility.csproj", "{FAC3A7F9-3FC6-42CE-9658-2436A4D643E4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -41,6 +47,42 @@ Global
{29B33764-7D72-4940-90F9-28467B569288}.Release|x64.Build.0 = Release|Any CPU
{29B33764-7D72-4940-90F9-28467B569288}.Release|x86.ActiveCfg = Release|Any CPU
{29B33764-7D72-4940-90F9-28467B569288}.Release|x86.Build.0 = Release|Any CPU
{019F8FA6-93A7-4C67-B1F2-B94621C73375}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{019F8FA6-93A7-4C67-B1F2-B94621C73375}.Debug|Any CPU.Build.0 = Debug|Any CPU
{019F8FA6-93A7-4C67-B1F2-B94621C73375}.Debug|x64.ActiveCfg = Debug|Any CPU
{019F8FA6-93A7-4C67-B1F2-B94621C73375}.Debug|x64.Build.0 = Debug|Any CPU
{019F8FA6-93A7-4C67-B1F2-B94621C73375}.Debug|x86.ActiveCfg = Debug|Any CPU
{019F8FA6-93A7-4C67-B1F2-B94621C73375}.Debug|x86.Build.0 = Debug|Any CPU
{019F8FA6-93A7-4C67-B1F2-B94621C73375}.Release|Any CPU.ActiveCfg = Release|Any CPU
{019F8FA6-93A7-4C67-B1F2-B94621C73375}.Release|Any CPU.Build.0 = Release|Any CPU
{019F8FA6-93A7-4C67-B1F2-B94621C73375}.Release|x64.ActiveCfg = Release|Any CPU
{019F8FA6-93A7-4C67-B1F2-B94621C73375}.Release|x64.Build.0 = Release|Any CPU
{019F8FA6-93A7-4C67-B1F2-B94621C73375}.Release|x86.ActiveCfg = Release|Any CPU
{019F8FA6-93A7-4C67-B1F2-B94621C73375}.Release|x86.Build.0 = Release|Any CPU
{77EA15B9-720C-4BCA-BDF5-33911F73E179}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{77EA15B9-720C-4BCA-BDF5-33911F73E179}.Debug|Any CPU.Build.0 = Debug|Any CPU
{77EA15B9-720C-4BCA-BDF5-33911F73E179}.Debug|x64.ActiveCfg = Debug|Any CPU
{77EA15B9-720C-4BCA-BDF5-33911F73E179}.Debug|x64.Build.0 = Debug|Any CPU
{77EA15B9-720C-4BCA-BDF5-33911F73E179}.Debug|x86.ActiveCfg = Debug|Any CPU
{77EA15B9-720C-4BCA-BDF5-33911F73E179}.Debug|x86.Build.0 = Debug|Any CPU
{77EA15B9-720C-4BCA-BDF5-33911F73E179}.Release|Any CPU.ActiveCfg = Release|Any CPU
{77EA15B9-720C-4BCA-BDF5-33911F73E179}.Release|Any CPU.Build.0 = Release|Any CPU
{77EA15B9-720C-4BCA-BDF5-33911F73E179}.Release|x64.ActiveCfg = Release|Any CPU
{77EA15B9-720C-4BCA-BDF5-33911F73E179}.Release|x64.Build.0 = Release|Any CPU
{77EA15B9-720C-4BCA-BDF5-33911F73E179}.Release|x86.ActiveCfg = Release|Any CPU
{77EA15B9-720C-4BCA-BDF5-33911F73E179}.Release|x86.Build.0 = Release|Any CPU
{FAC3A7F9-3FC6-42CE-9658-2436A4D643E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FAC3A7F9-3FC6-42CE-9658-2436A4D643E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FAC3A7F9-3FC6-42CE-9658-2436A4D643E4}.Debug|x64.ActiveCfg = Debug|Any CPU
{FAC3A7F9-3FC6-42CE-9658-2436A4D643E4}.Debug|x64.Build.0 = Debug|Any CPU
{FAC3A7F9-3FC6-42CE-9658-2436A4D643E4}.Debug|x86.ActiveCfg = Debug|Any CPU
{FAC3A7F9-3FC6-42CE-9658-2436A4D643E4}.Debug|x86.Build.0 = Debug|Any CPU
{FAC3A7F9-3FC6-42CE-9658-2436A4D643E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FAC3A7F9-3FC6-42CE-9658-2436A4D643E4}.Release|Any CPU.Build.0 = Release|Any CPU
{FAC3A7F9-3FC6-42CE-9658-2436A4D643E4}.Release|x64.ActiveCfg = Release|Any CPU
{FAC3A7F9-3FC6-42CE-9658-2436A4D643E4}.Release|x64.Build.0 = Release|Any CPU
{FAC3A7F9-3FC6-42CE-9658-2436A4D643E4}.Release|x86.ActiveCfg = Release|Any CPU
{FAC3A7F9-3FC6-42CE-9658-2436A4D643E4}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using paymentsense.geographic.business;

namespace Paymentsense.Coding.Challenge.Api.Controllers
{

[ApiController]
[Route("[controller]")]
public class GeographicController : ControllerBase
{
IGeographic _geographic;
public GeographicController(IGeographic geographic)
{
_geographic = geographic;
}

// GET: Geographic/countries
[HttpGet]
[Route("countries")]
public async Task<IActionResult> GetCountries()
{
var data = await _geographic.GetCountries();
return Ok(data);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@
<Folder Include="Services\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\paymentsense.geographic.business\paymentsense.geographic.business.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using paymentsense.geographic.business;

namespace Paymentsense.Coding.Challenge.Api
{
Expand All @@ -29,6 +30,8 @@ public void ConfigureServices(IServiceCollection services)
.AllowAnyHeader();
});
});
services.AddMemoryCache();
services.UseGeoGraphicServices();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"Microsoft.Hosting.Lifetime": "Information"
}
},
"RestGetCountryBaseUrl": "https://restcountries.eu/rest/v2/all",
"AllowedHosts": "*"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections.Generic;

namespace paymentsense.common.Contracts.Geographic
{
public class Country
{
public string name { get; set; }
public List<string> topLevelDomain { get; set; }
public string alpha2Code { get; set; }
public string alpha3Code { get; set; }
public List<string> callingCodes { get; set; }
public string capital { get; set; }
public List<string> altSpellings { get; set; }
public string region { get; set; }
public string subregion { get; set; }
public int population { get; set; }
public List<double?> latlng { get; set; }
public string demonym { get; set; }
public double? area { get; set; }
public double? gini { get; set; }
public List<string> timezones { get; set; }
public List<string> borders { get; set; }
public string nativeName { get; set; }
public string numericCode { get; set; }
public List<Currency> currencies { get; set; }
public List<Language> languages { get; set; }
public Translations translations { get; set; }
public string flag { get; set; }
public List<RegionalBloc> regionalBlocs { get; set; }
public string cioc { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace paymentsense.common.Contracts.Geographic
{
public class Currency
{
public string code { get; set; }
public string name { get; set; }
public string symbol { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace paymentsense.common.Contracts.Geographic
{
public class Language
{
public string iso639_1 { get; set; }
public string iso639_2 { get; set; }
public string name { get; set; }
public string nativeName { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;

namespace paymentsense.common.Contracts.Geographic
{
public class RegionalBloc
{
public string acronym { get; set; }
public string name { get; set; }
public List<object> otherAcronyms { get; set; }
public List<string> otherNames { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace paymentsense.common.Contracts.Geographic
{
public class Translations
{
public string de { get; set; }
public string es { get; set; }
public string fr { get; set; }
public string ja { get; set; }
public string it { get; set; }
public string br { get; set; }
public string pt { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.Extensions.DependencyInjection;
using paymentsense.utility;

namespace paymentsense.geographic.business
{
public static class Bootstrapper
{
public static void UseGeoGraphicServices(this IServiceCollection services)
{
services.UseUtilityServices();
services.AddSingleton<IGeographic, Geographic>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Microsoft.Extensions.Configuration;
using paymentsense.common.Contracts.Geographic;
using paymentsense.utility.CacheHelpers;
using paymentsense.utility.HtppHelpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace paymentsense.geographic.business
{
public class Geographic : IGeographic
{
ICache _cache;
IHttpHelpers _httpHelpers;
string countryCacheKey = "lstcountry";
string url = string.Empty;
public Geographic(ICache cache, IHttpHelpers httpHelpers, IConfiguration config)
{
_cache = cache;
_httpHelpers = httpHelpers;
url = config.GetValue<string>("RestGetCountryBaseUrl");
}

public async Task<IEnumerable<Country>> GetCountries()
{
List<Country> countries = new List<Country>();
try
{
countries = _cache.Get<List<Country>>(countryCacheKey);
if (countries == null || countries.Any() == false)
{
countries = await _httpHelpers.Get<List<Country>>(url);
_cache.Set<List<Country>>(countryCacheKey,countries);
}
}
catch (Exception ex)
{
}
return countries;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using paymentsense.common.Contracts.Geographic;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace paymentsense.geographic.business
{
public interface IGeographic
{
Task<IEnumerable<Country>> GetCountries();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\paymentsense.common\paymentsense.common.csproj" />
<ProjectReference Include="..\paymentsense.utility\paymentsense.utility.csproj" />
</ItemGroup>

</Project>
Loading