Skip to content

Commit 60cd74c

Browse files
committed
Added another standards tests that classes ending with Base should be
abstract classes
1 parent fa2a22c commit 60cd74c

File tree

3 files changed

+75
-62
lines changed

3 files changed

+75
-62
lines changed

src/Nest/CommonOptions/Scripting/ScriptBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public abstract class ScriptBase : IScript
2626
public static implicit operator ScriptBase(string inline) => new InlineScript(inline);
2727
}
2828

29-
public class ScriptDescriptorBase<TDescriptor, TInterface> : DescriptorBase<TDescriptor, TInterface>, IScript
29+
public abstract class ScriptDescriptorBase<TDescriptor, TInterface> : DescriptorBase<TDescriptor, TInterface>, IScript
3030
where TDescriptor : ScriptDescriptorBase<TDescriptor, TInterface>, TInterface, IScript
3131
where TInterface : class, IScript
3232
{

src/Nest/QueryDsl/TermLevel/Fuzzy/FuzzyQueryBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public abstract class FuzzyQueryBase<TValue, TFuzziness> : FieldNameQueryBase, I
5353

5454
}
5555

56-
public class FuzzyQueryDescriptorBase<TDescriptor, T, TValue, TFuzziness>
56+
public abstract class FuzzyQueryDescriptorBase<TDescriptor, T, TValue, TFuzziness>
5757
: FieldNameQueryDescriptorBase<TDescriptor, IFuzzyQuery<TValue, TFuzziness>, T> , IFuzzyQuery<TValue, TFuzziness>
5858
where T : class
5959
where TDescriptor : FieldNameQueryDescriptorBase<TDescriptor, IFuzzyQuery<TValue, TFuzziness>, T>, IFuzzyQuery<TValue, TFuzziness>

src/Tests/CodeStandards/NamingConventions.doc.cs

Lines changed: 73 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,34 @@ public class NamingConventions
1212
/**
1313
* Abstract class names should end with a `Base` suffix
1414
*/
15-
[U]
16-
public void AbstractClassNamesEndWithBase()
15+
[U] public void AbstractClassNamesEndWithBase()
1716
{
18-
var exceptions = new[]
19-
{
20-
typeof(DateMath)
21-
};
17+
var exceptions = new[]
18+
{
19+
typeof(DateMath)
20+
};
2221

2322
var abstractClasses = typeof(IRequest).Assembly().GetTypes()
2423
.Where(t => t.IsClass() && t.IsAbstract() && !t.IsSealed() && !exceptions.Contains(t))
25-
.Where(t => !t.Name.Split('`')[0].EndsWith("Base"))
26-
.Select(t => t.Name.Split('`')[0])
24+
.Where(t => !t.Name.Split('`')[0].EndsWith("Base"))
25+
.Select(t => t.Name.Split('`')[0])
26+
.ToList();
27+
28+
abstractClasses.Should().BeEmpty();
29+
}
30+
31+
[U] public void ClassNameContainsBaseShouldBeAbstract()
32+
{
33+
var exceptions = new[] { typeof(DateMath) };
34+
35+
var baseClassesNotAbstract = typeof(IRequest).Assembly().GetTypes()
36+
.Where(t => t.IsClass() && !exceptions.Contains(t))
37+
.Where(t => t.Name.Split('`')[0].EndsWith("Base"))
38+
.Where(t => !t.IsAbstract)
39+
.Select(t => t.Name.Split('`')[0])
2740
.ToList();
2841

29-
abstractClasses.Should().BeEmpty();
42+
baseClassesNotAbstract.Should().BeEmpty();
3043
}
3144

3245
/**
@@ -38,12 +51,12 @@ public void RequestClassNamesEndWithRequest()
3851
var types = typeof(IRequest).Assembly().GetTypes();
3952
var requests = types
4053
.Where(t => typeof(IRequest).IsAssignableFrom(t) && !t.IsAbstract())
41-
.Where(t => !typeof(IDescriptor).IsAssignableFrom(t))
54+
.Where(t => !typeof(IDescriptor).IsAssignableFrom(t))
4255
.Where(t => !t.Name.Split('`')[0].EndsWith("Request"))
43-
.Select(t => t.Name.Split('`')[0])
56+
.Select(t => t.Name.Split('`')[0])
4457
.ToList();
4558

46-
requests.Should().BeEmpty();
59+
requests.Should().BeEmpty();
4760
}
4861

4962
/**
@@ -55,11 +68,11 @@ public void ResponseClassNamesEndWithResponse()
5568
var types = typeof(IRequest).Assembly().GetTypes();
5669
var responses = types
5770
.Where(t => typeof(IResponse).IsAssignableFrom(t) && !t.IsAbstract())
58-
.Where(t => !t.Name.Split('`')[0].EndsWith("Response"))
59-
.Select(t => t.Name.Split('`')[0])
71+
.Where(t => !t.Name.Split('`')[0].EndsWith("Response"))
72+
.Select(t => t.Name.Split('`')[0])
6073
.ToList();
6174

62-
responses.Should().BeEmpty();
75+
responses.Should().BeEmpty();
6376
}
6477

6578
/**
@@ -69,65 +82,65 @@ public void ResponseClassNamesEndWithResponse()
6982
[U]
7083
public void ParityBetweenRequestsAndResponses()
7184
{
72-
// Add any exceptions to the rule here
73-
var exceptions = new []
74-
{
75-
typeof(CatAliasesRequest),
76-
typeof(CatAllocationRequest),
77-
typeof(CatCountRequest),
78-
typeof(CatFielddataRequest),
79-
typeof(CatHealthRequest),
80-
typeof(CatHelpRequest),
81-
typeof(CatIndicesRequest),
82-
typeof(CatMasterRequest),
83-
typeof(CatNodesRequest),
84-
typeof(CatPendingTasksRequest),
85-
typeof(CatPluginsRequest),
86-
typeof(CatRecoveryRequest),
87-
typeof(CatSegmentsRequest),
88-
typeof(CatShardsRequest),
89-
typeof(CatThreadPoolRequest),
90-
typeof(DocumentExistsRequest),
91-
typeof(DocumentExistsRequest<>),
92-
typeof(AliasExistsRequest),
93-
typeof(IndexExistsRequest),
94-
typeof(TypeExistsRequest),
95-
typeof(IndexTemplateExistsRequest),
96-
typeof(SearchExistsRequest),
97-
typeof(SearchExistsRequest<>),
98-
typeof(SearchTemplateRequest),
99-
typeof(SearchTemplateRequest<>),
100-
typeof(ScrollRequest),
101-
typeof(SourceRequest),
102-
typeof(SourceRequest<>),
85+
// Add any exceptions to the rule here
86+
var exceptions = new[]
87+
{
88+
typeof(CatAliasesRequest),
89+
typeof(CatAllocationRequest),
90+
typeof(CatCountRequest),
91+
typeof(CatFielddataRequest),
92+
typeof(CatHealthRequest),
93+
typeof(CatHelpRequest),
94+
typeof(CatIndicesRequest),
95+
typeof(CatMasterRequest),
96+
typeof(CatNodesRequest),
97+
typeof(CatPendingTasksRequest),
98+
typeof(CatPluginsRequest),
99+
typeof(CatRecoveryRequest),
100+
typeof(CatSegmentsRequest),
101+
typeof(CatShardsRequest),
102+
typeof(CatThreadPoolRequest),
103+
typeof(DocumentExistsRequest),
104+
typeof(DocumentExistsRequest<>),
105+
typeof(AliasExistsRequest),
106+
typeof(IndexExistsRequest),
107+
typeof(TypeExistsRequest),
108+
typeof(IndexTemplateExistsRequest),
109+
typeof(SearchExistsRequest),
110+
typeof(SearchExistsRequest<>),
111+
typeof(SearchTemplateRequest),
112+
typeof(SearchTemplateRequest<>),
113+
typeof(ScrollRequest),
114+
typeof(SourceRequest),
115+
typeof(SourceRequest<>),
103116

104117
// TODO: Remove when https://github.com/elastic/elasticsearch-net/issues/1778 is resolved
105118
typeof(ValidateQueryRequest),
106-
typeof(ValidateQueryRequest<>),
119+
typeof(ValidateQueryRequest<>),
107120

108-
typeof(GetAliasRequest),
109-
typeof(CatNodeattrsRequest),
110-
typeof(IndicesShardStoresRequest),
111-
typeof(RenderSearchTemplateRequest)
112-
};
121+
typeof(GetAliasRequest),
122+
typeof(CatNodeattrsRequest),
123+
typeof(IndicesShardStoresRequest),
124+
typeof(RenderSearchTemplateRequest)
125+
};
113126

114-
var types = typeof(IRequest).Assembly().GetTypes();
127+
var types = typeof(IRequest).Assembly().GetTypes();
115128

116129
var requests = new HashSet<string>(types
117-
.Where(t =>
118-
t.IsClass() &&
119-
!t.IsAbstract() &&
120-
typeof(IRequest).IsAssignableFrom(t) &&
121-
!typeof(IDescriptor).IsAssignableFrom(t)
122-
&& !exceptions.Contains(t))
130+
.Where(t =>
131+
t.IsClass() &&
132+
!t.IsAbstract() &&
133+
typeof(IRequest).IsAssignableFrom(t) &&
134+
!typeof(IDescriptor).IsAssignableFrom(t)
135+
&& !exceptions.Contains(t))
123136
.Select(t => t.Name.Split('`')[0].Replace("Request", ""))
124137
);
125138

126139
var responses = types
127140
.Where(t => t.IsClass() && !t.IsAbstract() && typeof(IResponse).IsAssignableFrom(t))
128141
.Select(t => t.Name.Split('`')[0].Replace("Response", ""));
129142

130-
requests.Except(responses).Should().BeEmpty();
143+
requests.Except(responses).Should().BeEmpty();
131144
}
132145
}
133146
}

0 commit comments

Comments
 (0)