|
3 | 3 |
|
4 | 4 | using System.Collections.Concurrent;
|
5 | 5 | using System.Linq.Expressions;
|
| 6 | +using System.Reflection; |
6 | 7 |
|
7 | 8 | namespace Microsoft.AspNetCore.Components.Forms;
|
8 | 9 |
|
@@ -142,7 +143,7 @@ public void CanCreateFromExpression_Property()
|
142 | 143 | public void CanCreateFromExpression_PropertyUsesCache()
|
143 | 144 | {
|
144 | 145 | var models = new TestModel[] { new TestModel(), new TestModel() };
|
145 |
| - var cache = new ConcurrentDictionary<(Type ModelType, string FieldName), Func<object, object>>(); |
| 146 | + var cache = new ConcurrentDictionary<(Type ModelType, MemberInfo FieldName), Func<object, object>>(); |
146 | 147 | var result = new TestModel[2];
|
147 | 148 | for (var i = 0; i < models.Length; i++)
|
148 | 149 | {
|
@@ -221,6 +222,53 @@ public void CanCreateFromExpression_MemberOfObjectWithCast()
|
221 | 222 | Assert.Equal(nameof(TestModel.StringField), fieldIdentifier.FieldName);
|
222 | 223 | }
|
223 | 224 |
|
| 225 | + [Fact] |
| 226 | + public void CanCreateFromExpression_DifferentCaseField() |
| 227 | + { |
| 228 | + var fieldIdentifier = FieldIdentifier.Create(() => model.Field); |
| 229 | + Assert.Same(model, fieldIdentifier.Model); |
| 230 | + Assert.Equal(nameof(model.Field), fieldIdentifier.FieldName); |
| 231 | + } |
| 232 | + |
| 233 | + private DifferentCaseFieldModel model = new() { Field = 1 }; |
| 234 | +#pragma warning disable CA1823 // This is used in the test above |
| 235 | + private DifferentCaseFieldModel Model = new() { field = 2 }; |
| 236 | +#pragma warning restore CA1823 // Avoid unused private fields |
| 237 | + |
| 238 | + [Fact] |
| 239 | + public void CanCreateFromExpression_DifferentCaseProperty() |
| 240 | + { |
| 241 | + var fieldIdentifier = FieldIdentifier.Create(() => Model2.Property); |
| 242 | + Assert.Same(Model2, fieldIdentifier.Model); |
| 243 | + Assert.Equal(nameof(Model2.Property), fieldIdentifier.FieldName); |
| 244 | + } |
| 245 | + |
| 246 | + protected DifferentCasePropertyModel Model2 { get; } = new() { property = 1 }; |
| 247 | + |
| 248 | + protected DifferentCasePropertyModel model2 { get; } = new() { Property = 2 }; |
| 249 | + |
| 250 | + [Fact] |
| 251 | + public void CanCreateFromExpression_DifferentCasePropertyAndField() |
| 252 | + { |
| 253 | + var fieldIdentifier = FieldIdentifier.Create(() => model3.Value); |
| 254 | + Assert.Same(model3, fieldIdentifier.Model); |
| 255 | + Assert.Equal(nameof(Model3.Value), fieldIdentifier.FieldName); |
| 256 | + } |
| 257 | + |
| 258 | + [Fact] |
| 259 | + public void CanCreateFromExpression_NonAsciiCharacters() |
| 260 | + { |
| 261 | + var fieldIdentifier = FieldIdentifier.Create(() => @ÖvrigAnställning.Ort); |
| 262 | + Assert.Same(@ÖvrigAnställning, fieldIdentifier.Model); |
| 263 | + Assert.Equal(nameof(@ÖvrigAnställning.Ort), fieldIdentifier.FieldName); |
| 264 | + } |
| 265 | + |
| 266 | + public DifferentCasePropertyFieldModel Model3 { get; } = new() { value = 1 }; |
| 267 | + |
| 268 | + public DifferentCasePropertyFieldModel model3 = new() { Value = 2 }; |
| 269 | + |
| 270 | + public ÖvrigAnställningModel @ÖvrigAnställning { get; set; } = new(); |
| 271 | + |
224 | 272 | string StringPropertyOnThisClass { get; set; }
|
225 | 273 |
|
226 | 274 | class TestModel
|
@@ -253,4 +301,27 @@ public override int GetHashCode()
|
253 | 301 | return StringComparer.Ordinal.GetHashCode(Property);
|
254 | 302 | }
|
255 | 303 | }
|
| 304 | + |
| 305 | + public class ÖvrigAnställningModel |
| 306 | + { |
| 307 | + public int Ort { get; set; } |
| 308 | + } |
| 309 | + |
| 310 | + private class DifferentCaseFieldModel |
| 311 | + { |
| 312 | + public int Field; |
| 313 | + public int field; |
| 314 | + } |
| 315 | + |
| 316 | + protected class DifferentCasePropertyModel |
| 317 | + { |
| 318 | + public int Property { get; set; } |
| 319 | + public int property { get; set; } |
| 320 | + } |
| 321 | + |
| 322 | + public class DifferentCasePropertyFieldModel |
| 323 | + { |
| 324 | + public int Value { get; set; } |
| 325 | + public int value; |
| 326 | + } |
256 | 327 | }
|
0 commit comments