Skip to content

Commit

Permalink
Optimize startup
Browse files Browse the repository at this point in the history
  • Loading branch information
pentp committed Sep 24, 2020
1 parent 9ae7481 commit bddc355
Show file tree
Hide file tree
Showing 25 changed files with 487 additions and 709 deletions.
33 changes: 0 additions & 33 deletions csharp/PhoneNumbers.Test/CountryCodeToRegionCodeMapForTesting.cs

This file was deleted.

5 changes: 5 additions & 0 deletions csharp/PhoneNumbers.Test/PhoneNumbers.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="..\..\resources\PhoneNumberMetaDataForTesting.xml" />
<EmbeddedResource Include="..\..\resources\test\geocoding\**" LinkBase="geocoding" />
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions csharp/PhoneNumbers.Test/TestAsYouTypeFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ namespace PhoneNumbers.Test
* @author Shaopeng Jia
*/
[Collection("TestMetadataTestCase")]
public class TestAsYouTypeFormatter : IClassFixture<TestMetadataTestCase>
public class TestAsYouTypeFormatter
{
private readonly PhoneNumberUtil phoneUtil;

public TestAsYouTypeFormatter(TestMetadataTestCase metadata)
public TestAsYouTypeFormatter()
{
phoneUtil = metadata.PhoneUtil;
phoneUtil = TestMetadataTestCase.PhoneUtil;
}

[Fact]
Expand Down
10 changes: 1 addition & 9 deletions csharp/PhoneNumbers.Test/TestExampleNumbers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,10 @@ namespace PhoneNumbers.Test
[Collection("TestMetadataTestCase")]
public class TestExampleNumbers
{
private readonly PhoneNumberUtil phoneNumberUtil;
private readonly PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.GetInstance();
private readonly List<PhoneNumber> invalidCases = new List<PhoneNumber>();
private readonly List<PhoneNumber> wrongTypeCases = new List<PhoneNumber>();

public TestExampleNumbers()
{
invalidCases.Clear();
wrongTypeCases.Clear();
PhoneNumberUtil.ResetInstance();
phoneNumberUtil = PhoneNumberUtil.GetInstance();
}

/**
* @param exampleNumberRequestedType type we are requesting an example number for
* @param possibleExpectedTypes acceptable types that this number should match, such as
Expand Down
28 changes: 14 additions & 14 deletions csharp/PhoneNumbers.Test/TestMappingFileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ public TestMappingFileProvider()
mappingProvider.ReadFileConfigs(mapping);
}

[Fact(Skip = "No binary yet")]
[Fact]
public void TestGetFileName()
{
Assert.Equal("1_en", mappingProvider.GetFileName(1, "en", "", ""));
Assert.Equal("1_en", mappingProvider.GetFileName(1, "en", "", "US"));
Assert.Equal("1_en", mappingProvider.GetFileName(1, "en", "", "GB"));
Assert.Equal("41_de", mappingProvider.GetFileName(41, "de", "", "CH"));
Assert.Equal("en.1.txt", mappingProvider.GetFileName(1, "en", "", ""));
Assert.Equal("en.1.txt", mappingProvider.GetFileName(1, "en", "", "US"));
Assert.Equal("en.1.txt", mappingProvider.GetFileName(1, "en", "", "GB"));
Assert.Equal("de.41.txt", mappingProvider.GetFileName(41, "de", "", "CH"));
Assert.Equal("", mappingProvider.GetFileName(44, "en", "", "GB"));
Assert.Equal("86_zh", mappingProvider.GetFileName(86, "zh", "", ""));
Assert.Equal("86_zh", mappingProvider.GetFileName(86, "zh", "Hans", ""));
Assert.Equal("86_zh", mappingProvider.GetFileName(86, "zh", "", "CN"));
Assert.Equal("zh.86.txt", mappingProvider.GetFileName(86, "zh", "", ""));
Assert.Equal("zh.86.txt", mappingProvider.GetFileName(86, "zh", "Hans", ""));
Assert.Equal("zh.86.txt", mappingProvider.GetFileName(86, "zh", "", "CN"));
Assert.Equal("", mappingProvider.GetFileName(86, "", "", "CN"));
Assert.Equal("86_zh", mappingProvider.GetFileName(86, "zh", "Hans", "CN"));
Assert.Equal("86_zh", mappingProvider.GetFileName(86, "zh", "Hans", "SG"));
Assert.Equal("86_zh", mappingProvider.GetFileName(86, "zh", "", "SG"));
Assert.Equal("86_zh_Hant", mappingProvider.GetFileName(86, "zh", "", "TW"));
Assert.Equal("86_zh_Hant", mappingProvider.GetFileName(86, "zh", "", "HK"));
Assert.Equal("86_zh_Hant", mappingProvider.GetFileName(86, "zh", "Hant", "TW"));
Assert.Equal("zh.86.txt", mappingProvider.GetFileName(86, "zh", "Hans", "CN"));
Assert.Equal("zh.86.txt", mappingProvider.GetFileName(86, "zh", "Hans", "SG"));
Assert.Equal("zh.86.txt", mappingProvider.GetFileName(86, "zh", "", "SG"));
Assert.Equal("zh_Hant.86.txt", mappingProvider.GetFileName(86, "zh", "", "TW"));
Assert.Equal("zh_Hant.86.txt", mappingProvider.GetFileName(86, "zh", "", "HK"));
Assert.Equal("zh_Hant.86.txt", mappingProvider.GetFileName(86, "zh", "Hant", "TW"));
}
}
}
18 changes: 1 addition & 17 deletions csharp/PhoneNumbers.Test/TestMetadataTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ namespace PhoneNumbers.Test
*/
public class TestMetadataTestCase
{
public const string TestMetaDataFilePrefix = "PhoneNumberMetaDataForTesting.xml";

public readonly PhoneNumberUtil PhoneUtil;

// ReSharper disable once MemberCanBeProtected.Global
public TestMetadataTestCase()
{
PhoneUtil = InitializePhoneUtilForTesting();
}

static PhoneNumberUtil InitializePhoneUtilForTesting()
{
PhoneNumberUtil.ResetInstance();
return PhoneNumberUtil.GetInstance(
TestMetaDataFilePrefix,
CountryCodeToRegionCodeMapForTesting.GetCountryCodeToRegionCodeMap());
}
public static readonly PhoneNumberUtil PhoneUtil = new PhoneNumberUtil("PhoneNumberMetaDataForTesting.xml", typeof(TestMetadataTestCase).Assembly);
}
}
6 changes: 3 additions & 3 deletions csharp/PhoneNumbers.Test/TestPhoneNumberMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
namespace PhoneNumbers.Test
{
[Collection("TestMetadataTestCase")]
public class TestPhoneNumberMatcher: IClassFixture<TestMetadataTestCase>
public class TestPhoneNumberMatcher
{
private readonly PhoneNumberUtil phoneUtil;

public TestPhoneNumberMatcher(TestMetadataTestCase metadata)
public TestPhoneNumberMatcher()
{
phoneUtil = metadata.PhoneUtil;
phoneUtil = TestMetadataTestCase.PhoneUtil;
}

/** See {@link PhoneNumberUtilTest#testParseNationalNumber()}. */
Expand Down
13 changes: 3 additions & 10 deletions csharp/PhoneNumbers.Test/TestPhoneNumberOfflineGeocoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace PhoneNumbers.Test
[Collection("TestMetadataTestCase")]
public class TestPhoneNumberOfflineGeocoder
{
private PhoneNumberOfflineGeocoder geocoder;
private const string TEST_MAPPING_DATA_DIRECTORY = "test.geocoding.";
private static readonly PhoneNumberOfflineGeocoder geocoder =
new PhoneNumberOfflineGeocoder("geocoding.", typeof(TestPhoneNumberOfflineGeocoder).Assembly);

// Set up some test numbers to re-use.
private static readonly PhoneNumber KONumber1 =
Expand Down Expand Up @@ -57,17 +57,10 @@ public class TestPhoneNumberOfflineGeocoder
private static readonly PhoneNumber InternationalTollFree =
new PhoneNumber.Builder().SetCountryCode(800).SetNationalNumber(12345678L).Build();

public TestPhoneNumberOfflineGeocoder()
{
PhoneNumberUtil.ResetInstance();
geocoder = new PhoneNumberOfflineGeocoder(TEST_MAPPING_DATA_DIRECTORY);
}

[Fact]
public void TestInstantiationWithRegularData()
{
PhoneNumberUtil.ResetInstance();
geocoder = PhoneNumberOfflineGeocoder.GetInstance();
Assert.NotNull(PhoneNumberOfflineGeocoder.GetInstance());
}

[Fact]
Expand Down
6 changes: 3 additions & 3 deletions csharp/PhoneNumbers.Test/TestPhoneNumberUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ namespace PhoneNumbers.Test
* @author Lara Rennie
*/
[Collection("TestMetadataTestCase")]
public class TestPhoneNumberUtil : IClassFixture<TestMetadataTestCase>
public class TestPhoneNumberUtil
{
private readonly PhoneNumberUtil phoneUtil;

public TestPhoneNumberUtil(TestMetadataTestCase metadata)
public TestPhoneNumberUtil()
{
phoneUtil = metadata.PhoneUtil;
phoneUtil = TestMetadataTestCase.PhoneUtil;
}

// Set up some test numbers to re-use.
Expand Down
Loading

0 comments on commit bddc355

Please sign in to comment.