Skip to content

Commit 23579f8

Browse files
authored
Merge pull request #15 from kapokmarketing/development
Development
2 parents d54413e + 1c52dcc commit 23579f8

File tree

13 files changed

+247
-38
lines changed

13 files changed

+247
-38
lines changed

.editorconfig

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# editorconfig.org
2+
# Source: .NET Runtime Coding Standards
3+
# See: https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/coding-style.md
4+
# See Also: https://github.com/dotnet/runtime/blob/main/.editorconfig
5+
6+
# top-most EditorConfig file
7+
root = true
8+
9+
# Default settings:
10+
# A newline ending every file
11+
# Use 4 spaces as indentation
12+
[*]
13+
insert_final_newline = true
14+
indent_style = space
15+
indent_size = 4
16+
trim_trailing_whitespace = true
17+
18+
[project.json]
19+
indent_size = 2
20+
21+
# Generated code
22+
[*{_AssemblyInfo.cs,.notsupported.cs}]
23+
generated_code = true
24+
25+
# C# files
26+
[*.cs]
27+
# New line preferences
28+
csharp_new_line_before_open_brace = all
29+
csharp_new_line_before_else = true
30+
csharp_new_line_before_catch = true
31+
csharp_new_line_before_finally = true
32+
csharp_new_line_before_members_in_object_initializers = true
33+
csharp_new_line_before_members_in_anonymous_types = true
34+
csharp_new_line_between_query_expression_clauses = true
35+
36+
# Indentation preferences
37+
csharp_indent_block_contents = true
38+
csharp_indent_braces = false
39+
csharp_indent_case_contents = true
40+
csharp_indent_case_contents_when_block = true
41+
csharp_indent_switch_labels = true
42+
csharp_indent_labels = one_less_than_current
43+
44+
# Modifier preferences
45+
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
46+
47+
# avoid this. unless absolutely necessary
48+
dotnet_style_qualification_for_field = false:suggestion
49+
dotnet_style_qualification_for_property = false:suggestion
50+
dotnet_style_qualification_for_method = false:suggestion
51+
dotnet_style_qualification_for_event = false:suggestion
52+
53+
# Types: use keywords instead of BCL types, and permit var only when the type is clear
54+
csharp_style_var_for_built_in_types = true:warning
55+
csharp_style_var_when_type_is_apparent = true:warning
56+
csharp_style_var_elsewhere = true:suggestion
57+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
58+
dotnet_style_predefined_type_for_member_access = true:suggestion
59+
60+
# name all constant fields using PascalCase
61+
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
62+
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
63+
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
64+
dotnet_naming_symbols.constant_fields.applicable_kinds = field
65+
dotnet_naming_symbols.constant_fields.required_modifiers = const
66+
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
67+
68+
# static fields should have s_ prefix
69+
dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion
70+
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
71+
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
72+
dotnet_naming_symbols.static_fields.applicable_kinds = field
73+
dotnet_naming_symbols.static_fields.required_modifiers = static
74+
dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected
75+
dotnet_naming_style.static_prefix_style.required_prefix = s_
76+
dotnet_naming_style.static_prefix_style.capitalization = camel_case
77+
78+
# internal and private fields should be _camelCase
79+
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
80+
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
81+
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
82+
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
83+
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
84+
dotnet_naming_style.camel_case_underscore_style.required_prefix = _
85+
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
86+
87+
# Code style defaults
88+
csharp_using_directive_placement = outside_namespace:suggestion
89+
dotnet_sort_system_directives_first = true
90+
csharp_prefer_braces = true:silent
91+
csharp_preserve_single_line_blocks = true:none
92+
csharp_preserve_single_line_statements = false:none
93+
csharp_prefer_static_local_function = true:suggestion
94+
csharp_prefer_simple_using_statement = false:none
95+
csharp_style_prefer_switch_expression = true:suggestion
96+
97+
# Code quality
98+
dotnet_style_readonly_field = true:suggestion
99+
dotnet_code_quality_unused_parameters = non_public:suggestion
100+
101+
# Expression-level preferences
102+
dotnet_style_object_initializer = true:suggestion
103+
dotnet_style_collection_initializer = true:suggestion
104+
dotnet_style_explicit_tuple_names = true:suggestion
105+
dotnet_style_coalesce_expression = true:suggestion
106+
dotnet_style_null_propagation = true:suggestion
107+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
108+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
109+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
110+
dotnet_style_prefer_auto_properties = true:suggestion
111+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
112+
dotnet_style_prefer_conditional_expression_over_return = true:silent
113+
csharp_prefer_simple_default_expression = true:suggestion
114+
115+
# Expression-bodied members
116+
csharp_style_expression_bodied_methods = true:silent
117+
csharp_style_expression_bodied_constructors = true:silent
118+
csharp_style_expression_bodied_operators = true:silent
119+
csharp_style_expression_bodied_properties = true:silent
120+
csharp_style_expression_bodied_indexers = true:silent
121+
csharp_style_expression_bodied_accessors = true:silent
122+
csharp_style_expression_bodied_lambdas = true:silent
123+
csharp_style_expression_bodied_local_functions = true:silent
124+
125+
# Pattern matching
126+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
127+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
128+
csharp_style_inlined_variable_declaration = true:suggestion
129+
130+
# Null checking preferences
131+
csharp_style_throw_expression = true:suggestion
132+
csharp_style_conditional_delegate_call = true:suggestion
133+
134+
# Other features
135+
csharp_style_prefer_index_operator = false:none
136+
csharp_style_prefer_range_operator = false:none
137+
csharp_style_pattern_local_over_anonymous_function = false:none
138+
139+
# Space preferences
140+
csharp_space_after_cast = false
141+
csharp_space_after_colon_in_inheritance_clause = true
142+
csharp_space_after_comma = true
143+
csharp_space_after_dot = false
144+
csharp_space_after_keywords_in_control_flow_statements = true
145+
csharp_space_after_semicolon_in_for_statement = true
146+
csharp_space_around_binary_operators = before_and_after
147+
csharp_space_around_declaration_statements = do_not_ignore
148+
csharp_space_before_colon_in_inheritance_clause = true
149+
csharp_space_before_comma = false
150+
csharp_space_before_dot = false
151+
csharp_space_before_open_square_brackets = false
152+
csharp_space_before_semicolon_in_for_statement = false
153+
csharp_space_between_empty_square_brackets = false
154+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
155+
csharp_space_between_method_call_name_and_opening_parenthesis = false
156+
csharp_space_between_method_call_parameter_list_parentheses = false
157+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
158+
csharp_space_between_method_declaration_name_and_open_parenthesis = false
159+
csharp_space_between_method_declaration_parameter_list_parentheses = false
160+
csharp_space_between_parentheses = false
161+
csharp_space_between_square_brackets = false
162+
163+
# Analyzers
164+
dotnet_code_quality.CA1052.api_surface = private, internal
165+
dotnet_code_quality.CA1802.api_surface = private, internal
166+
dotnet_code_quality.CA1822.api_surface = private, internal
167+
dotnet_code_quality.CA2208.api_surface = public
168+
169+
# License header (NOTE: this deviates from the original file)
170+
file_header_template = Copyright (c) Kapok Marketing, Inc. All Rights Reserved. CONFIDENTIAL & PROPRIETARY SOURCE CODE. See License.txt in the solution root for license information.
171+
172+
# C++ Files
173+
[*.{cpp,h,in}]
174+
curly_bracket_next_line = true
175+
indent_brace_style = Allman
176+
177+
# Xml project files
178+
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}]
179+
indent_size = 2
180+
181+
[*.{csproj,vbproj,proj,nativeproj,locproj}]
182+
charset = utf-8
183+
184+
# Xml build files
185+
[*.builds]
186+
indent_size = 2
187+
188+
# Xml files
189+
[*.{xml,stylecop,resx,ruleset}]
190+
indent_size = 2
191+
192+
# Xml config files
193+
[*.{props,targets,config,nuspec}]
194+
indent_size = 2
195+
196+
# YAML config files
197+
[*.{yml,yaml}]
198+
indent_size = 2
199+
200+
# Shell scripts
201+
[*.sh]
202+
end_of_line = lf
203+
[*.{cmd,bat}]
204+
end_of_line = crlf

Kapok.IpToGeolocation.Tests/BaseTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using Microsoft.Extensions.Configuration;
22
using Microsoft.VisualStudio.TestTools.UnitTesting;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Text;
63

74
namespace Kapok.IpToGeolocation.Tests
85
{

Kapok.IpToGeolocation.Tests/JsonTests.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
1-
using Microsoft.Extensions.Configuration;
21
using Microsoft.VisualStudio.TestTools.UnitTesting;
32
using System.Collections.Generic;
43
using System.Linq;
5-
using System.Net.Http;
6-
using System.Text.Json;
7-
using System.Threading;
8-
using System.Threading.Tasks;
94

105
namespace Kapok.IpToGeolocation.Tests
116
{
127
[TestClass]
138
[DeploymentItem("Data")]
149
public class JsonTests : BaseTests
1510
{
16-
private static IEnumerable<Provider> Sources;
11+
private static IEnumerable<Provider> s_sources;
1712

1813
[ClassInitialize]
1914
public static void Initialize(TestContext context)
2015
{
21-
Sources = new Provider[] { Provider.AbstractApi, Provider.IpRegistry, Provider.IpStack };
16+
s_sources = new Provider[] { Provider.AbstractApi, Provider.IpRegistry, Provider.IpStack };
2217
}
2318

2419
public static IEnumerable<object[]> GetSources()
25-
=> Sources.Select(source => new object[] { source });
20+
=> s_sources.Select(source => new object[] { source });
2621

2722
public static IEnumerable<object[]> GetSourcesWithCities()
2823
{
@@ -35,9 +30,13 @@ public static IEnumerable<object[]> GetSourcesWithCities()
3530
[DataTestMethod]
3631
public void JsonData_ShouldDeserializeWithData(Provider source)
3732
{
33+
// Arrange
3834
var json = GetJson(source);
35+
36+
// Act
3937
var result = GeolocationSerializer.Deserialize(source, json);
4038

39+
// Assert
4140
Assert.IsNotNull(result);
4241
Assert.IsNotNull(result.City);
4342
Assert.IsNotNull(result.RegionCode);
@@ -52,9 +51,13 @@ public void JsonData_ShouldDeserializeWithData(Provider source)
5251
[DataTestMethod]
5352
public void JsonData_ShouldDeserializeWithCorrectCity(Provider source, string expectedValue)
5453
{
54+
// Arrange
5555
var json = GetJson(source);
56+
57+
// Act
5658
var result = GeolocationSerializer.Deserialize(source, json);
5759

60+
// Assert
5861
Assert.AreEqual(expectedValue, result?.City);
5962
}
6063
}

Kapok.IpToGeolocation.Tests/Kapok.IpToGeolocation.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
</ItemGroup>
3434

3535
<ItemGroup>
36+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.15" />
3637
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.15" />
3738
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.15" />
3839
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />

Kapok.IpToGeolocation.Tests/ServiceTests.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
using Microsoft.Extensions.Configuration;
21
using Microsoft.VisualStudio.TestTools.UnitTesting;
32
using Moq;
43
using Moq.Protected;
5-
using System;
64
using System.Collections.Generic;
7-
using System.Linq;
85
using System.Net;
96
using System.Net.Http;
10-
using System.Text.Json;
117
using System.Threading;
128
using System.Threading.Tasks;
139

@@ -28,10 +24,13 @@ public static IEnumerable<object[]> GetSourcesWithIpAddresses()
2824
[DataTestMethod]
2925
public async Task Service_WhenOneProvider_ShouldReturnWithValidDataLive(Provider provider, string ipAddress, bool expectSuccess)
3026
{
27+
// Arrange
3128
var service = GetGeolocationService();
3229

30+
// Act
3331
var result = await service.GetAsync(ipAddress, new Provider[] { provider }, CancellationToken.None);
3432

33+
// Assert
3534
if (expectSuccess)
3635
{
3736
Assert.IsNotNull(result);
@@ -52,10 +51,13 @@ public async Task Service_WhenOneProvider_ShouldReturnWithValidDataLive(Provider
5251
[DataTestMethod]
5352
public async Task Service_WhenOneProvider_ShouldReturnWithValidData(Provider provider, string ipAddress, bool expectSuccess)
5453
{
54+
// Arrange
5555
var service = GetGeolocationServiceWithMockHttpMessageHandler(provider);
5656

57+
// Act
5758
var result = await service.GetAsync(ipAddress, new [] { provider }, CancellationToken.None);
5859

60+
// Assert
5961
Assert.IsNotNull(result);
6062
Assert.IsNotNull(result.Location);
6163
Assert.AreEqual(provider, result.Provider);
@@ -66,10 +68,13 @@ public async Task Service_WhenOneProvider_ShouldReturnWithValidData(Provider pro
6668
[DataTestMethod]
6769
public async Task Service_WhenNoProviders_ShouldReturnNullAndUnknown(Provider provider, string ipAddress, bool expectSuccess)
6870
{
71+
// Arrange
6972
var service = GetGeolocationServiceWithMockHttpMessageHandler(provider);
7073

74+
// Act
7175
var result = await service.GetAsync(ipAddress, new Provider[] { }, CancellationToken.None);
7276

77+
// Assert
7378
Assert.IsNotNull(result);
7479
Assert.IsNull(result.Location);
7580
Assert.AreEqual(Provider.Unknown, result.Provider);

Kapok.IpToGeolocation.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kapok.IpToGeolocation.Tests
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{625013D7-1D1C-4585-AED3-AA4C2B331362}"
1111
ProjectSection(SolutionItems) = preProject
12+
.editorconfig = .editorconfig
1213
.gitignore = .gitignore
14+
.git\config = .git\config
1315
LICENSE = LICENSE
1416
EndProjectSection
1517
EndProject

Kapok.IpToGeolocation/AbstractApi/Currency.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace Kapok.IpToGeolocation.AbstractApi
88
public class Currency
99
{
1010
[JsonPropertyName("currency_name")]
11-
public string CurrencyName { get; set; }
11+
public string? CurrencyName { get; set; }
1212

1313
[JsonPropertyName("currency_code")]
14-
public string CurrencyCode { get; set; }
14+
public string? CurrencyCode { get; set; }
1515
}
1616
}

Kapok.IpToGeolocation/AbstractApi/Flag.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ namespace Kapok.IpToGeolocation.AbstractApi
88
public class Flag
99
{
1010
[JsonPropertyName("emoji")]
11-
public string Emoji { get; set; }
11+
public string? Emoji { get; set; }
1212

1313
[JsonPropertyName("unicode")]
14-
public string Unicode { get; set; }
14+
public string? Unicode { get; set; }
1515

1616
[JsonPropertyName("png")]
17-
public string Png { get; set; }
17+
public string? Png { get; set; }
1818

1919
[JsonPropertyName("svg")]
20-
public string Svg { get; set; }
20+
public string? Svg { get; set; }
2121
}
2222
}

Kapok.IpToGeolocation/GeolocationProviderConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public class GeolocationProviderConfiguration
1414
public string? UrlPattern { get; set; }
1515
public string? PrivateKey { get; set; }
1616
public string? UrlPatternWithPrivateKey
17-
=> _urlPatternWithPrivateKey ?? (_urlPatternWithPrivateKey = PrivateKey != null ? UrlPattern?.Replace("{Key}", PrivateKey) : UrlPattern);
17+
=> _urlPatternWithPrivateKey ??= PrivateKey != null ? UrlPattern?.Replace("{Key}", PrivateKey) : UrlPattern;
1818
}
19-
}
19+
}

0 commit comments

Comments
 (0)