Skip to content

Commit 1650066

Browse files
committed
Fixing VS recommended messages in test project.
1 parent 960551c commit 1650066

25 files changed

Lines changed: 331 additions & 304 deletions

tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/AssertionExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public static void ShouldThrowException<T>(this Action action, Action<T> customA
3131
throws.ShouldBeTrue();
3232
}
3333

34-
public static void ShouldNotBeThrownBy(this Type exceptionType, Action action)
34+
#pragma warning disable IDE0060 // Remove unused parameter
35+
public static void ShouldNotBeThrownBy(this Type exceptionType, Action action)
36+
#pragma warning restore IDE0060 // Remove unused parameter
3537
=> action.ShouldNotThrow();
3638
}
3739
}

tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/AutoMapperSpecBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public abstract class NonValidatingSpecBase : SpecBase
2020
protected abstract MapperConfiguration Configuration { get; }
2121
protected IConfigurationProvider ConfigProvider => Configuration;
2222

23-
protected IMapper Mapper => mapper ?? (mapper = Configuration.CreateMapper());
23+
protected IMapper Mapper => mapper ??= Configuration.CreateMapper();
2424
}
2525

2626
public abstract class SpecBaseBase
@@ -59,6 +59,7 @@ protected SpecBase()
5959
public void Dispose()
6060
{
6161
Cleanup();
62+
GC.SuppressFinalize(this);
6263
}
6364
}
6465
}

tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapExpressionWithListConstants.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ public void Map_expression_with_constant_array()
2222
);
2323
config.AssertConfigurationIsValid();
2424
var mapper = config.CreateMapper();
25-
List<EntityModel> source1 = new() {
25+
List<EntityModel> source1 = [
2626
new EntityModel { SimpleEnum = SimpleEnumModel.Value3 }
27-
};
28-
List<EntityModel> source2 = new() {
27+
];
28+
List<EntityModel> source2 = [
2929
new EntityModel { SimpleEnum = SimpleEnumModel.Value1 }
30-
};
31-
Entity[] entities = new Entity[] { new Entity { SimpleEnum = SimpleEnum.Value1 }, new Entity { SimpleEnum = SimpleEnum.Value2 } };
30+
];
31+
Entity[] entities = [new Entity { SimpleEnum = SimpleEnum.Value1 }, new Entity { SimpleEnum = SimpleEnum.Value2 }];
3232
Expression<Func<Entity, bool>> filter = e => entities.Any(en => e.SimpleEnum == en.SimpleEnum);
3333

3434
//act
@@ -52,13 +52,13 @@ public void Map_expression_with_constant_list_using_generic_list_dot_contains()
5252
);
5353
config.AssertConfigurationIsValid();
5454
var mapper = config.CreateMapper();
55-
List<EntityModel> source1 = new() {
55+
List<EntityModel> source1 = [
5656
new EntityModel { SimpleEnum = SimpleEnumModel.Value3 }
57-
};
58-
List<EntityModel> source2 = new() {
57+
];
58+
List<EntityModel> source2 = [
5959
new EntityModel { SimpleEnum = SimpleEnumModel.Value1 }
60-
};
61-
List<SimpleEnum> enums = new() { SimpleEnum.Value1, SimpleEnum.Value2 };
60+
];
61+
List<SimpleEnum> enums = [SimpleEnum.Value1, SimpleEnum.Value2];
6262
Expression<Func<Entity, bool>> filter = e => enums.Contains(e.SimpleEnum);
6363

6464
//act
@@ -82,13 +82,13 @@ public void Map_expression_with_constant_list_using_generic_enumerable_dot_conta
8282
);
8383
config.AssertConfigurationIsValid();
8484
var mapper = config.CreateMapper();
85-
List<EntityModel> source1 = new() {
85+
List<EntityModel> source1 = [
8686
new EntityModel { SimpleEnum = SimpleEnumModel.Value3 }
87-
};
88-
List<EntityModel> source2 = new() {
87+
];
88+
List<EntityModel> source2 = [
8989
new EntityModel { SimpleEnum = SimpleEnumModel.Value1 }
90-
};
91-
List<SimpleEnum> enums = new() { SimpleEnum.Value1, SimpleEnum.Value2 };
90+
];
91+
List<SimpleEnum> enums = [SimpleEnum.Value1, SimpleEnum.Value2];
9292
Expression<Func<Entity, bool>> filter = e => Enumerable.Contains(enums, e.SimpleEnum);
9393

9494
//act
@@ -112,12 +112,12 @@ public void Map_expression_with_constant_dictionary()
112112
);
113113
config.AssertConfigurationIsValid();
114114
var mapper = config.CreateMapper();
115-
List<EntityModel> source1 = new() {
115+
List<EntityModel> source1 = [
116116
new EntityModel { SimpleEnum = SimpleEnumModel.Value3 }
117-
};
118-
List<EntityModel> source2 = new() {
117+
];
118+
List<EntityModel> source2 = [
119119
new EntityModel { SimpleEnum = SimpleEnumModel.Value1 }
120-
};
120+
];
121121
Dictionary<string, SimpleEnum> enumDictionary = new() { ["A"] = SimpleEnum.Value1, ["B"] = SimpleEnum.Value2 };
122122
Expression<Func<Entity, bool>> filter = e => enumDictionary.Any(i => i.Value == e.SimpleEnum);
123123

@@ -143,12 +143,12 @@ public void Map_expression_with_constant_dictionary_mapping_both_Key_and_value()
143143
);
144144
config.AssertConfigurationIsValid();
145145
var mapper = config.CreateMapper();
146-
List<EntityModel> source1 = new() {
146+
List<EntityModel> source1 = [
147147
new EntityModel { SimpleEnum = SimpleEnumModel.Value3 }
148-
};
149-
List<EntityModel> source2 = new() {
148+
];
149+
List<EntityModel> source2 = [
150150
new EntityModel { SimpleEnum = SimpleEnumModel.Value1 }
151-
};
151+
];
152152
Dictionary<SimpleEnum, Entity> enumDictionary = new() { [SimpleEnum.Value1] = new Entity { SimpleEnum = SimpleEnum.Value1 }, [SimpleEnum.Value2] = new Entity { SimpleEnum = SimpleEnum.Value2 } };
153153
Expression<Func<Entity, bool>> filter = e => enumDictionary.Any(i => i.Key == e.SimpleEnum && i.Value.SimpleEnum == e.SimpleEnum);
154154

tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapMemberFromTypeBinaryExpression.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public void Can_map_using_type_binary_expression_to_test_a_member_expression()
6666
Expression<Func<ShapeHolder, bool>> whereMapped = mapper.MapExpression<Expression<Func<ShapeHolder, bool>>>(where);
6767
var list = new List<ShapeHolder>
6868
{
69-
new ShapeHolder { Shape = new Circle() },
70-
new ShapeHolder { Shape = new Triangle() }
69+
new() { Shape = new Circle() },
70+
new() { Shape = new Triangle() }
7171
}
7272
.AsQueryable()
7373
.Where(whereMapped).ToList();
@@ -130,7 +130,7 @@ public void Can_map_using_static_method_call_to_test_the_parameter_expression()
130130

131131
//act
132132
Expression<Func<Shape, bool>> whereMapped = mapper.MapExpression<Expression<Func<Shape, bool>>>(where);
133-
var list = new List<Shape> { new Circle() { Messages = new List<string> { "" } }, new Triangle() { Messages = new List<string>() } }.AsQueryable().Where(whereMapped).ToList();
133+
var list = new List<Shape> { new Circle() { Messages = [""] }, new Triangle() { Messages = [] } }.AsQueryable().Where(whereMapped).ToList();
134134

135135
//assert
136136
Assert.Single(list);
@@ -218,7 +218,7 @@ public static class ShapeExtentions
218218
{
219219
public static bool HasMessages(this CanMapMemberFromTypeBinaryExpression.Shape shape)
220220
{
221-
return shape.Messages.Any();
221+
return shape.Messages.Count != 0;
222222
}
223223

224224
public static bool IsCircle<T>(this T shape)

tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapParameterBodyFromChildReferenceWithoutMemberExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void Can_map_parameter_body_from_child_reference_without_member_expressio
2525
var mapper = config.CreateMapper();
2626

2727
var products = new List<TestProduct>() {
28-
new TestProduct { }
28+
new() { }
2929
}.AsQueryable();
3030

3131
//Act

tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapParameterBodyWithoutMemberExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void Can_map_parameter_body_without_member_expression()
2222
var mapper = config.CreateMapper();
2323

2424
var products = new List<TestProduct>() {
25-
new TestProduct { }
25+
new() { }
2626
}.AsQueryable();
2727

2828
//Act

tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/EF.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
{
33
internal class EF
44
{
5+
#pragma warning disable IDE0060 // Remove unused parameter
56
internal static T Property<T>(object p, string v)
7+
#pragma warning restore IDE0060 // Remove unused parameter
68
{
79
return default;
810
}

tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/EnumerableDotContainsWorksOnLocalVariables.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public void Issue87()
3333
var mapped3 = mapper.MapExpression<Expression<Func<Source, bool>>>(expression3);
3434
var mapped4 = mapper.MapExpression<Expression<Func<Source, bool>>>(expression4);
3535

36-
Assert.Equal(1, new Source[] { new Source { } }.AsQueryable().Where(mapped1).Count());
37-
Assert.Equal(0, new Source[] { new Source { } }.AsQueryable().Where(mapped2).Count());
38-
Assert.Equal(1, new Source[] { new Source { Items = new List<SubSource> { new SubSource { Name = "item1" } } } }.AsQueryable().Where(mapped3).Count());
39-
Assert.Equal(0, new Source[] { new Source { Items = new List<SubSource> { new SubSource { Name = "" } } } }.AsQueryable().Where(mapped4).Count());
36+
Assert.Equal(1, new Source[] { new() { } }.AsQueryable().Where(mapped1).Count());
37+
Assert.Equal(0, new Source[] { new() { } }.AsQueryable().Where(mapped2).Count());
38+
Assert.Equal(1, new Source[] { new() { Items = [new SubSource { Name = "item1" }] } }.AsQueryable().Where(mapped3).Count());
39+
Assert.Equal(0, new Source[] { new() { Items = [new SubSource { Name = "" }] } }.AsQueryable().Where(mapped4).Count());
4040
}
4141

4242
public class Source { public ICollection<SubSource> Items { get; set; } }

tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/ExplicitExpansionAsDataSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected override void Because_of()
7474
}
7575
};
7676

77-
_dests = sourceList.AsQueryable().UseAsDataSource(Configuration).For<Dest>(d => d.Child2, d => d.Child4, d => d.Child4.GrandChild).ToArray();
77+
_dests = [.. sourceList.AsQueryable().UseAsDataSource(Configuration).For<Dest>(d => d.Child2, d => d.Child4, d => d.Child4.GrandChild)];
7878
}
7979

8080
[Fact]

tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/ExpressionMapping.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,14 @@ public void When_Use_Sub_Lambda_Statement()
212212
public void When_Use_Multiple_Parameter_Lambda_Statement()
213213
{
214214
_predicateExpression = p => p.Children.Any((c, i) => c.ID_ > 4);
215-
_valid = new Parent { Children = new[] { new Child { ID = 5 } } };
215+
_valid = new Parent { Children = [new Child { ID = 5 }] };
216216
}
217217

218218
[Fact]
219219
public void When_Use_Lambda_Statement_With_TypeMapped_Property_Being_Other_Than_First()
220220
{
221221
_predicateExpression = p => p.Children.AnyParamReverse((c, c2) => c.ID_ > 4);
222-
_valid = new Parent {Children = new[] {new Child {ID = 5}}};
222+
_valid = new Parent {Children = [new Child {ID = 5}]};
223223
}
224224

225225
[Fact]
@@ -228,10 +228,10 @@ public void When_Use_Child_TypeMap_In_Sub_Lambda_Statement()
228228
_predicateExpression = p => p.Children.Any(c => c.GrandChild.GrandChild.ID_ == 4);
229229
_valid = new Parent
230230
{
231-
Children = new[]
232-
{
231+
Children =
232+
[
233233
new Child {GrandChild = new Child {GrandChild = new Child {ID = 4}}}
234-
}
234+
]
235235
};
236236
}
237237

@@ -242,7 +242,7 @@ public void When_Use_Parent_And_Child_Lambda_Parameters_In_Child_Lambda_Statemen
242242
_valid = new Parent
243243
{
244244
Child = new Child {ID = 4},
245-
Children = new[] {new Child {GrandChild = new Child {ID = 4}}}
245+
Children = [new Child {GrandChild = new Child {ID = 4}}]
246246
};
247247
}
248248

@@ -295,7 +295,7 @@ public void When_Using_Everything_At_Once()
295295
{
296296
var year = DateTime.Now.Year;
297297
_predicateExpression = p => p.DateTime.Year == year && p.Child.Parent.Child.GrandChild.Parent.Child.GrandChild.GrandChild.ID_ == 4 && p.Children.Any(c => c.GrandChild.GrandChild.ID_ == 4);
298-
_valid = new Parent { DateTime = DateTime.Now, Child = new Child { GrandChild = new Child { GrandChild = new Child { ID = 4 } } }, Children = new[] { new Child { GrandChild = new Child { GrandChild = new Child { ID = 4 } } } } };
298+
_valid = new Parent { DateTime = DateTime.Now, Child = new Child { GrandChild = new Child { GrandChild = new Child { ID = 4 } } }, Children = [new Child { GrandChild = new Child { GrandChild = new Child { ID = 4 } } }] };
299299
}
300300

301301
[Fact]
@@ -324,9 +324,8 @@ public void Should_map_with_closures()
324324
{
325325
var req = new TestData { Code = "DD" };
326326
Expression<Func<TestData, bool>> f = s => s.Code == req.Code;
327-
#pragma warning disable CA2263 // Prefer generic overload when type is known
327+
328328
var result = (Expression<Func<TestModel, bool>>) Mapper.Map(f, typeof(Expression<Func<TestData, bool>>), typeof(Expression<Func<TestModel, bool>>));
329-
#pragma warning restore CA2263 // Prefer generic overload when type is known
330329

331330
var func = result.Compile();
332331

0 commit comments

Comments
 (0)