Skip to content

Commit f00d98c

Browse files
committed
Modernize code. Mostly analyzer fixes
1 parent 22f3f58 commit f00d98c

66 files changed

Lines changed: 1167 additions & 1283 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ dotnet_sort_system_directives_first = true
1919

2020
csharp_style_namespace_declarations = file_scoped:suggestion
2121

22-
[*.cs]
22+
# IDE0130: Namespace does not match folder structure
23+
dotnet_style_namespace_match_folder = false
24+
2325
# CS1574: XML comment has cref attribute that could not be resolved
2426
dotnet_diagnostic.CS1574.severity = none
27+
28+
# IDE0057: Use range operator
29+
csharp_style_prefer_range_operator = false

src/RepoDb.Core.UnitTests/Cachers/ClassMappedNameCacheTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ public void TestWithMapAttributeAndWithClassMapperMapping()
8484
Assert.AreEqual(expected, actual);
8585
}
8686

87-
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
87+
[TestMethod]
8888
public void ThrowExceptionOnClassMappingCacheIfTheTypeIsNull()
8989
{
9090
// Setup
91-
ClassMappedNameCache.Get(null);
91+
Assert.ThrowsExactly<ArgumentNullException>(() => ClassMappedNameCache.Get(null));
9292
}
9393

9494
#endregion

src/RepoDb.Core.UnitTests/Cachers/MemoryCacheTest.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,35 +158,35 @@ public void TestMemoryCacheManualExpirationDateViaCacheItem()
158158
Assert.AreEqual(expirationInMinutes, (actual.Expiration - actual.CreatedDate).TotalMinutes);
159159
}
160160

161-
[TestMethod, ExpectedException(typeof(MappingExistsException))]
161+
[TestMethod]
162162
public void ThrowExceptionOnAddingNewItemAtMemoryCacheWithTheSameKey()
163163
{
164164
// Prepare
165165
var cache = new MemoryCache();
166166
cache.Add("Key", new object(), throwException: true);
167167

168168
// Act/Assert
169-
cache.Add("Key", new object(), throwException: true);
169+
Assert.ThrowsExactly<MappingExistsException>(() => cache.Add("Key", new object(), throwException: true));
170170
}
171171

172-
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
172+
[TestMethod]
173173
public void ThrowExceptionAtMemoryCacheOnAddingACacheWithNegativeExpiration()
174174
{
175175
// Prepare
176-
var cache = new MemoryCache
176+
Assert.ThrowsExactly<ArgumentOutOfRangeException>(() => new MemoryCache
177177
{
178178
// Act/Assert
179179
{ "Key", "Value", -1 }
180-
};
180+
});
181181
}
182182

183-
[TestMethod, ExpectedException(typeof(ItemNotFoundException))]
183+
[TestMethod]
184184
public void ThrowExceptionAtMemoryCacheOnRemovingAKeyThatIsNotPresent()
185185
{
186186
// Prepare
187187
var cache = new MemoryCache();
188188

189189
// Act/Assert
190-
cache.Remove("Key", true);
190+
Assert.ThrowsExactly<ItemNotFoundException>(() => cache.Remove("Key", true));
191191
}
192192
}

src/RepoDb.Core.UnitTests/Cachers/PropertyMappedNameCacheTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public void TestWithMapAttribute()
5454
Assert.AreEqual(expected, property.GetMappedName());
5555
}
5656

57-
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
57+
[TestMethod]
5858
public void ThrowExceptionOnPropertyMappingCacheIfThePropertyIsNull()
5959
{
6060
// Setup
61-
PropertyMappedNameCache.Get<PropertyMappedNameCacheTestClass>((Field)null);
61+
Assert.ThrowsExactly<ArgumentNullException>(() => PropertyMappedNameCache.Get<PropertyMappedNameCacheTestClass>((Field)null));
6262
}
6363

6464
#endregion

src/RepoDb.Core.UnitTests/Cachers/PropertyValueAttributeCacheTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ private class PropertyValueAttributeClass
5151
#region Helpers
5252

5353
private IEnumerable<PropertyValueAttribute> GetPropertyValueAttributes() =>
54-
new PropertyValueAttribute[]
55-
{
54+
[
5655
// Different Values
5756
new NameAttribute("ColumnString"),
5857
new DbTypeAttribute(DbType.StringFixedLength),
@@ -62,7 +61,7 @@ private IEnumerable<PropertyValueAttribute> GetPropertyValueAttributes() =>
6261
new IsNullableAttribute(true),
6362
new PrecisionAttribute(100),
6463
new ScaleAttribute(2)
65-
};
64+
];
6665

6766
#endregion
6867

src/RepoDb.Core.UnitTests/ClassHandlers/ClassHandlerInvocationTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ private class ClassHandlerDbCommand : CustomDbCommand
3939
{
4040
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
4141
{
42-
var reader = new DataEntityDataReader<ClassHandlerTestClass>(new[]
43-
{
42+
var reader = new DataEntityDataReader<ClassHandlerTestClass>(
43+
[
4444
new ClassHandlerTestClass { Id = 1, Name = "James Doe" }
45-
});
45+
]);
4646
return reader;
4747
}
4848
}

src/RepoDb.Core.UnitTests/ClassHandlers/ClassHandlerPrecedenceTest.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ private class ClassHandlerDbCommand : CustomDbCommand
5353
{
5454
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
5555
{
56-
var reader = new DataEntityDataReader<ClassHandlerTestClass>(new[]
57-
{
56+
var reader = new DataEntityDataReader<ClassHandlerTestClass>(
57+
[
5858
new ClassHandlerTestClass { Id = 1, Name = "James Doe" }
59-
});
59+
]);
6060
return reader;
6161
}
6262
}
@@ -73,10 +73,10 @@ private class ClassHandlerForEntityWithAttributeDbCommand : CustomDbCommand
7373
{
7474
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
7575
{
76-
var reader = new DataEntityDataReader<ClassHandlerTestClassWithAttribute>(new[]
77-
{
76+
var reader = new DataEntityDataReader<ClassHandlerTestClassWithAttribute>(
77+
[
7878
new ClassHandlerTestClassWithAttribute { Id = 1, Name = "James Doe" }
79-
});
79+
]);
8080
return reader;
8181
}
8282
}
@@ -94,10 +94,10 @@ private class ClassHandlerForEntityWithGenericAttributeDbCommand : CustomDbComma
9494
{
9595
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
9696
{
97-
var reader = new DataEntityDataReader<ClassHandlerTestClassWithGenericAttribute>(new[]
98-
{
97+
var reader = new DataEntityDataReader<ClassHandlerTestClassWithGenericAttribute>(
98+
[
9999
new ClassHandlerTestClassWithGenericAttribute { Id = 1, Name = "James Doe" }
100-
});
100+
]);
101101
return reader;
102102
}
103103
}

src/RepoDb.Core.UnitTests/CustomObjects/CustomDbHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public override DbFieldCollection GetFields(IDbConnection connection,
1616
string tableName,
1717
IDbTransaction? transaction = null)
1818
{
19-
return new(new[]
20-
{
19+
return new(
20+
[
2121
new DbField("Id", true, true, false, typeof(int), null, null, null, null),
2222
new DbField("Name", false, false, true, typeof(string), null, null, null, null)
23-
});
23+
]);
2424
}
2525

2626
public override IEnumerable<DbSchemaObject> GetSchemaObjects(IDbConnection connection, IDbTransaction? transaction = null)

src/RepoDb.Core.UnitTests/DbHelpers/DbHelperTest.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ private class DbHelperDbConnection : CustomDbConnection { }
3434

3535
private DbFieldCollection GetDbFields()
3636
{
37-
return new(new[]
38-
{
37+
return new(
38+
[
3939
new DbField("Id", true, true, false, typeof(int), null, null, null, null),
4040
new DbField("Name", false, false, false, typeof(string), null, null, null, null)
41-
});
41+
]);
4242
}
4343

4444
public class MyDbHelper : BaseDbHelper
@@ -140,7 +140,7 @@ public void TestDbHelperForInsertAll()
140140
DbHelperMapper.Add<DbHelperDbConnection>(dbHelper.Object, true);
141141

142142
// Act
143-
connection.InsertAll<DbHelperDataEntity>(new[] { new DbHelperDataEntity { Id = 1, Name = "Name" } });
143+
connection.InsertAll<DbHelperDataEntity>([new DbHelperDataEntity { Id = 1, Name = "Name" }]);
144144

145145
// Assert
146146
dbHelper.Verify(builder =>
@@ -186,7 +186,7 @@ public void TestDbHelperForMergeAll()
186186
DbHelperMapper.Add<DbHelperDbConnection>(dbHelper.Object, true);
187187

188188
// Act
189-
connection.MergeAll<DbHelperDataEntity>(new[] { new DbHelperDataEntity { Id = 1, Name = "Name" } });
189+
connection.MergeAll<DbHelperDataEntity>([new DbHelperDataEntity { Id = 1, Name = "Name" }]);
190190

191191
// Assert
192192
dbHelper.Verify(builder =>
@@ -278,7 +278,7 @@ public void TestDbHelperForUpdateAll()
278278
DbHelperMapper.Add<DbHelperDbConnection>(dbHelper.Object, true);
279279

280280
// Act
281-
connection.UpdateAll<DbHelperDataEntity>(new[] { new DbHelperDataEntity { Id = 1, Name = "Name" } });
281+
connection.UpdateAll<DbHelperDataEntity>([new DbHelperDataEntity { Id = 1, Name = "Name" }]);
282282

283283
// Assert
284284
dbHelper.Verify(builder =>
@@ -357,7 +357,7 @@ public void TestDbHelperForInsertAllViaTableName()
357357

358358
// Act
359359
connection.InsertAll(ClassMappedNameCache.Get<DbHelperDataEntity>(),
360-
new[] { new { Id = 1, Name = "Name" } });
360+
[new { Id = 1, Name = "Name" }]);
361361

362362
// Assert
363363
dbHelper.Verify(builder =>
@@ -405,7 +405,7 @@ public void TestDbHelperForMergeAllViaTableName()
405405

406406
// Act
407407
connection.MergeAll(ClassMappedNameCache.Get<DbHelperDataEntity>(),
408-
new[] { new DbHelperDataEntity { Id = 1, Name = "Name" } });
408+
[new DbHelperDataEntity { Id = 1, Name = "Name" }]);
409409

410410
// Assert
411411
dbHelper.Verify(builder =>
@@ -500,7 +500,7 @@ public void TestDbHelperForUpdateAllViaTableName()
500500

501501
// Act
502502
connection.UpdateAll(ClassMappedNameCache.Get<DbHelperDataEntity>(),
503-
new[] { new DbHelperDataEntity { Id = 1, Name = "Name" } });
503+
[new DbHelperDataEntity { Id = 1, Name = "Name" }]);
504504

505505
// Assert
506506
dbHelper.Verify(builder =>

0 commit comments

Comments
 (0)