Skip to content

Commit

Permalink
refactor: use named constants for test cases to enable us maintain th…
Browse files Browse the repository at this point in the history
…e project easily (#11)

* update country identifier to include all countries

* remove duplicate comments for Democratic Republic of the Congo and Madagascar

* bugfix: resolve Aland Islands name

* fix Aland Islands failing test

* use named constants for test cases to enable us maintain the project easily

* add xml comment for state
  • Loading branch information
selfmadecode authored Jan 25, 2025
1 parent a604dec commit 344d2a9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
27 changes: 18 additions & 9 deletions src/World.Net.UnitTests/Countries/AlandIslandsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

public sealed class AlandIslandsTest
{
private const string ALAND_ISLANDS_NAME = "Aland Islands";
private const string ALAND_ISLANDS_OFFICIAL_NAME = "Åland Islands";
private const string ALAND_ISLANDS_NATIVE_NAME = "Åland";
private const string ALAND_ISLANDS_CAPITAL = "Mariehamn";
private const int ALAND_ISLANDS_NUMERIC_CODE = 248;
private const string ALAND_ISLANDS_ISO2_CODE = "AX";
private const string ALAND_ISLANDS_ISO3_CODE = "ALA";
private const string ALAND_ISLANDS_CALLING_CODE = "+358";

[Fact]
public void GetCountry_ReturnsCorrectInformation_ForAlandIslands()
{
Expand All @@ -12,14 +21,14 @@ public void GetCountry_ReturnsCorrectInformation_ForAlandIslands()
var country = CountryProvider.GetCountry(existingCountryId);

//Assert
Assert.Equal(2, country.Id);
Assert.Equal("Aland Islands", country.Name);
Assert.Equal("Åland Islands", country.OfficialName);
Assert.Equal("Åland", country.NativeName);
Assert.Equal("Mariehamn", country.Capital);
Assert.Equal(248, country.NumericCode);
Assert.Equal("AX", country.ISO2Code);
Assert.Equal("ALA", country.ISO3Code);
Assert.Equal("+358", country.CallingCode);
Assert.Equal(existingCountryId, country.Id);
Assert.Equal(ALAND_ISLANDS_NAME, country.Name);
Assert.Equal(ALAND_ISLANDS_OFFICIAL_NAME, country.OfficialName);
Assert.Equal(ALAND_ISLANDS_NATIVE_NAME, country.NativeName);
Assert.Equal(ALAND_ISLANDS_CAPITAL, country.Capital);
Assert.Equal(ALAND_ISLANDS_NUMERIC_CODE, country.NumericCode);
Assert.Equal(ALAND_ISLANDS_ISO2_CODE, country.ISO2Code);
Assert.Equal(ALAND_ISLANDS_ISO3_CODE, country.ISO3Code);
Assert.Equal(ALAND_ISLANDS_CALLING_CODE, country.CallingCode);
}
}
27 changes: 18 additions & 9 deletions src/World.Net.UnitTests/CountryProviderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ namespace World.Net.UnitTests;

public sealed class CountryProviderTest
{
private const string AFGHANISTAN_ISO2_CODE = "AF";
private const string AFGHANISTAN_ISO3_CODE = "AFG";
private const string AFGHANISTAN_CAPITAL = "Kabul";
private const int AFGHANISTAN_NUMERIC_CODE = 004;
private const string AFGHANISTAN_CALLING_CODE = "+93";
private const int AFGHANISTAN_STATE_COUNT = 34;
private const string AFGHANISTAN_NAME = "Afghanistan";
private const string AFGHANISTAN_NATIVE_NAME = "افغانستان";
private const string AFGHANISTAN_OFFICIAL_NAME = "Islamic Republic of Afghanistan";
[Fact]
public void GetAllCountries_ShouldReturn_NonEmptyAndNonNullCollection()
{
Expand All @@ -26,16 +35,16 @@ public void GetCountry_ShouldReturn_Country_WhenCountryExists()
Assert.NotNull(country);
Assert.NotEmpty(country.Name);
Assert.NotEmpty(country.States);
Assert.Equal("AF", country.ISO2Code);
Assert.Equal("AFG", country.ISO3Code);
Assert.Equal("Kabul", country.Capital);
Assert.Equal(004, country.NumericCode);
Assert.Equal("+93", country.CallingCode);
Assert.Equal(34, country.States.Count());
Assert.Equal("Afghanistan", country.Name);
Assert.Equal(AFGHANISTAN_ISO2_CODE, country.ISO2Code);
Assert.Equal(AFGHANISTAN_ISO3_CODE, country.ISO3Code);
Assert.Equal(AFGHANISTAN_CAPITAL, country.Capital);
Assert.Equal(AFGHANISTAN_NUMERIC_CODE, country.NumericCode);
Assert.Equal(AFGHANISTAN_CALLING_CODE, country.CallingCode);
Assert.Equal(AFGHANISTAN_STATE_COUNT, country.States.Count());
Assert.Equal(AFGHANISTAN_NAME, country.Name);
Assert.Equal(existingCountryId, country.Id);
Assert.Equal("افغانستان", country.NativeName);
Assert.Equal("Islamic Republic of Afghanistan", country.OfficialName);
Assert.Equal(AFGHANISTAN_NATIVE_NAME, country.NativeName);
Assert.Equal(AFGHANISTAN_OFFICIAL_NAME, country.OfficialName);
}

[Fact]
Expand Down
3 changes: 3 additions & 0 deletions src/World.Net/State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace World.Net;

/// <summary>
/// Represents a state, province, or region with relevant details such as its name, ISO code, and type.
/// </summary>
public class State
{
/// <summary>
Expand Down

0 comments on commit 344d2a9

Please sign in to comment.