Skip to content

Commit

Permalink
Merge pull request #272 from maxmind/greg/net-9
Browse files Browse the repository at this point in the history
Update targets and misc code cleanup
  • Loading branch information
horgh authored Nov 22, 2024
2 parents d9fd4d0 + ece5a2a commit b0bb547
Show file tree
Hide file tree
Showing 42 changed files with 265 additions and 257 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
4 changes: 2 additions & 2 deletions MaxMind.MinFraud.UnitTest/JsonElementComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public bool Equals(JsonElement x, JsonElement y)
}

default:
throw new JsonException(string.Format("Unknown JsonValueKind {0}", x.ValueKind));
throw new JsonException($"Unknown JsonValueKind {x.ValueKind}");
}
}

Expand Down Expand Up @@ -128,7 +128,7 @@ private void ComputeHashCode(JsonElement obj, ref HashCode hash, int depth)
break;

default:
throw new JsonException(string.Format("Unknown JsonValueKind {0}", obj.ValueKind));
throw new JsonException($"Unknown JsonValueKind {obj.ValueKind}");
}
}

Expand Down
6 changes: 3 additions & 3 deletions MaxMind.MinFraud.UnitTest/MaxMind.MinFraud.UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<Description>Test project for minFraud API</Description>
<VersionPrefix>0.6.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.MinFraud.UnitTest</AssemblyName>
<PackageId>MaxMind.MinFraud.UnitTest</PackageId>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand All @@ -17,7 +17,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
16 changes: 8 additions & 8 deletions MaxMind.MinFraud.UnitTest/Request/CustomInputsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ public void TestJson()
var comparer = new JsonElementComparer();
Assert.True(comparer.JsonEquals(
JsonDocument.Parse(
@"
"""
{
""string_input_1"": ""test string"",
""int_input"": 19,
""long_input"": 12,
""float_input"": 3.20000005,
""double_input"": 32.122999999999998,
""bool_input"": true
"string_input_1": "test string",
"int_input": 19,
"long_input": 12,
"float_input": 3.20000005,
"double_input": 32.122999999999998,
"bool_input": true
}
"),
"""),
JsonDocument.Parse(json)
),
json
Expand Down
26 changes: 13 additions & 13 deletions MaxMind.MinFraud.UnitTest/Request/EmailTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public void TestAddress()
Assert.True(
comparer.JsonEquals(
JsonDocument.Parse(
$@"
{{
""address"": ""{address}"",
""domain"": ""{domain}""
}}
"),
$$"""
{
"address": "{{address}}",
"domain": "{{domain}}"
}
"""),
JsonDocument.Parse(json)
),
json
Expand All @@ -52,12 +52,12 @@ public void TestAddressWithHashing()
Assert.True(
comparer.JsonEquals(
JsonDocument.Parse(
$@"
{{
""address"": ""{md5}"",
""domain"": ""{domain}""
}}
"),
$$"""
{
"address": "{{md5}}",
"domain": "{{domain}}"
}
"""),
JsonDocument.Parse(json)
)
);
Expand All @@ -66,7 +66,7 @@ public void TestAddressWithHashing()
[Fact]
public void TestNormalizing()
{
Email e = new Email(address: "[email protected]", hashAddress: true);
var e = new Email(address: "[email protected]", hashAddress: true);
Assert.Equal("977577b140bfb7c516e4746204fbdb01", e.AddressMD5);
Assert.Equal("maxmind.com", e.Domain);

Expand Down
12 changes: 6 additions & 6 deletions MaxMind.MinFraud.UnitTest/Request/EventTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public void TestSerialization()
Assert.True(
comparer.JsonEquals(
JsonDocument.Parse(
@"
"""
{
""transaction_id"": ""txn123"",
""shop_id"": ""shop123"",
""time"": ""2020-07-12T15:30:00+02:00"",
""type"": ""account_creation""
"transaction_id": "txn123",
"shop_id": "shop123",
"time": "2020-07-12T15:30:00+02:00",
"type": "account_creation"
}
"),
"""),
JsonDocument.Parse(json)
),
json
Expand Down
14 changes: 7 additions & 7 deletions MaxMind.MinFraud.UnitTest/Response/BillingAddressTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public class BillingAddressTest
public void TestBillingAddress()
{
var address = JsonSerializer.Deserialize<BillingAddress>(
@"
"""
{
""is_in_ip_country"": true,
""latitude"": 43.1,
""longitude"": 32.1,
""distance_to_ip_location"": 100,
""is_postal_in_city"": true
"is_in_ip_country": true,
"latitude": 43.1,
"longitude": 32.1,
"distance_to_ip_location": 100,
"is_postal_in_city": true
}
");
""");

TestAddress(address!);
}
Expand Down
20 changes: 10 additions & 10 deletions MaxMind.MinFraud.UnitTest/Response/CreditCardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ public class CreditCardTest
public void TestCreditCard()
{
var cc = JsonSerializer.Deserialize<CreditCard>(
@"
"""
{
""issuer"": {""name"": ""Bank""},
""brand"": ""Visa"",
""country"": ""US"",
""is_business"": true,
""is_issued_in_billing_address_country"": true,
""is_prepaid"": true,
""is_virtual"": true,
""type"": ""credit""
"issuer": {"name": "Bank"},
"brand": "Visa",
"country": "US",
"is_business": true,
"is_issued_in_billing_address_country": true,
"is_prepaid": true,
"is_virtual": true,
"type": "credit"
}
")!;
""")!;

Assert.Equal("Bank", cc.Issuer.Name);
Assert.Equal("US", cc.Country);
Expand Down
16 changes: 8 additions & 8 deletions MaxMind.MinFraud.UnitTest/Response/DeviceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public void TestDevice()
var lastSeen = "2016-06-08T14:16:38+00:00";
var localTime = "2016-06-10T14:19:10-08:00";
var device = JsonSerializer.Deserialize<Device>(
@$"
{{
""confidence"": 99,
""id"": ""{id}"",
""last_seen"": ""{lastSeen}"",
""local_time"": ""{localTime}""
}}
")!;
$$"""
{
"confidence": 99,
"id": "{{id}}",
"last_seen": "{{lastSeen}}",
"local_time": "{{localTime}}"
}
""")!;

Assert.Equal(99, device.Confidence);
Assert.Equal(new Guid(id), device.Id);
Expand Down
14 changes: 7 additions & 7 deletions MaxMind.MinFraud.UnitTest/Response/DispositionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ public class DispositionTest
public void TestDisposition()
{
var disposition = JsonSerializer.Deserialize<Disposition>(
@"
{
""action"": ""manual_review"",
""reason"": ""custom_rule"",
""rule_label"": ""the rule's label""
}
")!;
"""
{
"action": "manual_review",
"reason": "custom_rule",
"rule_label": "the rule's label"
}
""")!;

Assert.Equal("manual_review", disposition.Action);
Assert.Equal("custom_rule", disposition.Reason);
Expand Down
2 changes: 1 addition & 1 deletion MaxMind.MinFraud.UnitTest/Response/EmailDomainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class EmailDomainTest
public void TestEmailDomain()
{
var domain = JsonSerializer.Deserialize<EmailDomain>(
@"{""first_seen"": ""2017-01-02""}")!;
"""{"first_seen": "2017-01-02"}""")!;

Assert.Equal("2017-01-02", domain.FirstSeen?.ToString("yyyy-MM-dd"));
}
Expand Down
18 changes: 9 additions & 9 deletions MaxMind.MinFraud.UnitTest/Response/EmailTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ public class EmailTest
public void TestEmail()
{
var email = JsonSerializer.Deserialize<Email>(
@"
{
""domain"": { ""first_seen"": ""2014-02-03"" },
""first_seen"": ""2017-01-02"",
""is_disposable"": true,
""is_free"": true,
""is_high_risk"": true
}
")!;
"""
{
"domain": { "first_seen": "2014-02-03" },
"first_seen": "2017-01-02",
"is_disposable": true,
"is_free": true,
"is_high_risk": true
}
""")!;

Assert.Equal("2014-02-03", email.Domain.FirstSeen?.ToString("yyyy-MM-dd"));
Assert.Equal("2017-01-02", email.FirstSeen?.ToString("yyyy-MM-dd"));
Expand Down
12 changes: 6 additions & 6 deletions MaxMind.MinFraud.UnitTest/Response/GeoIP2CountryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class GeoIP2CountryTest
public void TestIsHighRisk()
{
var country = JsonSerializer.Deserialize<Country>(
@"
{
""is_high_risk"": true,
""is_in_european_union"": true
}
")!;
"""
{
"is_high_risk": true,
"is_in_european_union": true
}
""")!;

Assert.True(country.IsInEuropeanUnion);
}
Expand Down
2 changes: 1 addition & 1 deletion MaxMind.MinFraud.UnitTest/Response/GeoIP2LocationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public void TestGetLocalTime()
{
var time = "2015-04-19T12:59:23-01:00";
var location = JsonSerializer.Deserialize<GeoIP2Location>(
@$"{{""local_time"": ""{time}"" }}")!;
$$"""{"local_time": "{{time}}" }""")!;

Assert.Equal(time, location.LocalTime?.ToString("yyyy-MM-ddTHH:mm:ssK"));
}
Expand Down
54 changes: 27 additions & 27 deletions MaxMind.MinFraud.UnitTest/Response/IPAddressTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@ public void TestIPAddress()
var time = "2015-04-19T12:59:23-01:00";

var address = JsonSerializer.Deserialize<IPAddress>(
$@"
{{
""risk"": 99,
""risk_reasons"": [
{{
""code"": ""ANONYMOUS_IP"",
""reason"": ""The IP address belongs to an anonymous network. See /ip_address/traits for more details.""
}},
{{
""code"": ""MINFRAUD_NETWORK_ACTIVITY"",
""reason"": ""Suspicious activity has been seen on this IP address across minFraud customers.""
}}
],
""country"": {{""is_high_risk"": true}},
""location"": {{""local_time"": ""{time}""}},
""traits"": {{
""is_anonymous"": true,
""is_anonymous_vpn"": true,
""is_hosting_provider"": true,
""is_public_proxy"": true,
""is_residential_proxy"": true,
""is_tor_exit_node"": true,
""mobile_country_code"" : ""310"",
""mobile_network_code"" : ""004""
}}
}}
")!;
$$"""
{
"risk": 99,
"risk_reasons": [
{
"code": "ANONYMOUS_IP",
"reason": "The IP address belongs to an anonymous network. See /ip_address/traits for more details."
},
{
"code": "MINFRAUD_NETWORK_ACTIVITY",
"reason": "Suspicious activity has been seen on this IP address across minFraud customers."
}
],
"country": {"is_high_risk": true},
"location": {"local_time": "{{time}}"},
"traits": {
"is_anonymous": true,
"is_anonymous_vpn": true,
"is_hosting_provider": true,
"is_public_proxy": true,
"is_residential_proxy": true,
"is_tor_exit_node": true,
"mobile_country_code" : "310",
"mobile_network_code" : "004"
}
}
""")!;

Assert.Equal(99, address.Risk);
Assert.Equal("ANONYMOUS_IP", address.RiskReasons[0].Code);
Expand Down
Loading

0 comments on commit b0bb547

Please sign in to comment.