Skip to content

Commit

Permalink
Add some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint committed Jan 15, 2016
1 parent 97840e9 commit 0a40c95
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions TimeZoneNames.Tests/TimeZoneCountriesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,22 @@ public void Can_Get_Zones_For_RU()

Assert.True(!zones.Contains("Europe/London"));
}

[Fact]
public void Can_Get_Zones_For_CA()
{
var zones = TimeZoneNames.GetTimeZoneIdsForCountry("CA");

foreach (var zone in zones)
_output.WriteLine(zone);

Assert.Equal(28, zones.Length);

Assert.True(zones.Contains("America/Vancouver"));
Assert.True(zones.Contains("America/Fort_Nelson"));
Assert.True(zones.Contains("America/Toronto"));

Assert.True(!zones.Contains("Europe/London"));
}
}
}
28 changes: 28 additions & 0 deletions TimeZoneNames.Tests/TimeZoneNamesForCountriesTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -122,5 +124,31 @@ public void Can_Get_Names_For_PG_English()
Assert.Equal(expected.Value[2], zones[tz].Daylight);
}
}

[Fact]
public void Can_Get_Names_For_All_Countries()
{
var countries = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
.Select(x => new RegionInfo(x.LCID).TwoLetterISORegionName)
.Where(x => !string.IsNullOrEmpty(x))
.Where(x=> x.Length == 2)
.OrderBy(x => x)
.Distinct();

foreach (var country in countries)
{
try
{
var zones = TimeZoneNames.GetTimeZonesForCountry(country, "en");
_output.WriteLine(country + ": " + zones.Count);
Assert.NotEqual(0, zones.Count);
}
catch
{
_output.WriteLine(country + " -- FAILED");
throw;
}
}
}
}
}

0 comments on commit 0a40c95

Please sign in to comment.