Skip to content

Commit 3e6b76b

Browse files
committed
Namespace assertions
Assert that all types in Nest are in the root namespace Assert that all types in Elasticsearch.Net are in the root namespace
1 parent c746c53 commit 3e6b76b

File tree

7 files changed

+495
-319
lines changed

7 files changed

+495
-319
lines changed

docs/asciidoc/client-concepts/connection-pooling/sniffing/role-detection.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ await pipeline.SniffAsync();
103103
[source,csharp]
104104
----
105105
this._settings =
106-
this._cluster.Client(u => new SniffingConnectionPool(new[] {u}), c => c.PrettyJson()).ConnectionSettings;
106+
this._cluster.Node.Client(u => new SniffingConnectionPool(new[] {u}), c => c.PrettyJson()).ConnectionSettings;
107107
108108
var pipeline = new RequestPipeline(this._settings, DateTimeProvider.Default, new MemoryStreamFactory(),
109109
new SearchRequestParameters());

docs/asciidoc/client-concepts/high-level/inference/property-inference.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
:nuget: https://www.nuget.org/packages
66

77
[[property-inference]]
8-
== Property Name Inference
8+
== Property Name Inference
99

1010
=== Appending suffixes to a Lambda expression body
1111

docs/asciidoc/code-standards/naming-conventions.asciidoc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,35 @@ requests.Except(responses).Should().BeEmpty();
128128
----
129129
<1> _Exceptions to the rule_
130130

131+
[source,csharp]
132+
----
133+
var exceptions = new List<Type>
134+
{
135+
typeof(IElasticClient).Assembly().GetType("Elasticsearch.Net.DotNetCoreTypeExtensions"),
136+
typeof(AggregationWalker),
137+
typeof(AggregationVisitor),
138+
typeof(IAggregationVisitor),
139+
typeof(IElasticClient).Assembly().GetType("System.AssemblyVersionInformation")
140+
};
141+
142+
var types = typeof(IElasticClient).Assembly().GetTypes();
143+
144+
var typesNotInNestNamespace = types
145+
.Where(t => !exceptions.Contains(t))
146+
.Where(t => t.Namespace != "Nest")
147+
.ToList();
148+
149+
typesNotInNestNamespace.Should().BeEmpty();
150+
----
151+
152+
[source,csharp]
153+
----
154+
var types = typeof(IElasticLowLevelClient).Assembly().GetTypes();
155+
156+
var typesNotInNestNamespace = types
157+
.Where(t => t.Namespace != "Elasticsearch.Net")
158+
.ToList();
159+
160+
typesNotInNestNamespace.Should().BeEmpty();
161+
----
162+

paket.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
NUGET
2-
remote: https://www.nuget.org/api/v2
2+
remote: http://api.nuget.org/v3/index.json
33
specs:
44
AsciiDocNet (1.0.0-alpha3)
55
Bogus (3.0.5-beta-2)
@@ -42,7 +42,6 @@ NUGET
4242
Microsoft.CodeAnalysis.Common (1.1.1)
4343
NDesk.Options (0.2.1)
4444
Newtonsoft.Json (8.0.2)
45-
RazorMachine (2.6.1)
4645
Rx-Core (2.2.5)
4746
Rx-Interfaces (>= 2.2.5)
4847
Rx-Interfaces (2.2.5)
@@ -57,6 +56,7 @@ NUGET
5756
Rx-PlatformServices (2.2.5)
5857
Rx-Core (>= 2.2.5)
5958
Rx-Interfaces (>= 2.2.5)
59+
ShellProgressBar (3.0)
6060
System.Collections (4.0.10) - framework: dnxcore50
6161
System.Diagnostics.Debug (>= 4.0) - framework: dnxcore50
6262
System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50
@@ -348,9 +348,9 @@ NUGET
348348
System.Threading.Tasks (>= 4.0) - framework: dnxcore50
349349
xunit.abstractions (>= 2.0) - framework: dnxcore50
350350
xunit.extensibility.core (2.1) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, xamarinios, winv4.5, wpv8.0, wpav8.1
351-
remote: http://api.nuget.org/v3/index.json
351+
remote: https://www.nuget.org/api/v2
352352
specs:
353-
ShellProgressBar (3.0)
353+
RazorMachine (2.6.1)
354354

355355
GROUP build
356356
NUGET

src/Nest/XPack/License/GetLicense/GetLicenseResponse.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ private class Wrapped
8282
[JsonProperty("license")]
8383
public License License { get; set; }
8484
}
85+
8586
public static License LoadFromDisk(string path)
8687
{
8788
var contents = File.ReadAllText(path);

src/Tests/CodeStandards/NamingConventions.doc.cs

Lines changed: 144 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.CodeDom.Compiler;
3+
using System.Collections.Generic;
4+
using System.Globalization;
25
using System.Linq;
36
using System.Reflection;
7+
using Elasticsearch.Net;
48
using FluentAssertions;
59
using Nest;
10+
using Nest.Aggregations.Visitor;
611
using Tests.Framework;
712

813
namespace Tests.CodeStandards
914
{
1015
/** == Naming Conventions
11-
*
16+
*
1217
* NEST uses the following naming conventions (with _some_ exceptions).
1318
*/
1419
public class NamingConventions
@@ -136,5 +141,142 @@ public void ParityBetweenRequestsAndResponses()
136141

137142
requests.Except(responses).Should().BeEmpty();
138143
}
144+
145+
[U]
146+
public void AllNestTypesAreInNestNamespace()
147+
{
148+
var nestAssembly = typeof(IElasticClient).Assembly();
149+
150+
var exceptions = new List<Type>
151+
{
152+
nestAssembly.GetType("Elasticsearch.Net.DotNetCoreTypeExtensions"),
153+
typeof(AggregationWalker),
154+
typeof(AggregationVisitor),
155+
typeof(IAggregationVisitor),
156+
nestAssembly.GetType("System.AssemblyVersionInformation"),
157+
#if DOTNETCORE
158+
typeof(SynchronizedCollection<>),
159+
nestAssembly.GetType("System.ComponentModel.Browsable")
160+
#endif
161+
};
162+
163+
var types = nestAssembly.GetTypes();
164+
var typesNotInNestNamespace = types
165+
.Where(t => !exceptions.Contains(t))
166+
.Where(t => t.Namespace != "Nest")
167+
.Where(t => !t.Name.StartsWith("<"))
168+
.Where(t => IsValidTypeNameOrIdentifier(t.Name, true))
169+
.ToList();
170+
171+
typesNotInNestNamespace.Should().BeEmpty();
172+
}
173+
174+
[U]
175+
public void AllElasticsearchNetTypesAreInElasticsearchNetNamespace()
176+
{
177+
var elasticsearchNetAssembly = typeof(IElasticLowLevelClient).Assembly();
178+
179+
var exceptions = new List<Type>
180+
{
181+
elasticsearchNetAssembly.GetType("System.AssemblyVersionInformation"),
182+
elasticsearchNetAssembly.GetType("System.FormattableString"),
183+
elasticsearchNetAssembly.GetType("System.Runtime.CompilerServices.FormattableStringFactory"),
184+
elasticsearchNetAssembly.GetType("System.Runtime.CompilerServices.FormattableStringFactory"),
185+
elasticsearchNetAssembly.GetType("Purify.Purifier"),
186+
elasticsearchNetAssembly.GetType("Purify.Purifier+IPurifier"),
187+
elasticsearchNetAssembly.GetType("Purify.Purifier+PurifierDotNet"),
188+
elasticsearchNetAssembly.GetType("Purify.Purifier+PurifierMono"),
189+
elasticsearchNetAssembly.GetType("Purify.Purifier+UriInfo"),
190+
#if DOTNETCORE
191+
elasticsearchNetAssembly.GetType("System.ComponentModel.Browsable")
192+
#endif
193+
};
194+
195+
var types = elasticsearchNetAssembly.GetTypes();
196+
var typesNotIElasticsearchNetNamespace = types
197+
.Where(t => !exceptions.Contains(t))
198+
.Where(t => t.Namespace != "Elasticsearch.Net")
199+
.Where(t => !t.Name.StartsWith("<"))
200+
.Where(t => IsValidTypeNameOrIdentifier(t.Name, true))
201+
.ToList();
202+
203+
typesNotIElasticsearchNetNamespace.Should().BeEmpty();
204+
}
205+
206+
/// implementation from System.CodeDom.Compiler.CodeGenerator.IsValidLanguageIndependentIdentifier(string value)
207+
private static bool IsValidTypeNameOrIdentifier(string value, bool isTypeName)
208+
{
209+
bool nextMustBeStartChar = true;
210+
if (value.Length == 0)
211+
return false;
212+
for (int index = 0; index < value.Length; ++index)
213+
{
214+
var character = value[index];
215+
#if DOTNETCORE
216+
var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(character);
217+
#else
218+
var unicodeCategory = char.GetUnicodeCategory(character);
219+
#endif
220+
switch (unicodeCategory)
221+
{
222+
case UnicodeCategory.UppercaseLetter:
223+
case UnicodeCategory.LowercaseLetter:
224+
case UnicodeCategory.TitlecaseLetter:
225+
case UnicodeCategory.ModifierLetter:
226+
case UnicodeCategory.OtherLetter:
227+
case UnicodeCategory.LetterNumber:
228+
nextMustBeStartChar = false;
229+
break;
230+
case UnicodeCategory.NonSpacingMark:
231+
case UnicodeCategory.SpacingCombiningMark:
232+
case UnicodeCategory.DecimalDigitNumber:
233+
case UnicodeCategory.ConnectorPunctuation:
234+
if (nextMustBeStartChar && (int)character != 95)
235+
return false;
236+
nextMustBeStartChar = false;
237+
break;
238+
default:
239+
if (!isTypeName || !IsSpecialTypeChar(character, ref nextMustBeStartChar))
240+
return false;
241+
break;
242+
}
243+
}
244+
return true;
245+
}
246+
247+
private static bool IsSpecialTypeChar(char ch, ref bool nextMustBeStartChar)
248+
{
249+
if ((uint)ch <= 62U)
250+
{
251+
switch (ch)
252+
{
253+
case '$':
254+
case '&':
255+
case '*':
256+
case '+':
257+
case ',':
258+
case '-':
259+
case '.':
260+
case ':':
261+
case '<':
262+
case '>':
263+
break;
264+
default:
265+
goto label_6;
266+
}
267+
}
268+
else if ((int)ch != 91 && (int)ch != 93)
269+
{
270+
if ((int)ch == 96)
271+
return true;
272+
goto label_6;
273+
}
274+
nextMustBeStartChar = true;
275+
return true;
276+
label_6:
277+
return false;
278+
}
139279
}
140280
}
281+
282+

0 commit comments

Comments
 (0)