diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/CollectionModelBinderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/CollectionModelBinderTest.cs index fdc17cf9f8..c6d3c9796d 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/CollectionModelBinderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/CollectionModelBinderTest.cs @@ -10,7 +10,6 @@ using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding.Test; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; -using Moq; using Xunit; namespace Microsoft.AspNetCore.Mvc.ModelBinding @@ -367,11 +366,16 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding bool isReadOnly = false) { var metadataProvider = new TestModelMetadataProvider(); - metadataProvider.ForType>().BindingDetails(bd => bd.IsReadOnly = isReadOnly); + metadataProvider + .ForProperty(nameof(ModelWithIListProperty.ListProperty)) + .BindingDetails(bd => bd.IsReadOnly = isReadOnly); + var metadata = metadataProvider.GetMetadataForProperty( + typeof(ModelWithIListProperty), + nameof(ModelWithIListProperty.ListProperty)); var bindingContext = new DefaultModelBindingContext { - ModelMetadata = metadataProvider.GetMetadataForType(typeof(IList)), + ModelMetadata = metadata, ModelName = "someName", ModelState = new ModelStateDictionary(), ValueProvider = valueProvider, @@ -431,6 +435,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding public List ListProperty { get; set; } } + private class ModelWithIListProperty + { + public IList ListProperty { get; set; } + } + private class ModelWithSimpleProperties { public int Id { get; set; } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/DictionaryModelBinderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/DictionaryModelBinderTest.cs index 50c086eabd..d9ad2333ec 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/DictionaryModelBinderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/DictionaryModelBinderTest.cs @@ -472,7 +472,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Test IDictionary> values) { var metadataProvider = new TestModelMetadataProvider(); - metadataProvider.ForType>().BindingDetails(bd => bd.IsReadOnly = isReadOnly); + metadataProvider + .ForProperty(nameof(ModelWithIDictionaryProperty.DictionaryProperty)) + .BindingDetails(bd => bd.IsReadOnly = isReadOnly); + var metadata = metadataProvider.GetMetadataForProperty( + typeof(ModelWithIDictionaryProperty), + nameof(ModelWithIDictionaryProperty.DictionaryProperty)); var binder = new StubModelBinder(mbc => { @@ -491,7 +496,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Test var bindingContext = new DefaultModelBindingContext { - ModelMetadata = metadataProvider.GetMetadataForType(typeof(IDictionary)), + ModelMetadata = metadata, ModelName = "someName", ModelState = new ModelStateDictionary(), OperationBindingContext = new OperationBindingContext @@ -507,6 +512,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Test return bindingContext; } + private class ModelWithIDictionaryProperty + { + public IDictionary DictionaryProperty { get; set; } + } + private class ModelWithDictionaryProperties { // A Dictionary instance cannot be assigned to this property.