Skip to content

Commit

Permalink
Merge pull request #321 from maxmind/greg/net-9
Browse files Browse the repository at this point in the history
Update targets and misc cleanup
  • Loading branch information
horgh authored Nov 22, 2024
2 parents 4c8aad5 + e3c232e commit eef75bb
Show file tree
Hide file tree
Showing 20 changed files with 215 additions and 235 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
9.0.x
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
9.0.x
- name: Build
run: |
Expand Down
6 changes: 3 additions & 3 deletions MaxMind.GeoIP2.Benchmark/MaxMind.GeoIP2.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<Description>Benchmark project to validate MaxMind GeoIP2 Database Reader and Web Service Client</Description>
<VersionPrefix>5.0.0</VersionPrefix>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net8.0;net7.0;net6.0;net472</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net9.0;net8.0;net481</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">net9.0;net8.0</TargetFrameworks>
<AssemblyName>MaxMind.GeoIP2.Benchmark</AssemblyName>
<OutputType>Exe</OutputType>
<AssemblyOriginatorKeyFile>../MaxMind.snk</AssemblyOriginatorKeyFile>
Expand All @@ -20,7 +20,7 @@
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<LangVersion>12.0</LangVersion>
<LangVersion>13.0</LangVersion>
<Nullable>enable</Nullable>
<AnalysisLevel>latest</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
Expand Down
2 changes: 1 addition & 1 deletion MaxMind.GeoIP2.UnitTests/DeserializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private static void CanDeserializeInsightsResponse(InsightsResponse insights)
Assert.Equal("004", insights.Traits.MobileNetworkCode);

var network = insights.Traits.Network!;
Assert.Equal("1.2.3.0", network.NetworkAddress?.ToString());
Assert.Equal("1.2.3.0", network.NetworkAddress.ToString());
Assert.Equal(24, network.PrefixLength);

Assert.Equal("Blorg", insights.Traits.Organization);
Expand Down
14 changes: 7 additions & 7 deletions MaxMind.GeoIP2.UnitTests/MaxMind.GeoIP2.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<Description>Test project to validate MaxMind GeoIP2 Database Reader and Web Service Client</Description>
<VersionPrefix>5.0.0</VersionPrefix>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net8.0;net7.0;net6.0;net472</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net9.0;net8.0;net481</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">net9.0;net8.0</TargetFrameworks>
<AssemblyName>MaxMind.GeoIP2.UnitTests</AssemblyName>
<AssemblyOriginatorKeyFile>../MaxMind.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand All @@ -20,7 +20,7 @@
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<LangVersion>12.0</LangVersion>
<LangVersion>13.0</LangVersion>
<Nullable>enable</Nullable>
<AnalysisLevel>latest</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
Expand All @@ -29,10 +29,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="WireMock.Net" Version="1.5.40" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="WireMock.Net" Version="1.6.7" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
222 changes: 112 additions & 110 deletions MaxMind.GeoIP2.UnitTests/ResponseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,122 +2,124 @@
{
internal static class ResponseHelper
{
public static string InsightsJson = @"
{
""city"": {
""confidence"": 76,
""geoname_id"": 9876,
""names"": {""en"": ""Minneapolis""}
},
""continent"": {
""code"": ""NA"",
""geoname_id"": 42,
""names"": {""en"": ""North America""}
},
""country"": {
""confidence"": 99,
""iso_code"": ""US"",
""geoname_id"": 1,
""names"": {""en"": ""United States of America""}
},
""location"": {
""accuracy_radius"": 1500,
""average_income"": 50000,
""latitude"": 44.98,
""longitude"": 93.2636,
""metro_code"": 765,
""population_density"": 100,
""time_zone"": ""America/Chicago""
},
""postal"": {
""confidence"": 33,
""code"": ""55401""
},
""registered_country"": {
""geoname_id"": 2,
""is_in_european_union"": true,
""iso_code"": ""DE"",
""names"": {""en"": ""Germany""}
},
""represented_country"": {
""geoname_id"": 3,
""is_in_european_union"": true,
""iso_code"": ""GB"",
""names"": {""en"": ""United Kingdom""},
""type"": ""military""
},
""subdivisions"": [
{
""confidence"": 88,
""geoname_id"": 574635,
""iso_code"": ""MN"",
""names"": {""en"": ""Minnesota""}
public static string InsightsJson = """
{
"city": {
"confidence": 76,
"geoname_id": 9876,
"names": {"en": "Minneapolis"}
},
{""iso_code"": ""TT""}
],
""traits"": {
""autonomous_system_number"": 1234,
""autonomous_system_organization"": ""AS Organization"",
""connection_type"": ""Cable/DSL"",
""domain"": ""example.com"",
""ip_address"": ""1.2.3.4"",
""is_anonymous"": true,
""is_anonymous_proxy"": true,
""is_anonymous_vpn"": true,
""is_anycast"": true,
""is_hosting_provider"": true,
""is_public_proxy"": true,
""is_residential_proxy"": true,
""is_satellite_provider"": true,
""is_tor_exit_node"": true,
""isp"": ""Comcast"",
""mobile_country_code"": ""310"",
""mobile_network_code"": ""004"",
""network"": ""1.2.3.0/24"",
""organization"": ""Blorg"",
""static_ip_score"": 1.5,
""user_count"": 1,
""user_type"": ""college""
},
""maxmind"": {""queries_remaining"": 11}
}";
"continent": {
"code": "NA",
"geoname_id": 42,
"names": {"en": "North America"}
},
"country": {
"confidence": 99,
"iso_code": "US",
"geoname_id": 1,
"names": {"en": "United States of America"}
},
"location": {
"accuracy_radius": 1500,
"average_income": 50000,
"latitude": 44.98,
"longitude": 93.2636,
"metro_code": 765,
"population_density": 100,
"time_zone": "America/Chicago"
},
"postal": {
"confidence": 33,
"code": "55401"
},
"registered_country": {
"geoname_id": 2,
"is_in_european_union": true,
"iso_code": "DE",
"names": {"en": "Germany"}
},
"represented_country": {
"geoname_id": 3,
"is_in_european_union": true,
"iso_code": "GB",
"names": {"en": "United Kingdom"},
"type": "military"
},
"subdivisions": [
{
"confidence": 88,
"geoname_id": 574635,
"iso_code": "MN",
"names": {"en": "Minnesota"}
},
{"iso_code": "TT"}
],
"traits": {
"autonomous_system_number": 1234,
"autonomous_system_organization": "AS Organization",
"connection_type": "Cable/DSL",
"domain": "example.com",
"ip_address": "1.2.3.4",
"is_anonymous": true,
"is_anonymous_proxy": true,
"is_anonymous_vpn": true,
"is_anycast": true,
"is_hosting_provider": true,
"is_public_proxy": true,
"is_residential_proxy": true,
"is_satellite_provider": true,
"is_tor_exit_node": true,
"isp": "Comcast",
"mobile_country_code": "310",
"mobile_network_code": "004",
"network": "1.2.3.0/24",
"organization": "Blorg",
"static_ip_score": 1.5,
"user_count": 1,
"user_type": "college"
},
"maxmind": {"queries_remaining": 11}
}
""";

public static string CountryJson = @"
{
""continent"": {
""code"": ""NA"",
""geoname_id"": 42,
""names"": {""en"": ""North America""}
},
""country"": {
""geoname_id"": 1,
""iso_code"": ""US"",
""confidence"": 56,
""names"": {""en"": ""United States""}
},
""registered_country"": {
""geoname_id"": 2,
""is_in_european_union"": true ,
""iso_code"": ""DE"",
""names"": {""en"": ""Germany""}
},
""represented_country"": {
""geoname_id"": 4,
""is_in_european_union"": true ,
""iso_code"": ""GB"",
""names"": {""en"": ""United Kingdom""},
""type"": ""military""
},
""traits"": {
""ip_address"": ""1.2.3.4"",
""is_anycast"": true,
""network"": ""1.2.3.0/24""
public static string CountryJson = """
{
"continent": {
"code": "NA",
"geoname_id": 42,
"names": {"en": "North America"}
},
"country": {
"geoname_id": 1,
"iso_code": "US",
"confidence": 56,
"names": {"en": "United States"}
},
"registered_country": {
"geoname_id": 2,
"is_in_european_union": true ,
"iso_code": "DE",
"names": {"en": "Germany"}
},
"represented_country": {
"geoname_id": 4,
"is_in_european_union": true ,
"iso_code": "GB",
"names": {"en": "United Kingdom"},
"type": "military"
},
"traits": {
"ip_address": "1.2.3.4",
"is_anycast": true,
"network": "1.2.3.0/24"
}
}
}";
""";

public static string ErrorJson(string code, string message)
{
return $@"{{""code"": ""{code}"", ""error"": ""{message}""}}";
return $$"""{"code": "{{code}}", "error": "{{message}}"}""";
}
}
}
41 changes: 17 additions & 24 deletions MaxMind.GeoIP2.UnitTests/WebServiceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,43 +36,36 @@ public WebServiceClientTests()
public static readonly object[][] TestCases =
{
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
new object[] {"country", (ClientRunner) (async (c, i) => c.Country(i)), typeof(CountryResponse)},
["country", (ClientRunner) (async (c, i) => c.Country(i)), typeof(CountryResponse)],
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
new object[] {"city", (ClientRunner) (async (c, i) => c.City(i)), typeof(CityResponse)},
["city", (ClientRunner) (async (c, i) => c.City(i)), typeof(CityResponse)],
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
new object[] {"insights", (ClientRunner) (async (c, i) => c.Insights(i)), typeof(InsightsResponse)},
["insights", (ClientRunner) (async (c, i) => c.Insights(i)), typeof(InsightsResponse)],
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
new object[]
{"countryAsync", (ClientRunner) (async (c, i) => await c.CountryAsync(i)), typeof(CountryResponse)},
new object[] {"cityAsync", (ClientRunner) (async (c, i) => await c.CityAsync(i)), typeof(CityResponse)},
new object[]
{"insightsAsync", (ClientRunner) (async (c, i) => await c.InsightsAsync(i)), typeof(InsightsResponse)}
["countryAsync", (ClientRunner) (async (c, i) => await c.CountryAsync(i)), typeof(CountryResponse)],
["cityAsync", (ClientRunner) (async (c, i) => await c.CityAsync(i)), typeof(CityResponse)],
["insightsAsync", (ClientRunner) (async (c, i) => await c.InsightsAsync(i)), typeof(InsightsResponse)]
};

public delegate Task<AbstractCountryResponse> MeClientRunner(WebServiceClient c);

public static readonly object[][] MeTestCases =
{
new object[]
{
[
[
"country", (MeClientRunner) (c => Task.FromResult<AbstractCountryResponse>(c.Country())),
typeof(CountryResponse)
},
new object[]
{
],
[
"city", (MeClientRunner) (c => Task.FromResult<AbstractCountryResponse>(c.City())), typeof(CityResponse)
},
new object[]
{
],
[
"insights", (MeClientRunner) (c => Task.FromResult<AbstractCountryResponse>(c.Insights())),
typeof(InsightsResponse)
},
new object[]
{"countryAsync", (MeClientRunner) (async c => await c.CountryAsync()), typeof(CountryResponse)},
new object[] {"cityAsync", (MeClientRunner) (async c => await c.CityAsync()), typeof(CityResponse)},
new object[]
{"insightsAsync", (MeClientRunner) (async c => await c.InsightsAsync()), typeof(InsightsResponse)}
};
],
["countryAsync", (MeClientRunner) (async c => await c.CountryAsync()), typeof(CountryResponse)],
["cityAsync", (MeClientRunner) (async c => await c.CityAsync()), typeof(CityResponse)],
["insightsAsync", (MeClientRunner) (async c => await c.InsightsAsync()), typeof(InsightsResponse)]
];
private bool _disposed;

private WebServiceClient CreateClient(string type, string ipAddress = "1.2.3.4",
Expand Down
Loading

0 comments on commit eef75bb

Please sign in to comment.