Skip to content

Commit aee2db3

Browse files
committed
Replaced Count() with either Count or Length
The built-in counting properties, such as `Count` and `Length`, are far more efficient than using LINQ's `Count()` extension method. This only affected our unit tests, but it should still be resolved. This issue was exposed by updates to the Microsoft Code Analyzers (see #865195f).
1 parent 6b48d5d commit aee2db3

5 files changed

Lines changed: 13 additions & 13 deletions

File tree

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ private static string CreateRelationshipsXml(Topic topic) {
11951195
attributesXml.Append("\">");
11961196

11971197
// Build out string array of related items in this scope
1198-
var targetIds = new string[scope.Count()];
1198+
var targetIds = new string[scope.Count];
11991199
var count = 0;
12001200
foreach (var relTopic in scope) {
12011201
targetIds[count] = relTopic.Id.ToString(CultureInfo.InvariantCulture);

OnTopic.Tests/ITopicRepositoryTest.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,14 @@ public void Move_ToNewParent_ConfirmedMove() {
167167
var topic = _topicRepository.Load("Root:Web:Web_0:Web_0_1");
168168

169169
Assert.ReferenceEquals(topic.Parent, source);
170-
Assert.AreEqual<int>(2, destination.Children.Count());
171-
Assert.AreEqual<int>(2, source.Children.Count());
170+
Assert.AreEqual<int>(2, destination.Children.Count);
171+
Assert.AreEqual<int>(2, source.Children.Count);
172172

173173
_topicRepository.Move(topic, destination);
174174

175175
Assert.ReferenceEquals(topic.Parent, destination);
176-
Assert.AreEqual<int>(1, source.Children.Count());
177-
Assert.AreEqual<int>(3, destination.Children.Count());
176+
Assert.AreEqual<int>(1, source.Children.Count);
177+
Assert.AreEqual<int>(3, destination.Children.Count);
178178

179179
}
180180

@@ -193,12 +193,12 @@ public void Move_ToNewSibling_ConirmedMove() {
193193

194194
Assert.ReferenceEquals(topic.Parent, parent);
195195
Assert.AreEqual<string>("Web_0_0", parent.Children.First().Key);
196-
Assert.AreEqual<int>(2, parent.Children.Count());
196+
Assert.AreEqual<int>(2, parent.Children.Count);
197197

198198
_topicRepository.Move(topic, parent, sibling);
199199

200200
Assert.ReferenceEquals(topic.Parent, parent);
201-
Assert.AreEqual<int>(2, parent.Children.Count());
201+
Assert.AreEqual<int>(2, parent.Children.Count);
202202
Assert.AreEqual<string>("Web_0_1", parent.Children.First().Key);
203203
Assert.AreEqual<string>("Web_0_0", parent.Children[1].Key);
204204

@@ -217,11 +217,11 @@ public void Delete_Topic_Removed() {
217217
var topic = _topicRepository.Load("Root:Web:Web_1:Web_1_1");
218218
var child = _topicRepository.Load("Root:Web:Web_1:Web_1_1:Web_1_1_0");
219219

220-
Assert.AreEqual<int>(2, parent.Children.Count());
220+
Assert.AreEqual<int>(2, parent.Children.Count);
221221

222222
_topicRepository.Delete(topic);
223223

224-
Assert.AreEqual<int>(1, parent.Children.Count());
224+
Assert.AreEqual<int>(1, parent.Children.Count);
225225

226226
}
227227

OnTopic.Tests/RelatedTopicCollectionTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void GetAllTopics_ReturnsAllTopics() {
9595

9696
Assert.AreEqual<int>(5, relationships.Count);
9797
Assert.AreEqual<string>("Related3", relationships.GetTopics("Relationship3").First().Key);
98-
Assert.AreEqual<int>(5, relationships.GetAllTopics().Count());
98+
Assert.AreEqual<int>(5, relationships.GetAllTopics().Count);
9999

100100
}
101101

@@ -117,7 +117,7 @@ public void GetAllContentTypes_ReturnsAllContentTypes() {
117117
}
118118

119119
Assert.AreEqual<int>(5, relationships.Count);
120-
Assert.AreEqual<int>(1, relationships.GetAllTopics("ContentType3").Count());
120+
Assert.AreEqual<int>(1, relationships.GetAllTopics("ContentType3").Count);
121121

122122
}
123123

OnTopic.Tests/TopicTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public void FindAllByAttribute_ReturnsCorrectTopics() {
204204
grandNieceTopic.Attributes.SetValue("Foo", "Bar");
205205

206206
Assert.ReferenceEquals(parentTopic.FindAllByAttribute("Foo", "Bar").First(), grandNieceTopic);
207-
Assert.AreEqual<int>(2, parentTopic.FindAllByAttribute("Foo", "Bar").Count());
207+
Assert.AreEqual<int>(2, parentTopic.FindAllByAttribute("Foo", "Bar").Count);
208208
Assert.ReferenceEquals(parentTopic.FindAllByAttribute("Foo", "Baz").First(), grandChildTopic);
209209

210210
}

OnTopic/Internal/Reflection/TypeMemberInfoCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public bool HasSettableMethod(Type type, string name) {
268268
var method = GetMember<MethodInfo>(type, name);
269269
return (
270270
method != null &&
271-
method.GetParameters().Count().Equals(1) &&
271+
method.GetParameters().Length.Equals(1) &&
272272
IsSettableType(method.GetParameters().First().ParameterType) &&
273273
(_attributeFlag == null || System.Attribute.IsDefined(method, _attributeFlag))
274274
);

0 commit comments

Comments
 (0)