diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Abstractions/Formatters/OutputFormatterCanWriteContext.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Abstractions/Formatters/OutputFormatterCanWriteContext.cs index e42c092624..ae48a91b1e 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Abstractions/Formatters/OutputFormatterCanWriteContext.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Abstractions/Formatters/OutputFormatterCanWriteContext.cs @@ -12,20 +12,6 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// public abstract class OutputFormatterCanWriteContext { - /// - /// - /// This constructor is obsolete and will be removed in a future version. - /// Please use instead. - /// - /// - /// Creates a new . - /// - /// - [Obsolete("This constructor is obsolete and will be removed in a future version. Please use the constructor taking a HttpContext instead.")] - protected OutputFormatterCanWriteContext() - { - } - /// /// Creates a new . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.ApiExplorer/DefaultApiDescriptionProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.ApiExplorer/DefaultApiDescriptionProvider.cs index e5564f497f..5c2634c1b2 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.ApiExplorer/DefaultApiDescriptionProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.ApiExplorer/DefaultApiDescriptionProvider.cs @@ -29,44 +29,6 @@ namespace Microsoft.AspNetCore.Mvc.ApiExplorer private readonly IInlineConstraintResolver _constraintResolver; private readonly IModelMetadataProvider _modelMetadataProvider; - /// - /// Creates a new instance of . - /// - /// The accessor for . - /// The used for resolving inline - /// constraints. - /// The . - [Obsolete("This constructor is obsolete and will be removed in a future release.")] - public DefaultApiDescriptionProvider( - IOptions optionsAccessor, - IInlineConstraintResolver constraintResolver, - IModelMetadataProvider modelMetadataProvider) - : this(optionsAccessor, constraintResolver, modelMetadataProvider, null) - { - } - - /// - /// Creates a new instance of . - /// - /// The accessor for . - /// The used for resolving inline - /// constraints. - /// The . - /// The . - /// The parameter is currently ignored. - [Obsolete("This constructor is obsolete and will be removed in a future release.")] - public DefaultApiDescriptionProvider( - IOptions optionsAccessor, - IInlineConstraintResolver constraintResolver, - IModelMetadataProvider modelMetadataProvider, - IActionResultTypeMapper mapper) - { - _mvcOptions = optionsAccessor.Value; - _constraintResolver = constraintResolver; - _modelMetadataProvider = modelMetadataProvider; - _responseTypeProvider = new ApiResponseTypeProvider(modelMetadataProvider, mapper, _mvcOptions); - } - /// /// Creates a new instance of . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatFilter.cs index 5ba22953e5..d5b52f01e0 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatFilter.cs @@ -21,16 +21,6 @@ namespace Microsoft.AspNetCore.Mvc.Formatters private readonly MvcOptions _options; private readonly ILogger _logger; - /// - /// Initializes an instance of . - /// - /// The - [Obsolete("This constructor is obsolete and will be removed in a future version.")] - public FormatFilter(IOptions options) - : this(options, NullLoggerFactory.Instance) - { - } - /// /// Initializes an instance of . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/LocalRedirectResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/LocalRedirectResult.cs index a600c39079..2f73c47c76 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/LocalRedirectResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/LocalRedirectResult.cs @@ -104,42 +104,5 @@ namespace Microsoft.AspNetCore.Mvc var executor = context.HttpContext.RequestServices.GetRequiredService>(); return executor.ExecuteAsync(context, this); } - -#pragma warning disable CS0809 - [Obsolete("This implementation will be removed in a future release, use ExecuteResultAsync.")] - public override void ExecuteResult(ActionContext context) - { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - - var services = context.HttpContext.RequestServices; - var urlHelperFactory = services.GetRequiredService(); - var logger = services.GetRequiredService>(); - - var urlHelper = UrlHelper ?? urlHelperFactory.GetUrlHelper(context); - - // IsLocalUrl is called to handle Urls starting with '~/'. - if (!urlHelper.IsLocalUrl(Url)) - { - throw new InvalidOperationException(Resources.UrlNotLocal); - } - - var destinationUrl = urlHelper.Content(Url); - logger.LocalRedirectResultExecuting(destinationUrl); - - if (PreserveMethod) - { - context.HttpContext.Response.StatusCode = Permanent ? - StatusCodes.Status308PermanentRedirect : StatusCodes.Status307TemporaryRedirect; - context.HttpContext.Response.Headers[HeaderNames.Location] = destinationUrl; - } - else - { - context.HttpContext.Response.Redirect(destinationUrl, Permanent); - } - } -#pragma warning restore CS0809 } } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ArrayModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ArrayModelBinder.cs index ccfa3f6af7..29705d88a6 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ArrayModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ArrayModelBinder.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { @@ -16,21 +15,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders /// Type of elements in the array. public class ArrayModelBinder : CollectionModelBinder { - /// - /// This constructor is obsolete and will be removed in a future version. The recommended alternative - /// is the overload that also takes an . - /// Creates a new . - /// - /// - /// The for binding . - /// - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative" - + " is the overload that also takes an " + nameof(ILoggerFactory) + ".")] - public ArrayModelBinder(IModelBinder elementBinder) - : this(elementBinder, NullLoggerFactory.Instance) - { - } - /// /// Creates a new . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ByteArrayModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ByteArrayModelBinder.cs index c3772d8383..ca77af7cf6 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ByteArrayModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ByteArrayModelBinder.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { @@ -15,18 +14,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { private readonly ILogger _logger; - /// - /// This constructor is obsolete and will be removed in a future version. The recommended alternative - /// is the overload that takes an . - /// Initializes a new instance of . - /// - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative" - + " is the overload that takes an " + nameof(ILoggerFactory) + ".")] - public ByteArrayModelBinder() - : this(NullLoggerFactory.Instance) - { - } - /// /// Initializes a new instance of . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CollectionModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CollectionModelBinder.cs index 70aa099cfe..8746cd487e 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CollectionModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CollectionModelBinder.cs @@ -11,7 +11,6 @@ using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { @@ -24,19 +23,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders private static readonly IValueProvider EmptyValueProvider = new CompositeValueProvider(); private Func _modelCreator; - /// - /// This constructor is obsolete and will be removed in a future version. The recommended alternative - /// is the overload that also takes an . - /// Creates a new . - /// - /// The for binding elements. - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative" - + " is the overload that also takes an " + nameof(ILoggerFactory) + ".")] - public CollectionModelBinder(IModelBinder elementBinder) - : this(elementBinder, NullLoggerFactory.Instance) - { - } - /// /// Creates a new . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ComplexTypeModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ComplexTypeModelBinder.cs index b44a969643..fa1b482f70 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ComplexTypeModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ComplexTypeModelBinder.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { @@ -22,21 +21,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders private readonly ILogger _logger; private Func _modelCreator; - /// - /// This constructor is obsolete and will be removed in a future version. The recommended alternative - /// is the overload that also takes an . - /// Creates a new . - /// - /// - /// The of binders to use for binding properties. - /// - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative" - + " is the overload that also takes an " + nameof(ILoggerFactory) + ".")] - public ComplexTypeModelBinder(IDictionary propertyBinders) - : this(propertyBinders, NullLoggerFactory.Instance) - { - } - /// /// Creates a new . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DecimalModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DecimalModelBinder.cs index 3670185732..b8f27116b5 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DecimalModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DecimalModelBinder.cs @@ -6,7 +6,6 @@ using System.Globalization; using System.Runtime.ExceptionServices; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { @@ -19,19 +18,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders private readonly NumberStyles _supportedStyles; private readonly ILogger _logger; - /// - /// This constructor is obsolete and will be removed in a future version. The recommended alternative - /// is the overload that also takes an . - /// Initializes a new instance of . - /// - /// The . - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative" - + " is the overload that also takes an " + nameof(ILoggerFactory) + ".")] - public DecimalModelBinder(NumberStyles supportedStyles) - : this(supportedStyles, NullLoggerFactory.Instance) - { - } - /// /// Initializes a new instance of . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DictionaryModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DictionaryModelBinder.cs index 7f8ef63d0a..412cfd59af 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DictionaryModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DictionaryModelBinder.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { @@ -21,20 +20,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { private readonly IModelBinder _valueBinder; - /// - /// This constructor is obsolete and will be removed in a future version. The recommended alternative - /// is the overload that also takes an . - /// Creates a new . - /// - /// The for . - /// The for . - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative" - + " is the overload that also takes an " + nameof(ILoggerFactory) + ".")] - public DictionaryModelBinder(IModelBinder keyBinder, IModelBinder valueBinder) - : this(keyBinder, valueBinder, NullLoggerFactory.Instance) - { - } - /// /// Creates a new . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DoubleModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DoubleModelBinder.cs index 3a62b2fa39..64dd08301a 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DoubleModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DoubleModelBinder.cs @@ -6,7 +6,6 @@ using System.Globalization; using System.Runtime.ExceptionServices; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { @@ -19,19 +18,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders private readonly NumberStyles _supportedStyles; private readonly ILogger _logger; - /// - /// This constructor is obsolete and will be removed in a future version. The recommended alternative - /// is the overload that also takes an . - /// Initializes a new instance of . - /// - /// The . - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative" - + " is the overload that also takes an " + nameof(ILoggerFactory) + ".")] - public DoubleModelBinder(NumberStyles supportedStyles) - : this(supportedStyles, NullLoggerFactory.Instance) - { - } - /// /// Initializes a new instance of . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FloatModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FloatModelBinder.cs index c34a8be777..09a150213b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FloatModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FloatModelBinder.cs @@ -6,7 +6,6 @@ using System.Globalization; using System.Runtime.ExceptionServices; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { @@ -19,19 +18,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders private readonly NumberStyles _supportedStyles; private readonly ILogger _logger; - /// - /// This constructor is obsolete and will be removed in a future version. The recommended alternative - /// is the overload that also takes an . - /// Initializes a new instance of . - /// - /// The . - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative" - + " is the overload that also takes an " + nameof(ILoggerFactory) + ".")] - public FloatModelBinder(NumberStyles supportedStyles) - : this(supportedStyles, NullLoggerFactory.Instance) - { - } - /// /// Initializes a new instance of . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs index 3c26cafb2d..7113a2563d 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders @@ -20,18 +19,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { private readonly ILogger _logger; - /// - /// This constructor is obsolete and will be removed in a future version. The recommended alternative - /// is the overload that takes an . - /// Initializes a new instance of . - /// - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative" - + " is the overload that takes an " + nameof(ILoggerFactory) + ".")] - public FormCollectionModelBinder() - : this(NullLoggerFactory.Instance) - { - } - /// /// Initializes a new instance of . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormFileModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormFileModelBinder.cs index 526225343e..597eeba279 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormFileModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormFileModelBinder.cs @@ -10,7 +10,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { @@ -21,18 +20,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { private readonly ILogger _logger; - /// - /// This constructor is obsolete and will be removed in a future version. The recommended alternative - /// is the overload that takes an . - /// Initializes a new instance of . - /// - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative" - + " is the overload that takes an " + nameof(ILoggerFactory) + ".")] - public FormFileModelBinder() - : this(NullLoggerFactory.Instance) - { - } - /// /// Initializes a new instance of . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/HeaderModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/HeaderModelBinder.cs index 54ce71f896..e8faee0175 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/HeaderModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/HeaderModelBinder.cs @@ -7,7 +7,6 @@ using System.Globalization; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { @@ -19,18 +18,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { private readonly ILogger _logger; - /// - /// This constructor is obsolete and will be removed in a future version. The recommended alternative - /// is the overload that takes an and an . - /// Initializes a new instance of . - /// - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative" - + " is the overload that takes an " + nameof(ILoggerFactory) + " and an " + nameof(IModelBinder) + ".")] - public HeaderModelBinder() - : this(NullLoggerFactory.Instance) - { - } - /// /// Initializes a new instance of . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/KeyValuePairModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/KeyValuePairModelBinder.cs index 45aab720ba..bc61e66ebb 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/KeyValuePairModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/KeyValuePairModelBinder.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { @@ -20,20 +19,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders private readonly IModelBinder _valueBinder; private readonly ILogger _logger; - /// - /// This constructor is obsolete and will be removed in a future version. The recommended alternative - /// is the overload that also takes an . - /// Creates a new . - /// - /// The for . - /// The for . - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative" - + " is the overload that also takes an " + nameof(ILoggerFactory) + ".")] - public KeyValuePairModelBinder(IModelBinder keyBinder, IModelBinder valueBinder) - : this(keyBinder, valueBinder, NullLoggerFactory.Instance) - { - } - /// /// Creates a new . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/SimpleTypeModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/SimpleTypeModelBinder.cs index de1f1da636..8d9b1eeee9 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/SimpleTypeModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/SimpleTypeModelBinder.cs @@ -6,7 +6,6 @@ using System.ComponentModel; using System.Runtime.ExceptionServices; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { @@ -18,19 +17,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders private readonly TypeConverter _typeConverter; private readonly ILogger _logger; - /// - /// This constructor is obsolete and will be removed in a future version. The recommended alternative - /// is the overload that also takes an . - /// Initializes a new instance of . - /// - /// The type to create binder for. - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative" - + " is the overload that also takes an " + nameof(ILoggerFactory) + ".")] - public SimpleTypeModelBinder(Type type) - : this(type, NullLoggerFactory.Instance) - { - } - /// /// Initializes a new instance of . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/ModelAttributes.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/ModelAttributes.cs index 0f9a5bf103..b5cc024d22 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/ModelAttributes.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/ModelAttributes.cs @@ -13,31 +13,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// public class ModelAttributes { - private static readonly IEnumerable _emptyAttributesCollection = Enumerable.Empty(); - - /// - /// Creates a new for a . - /// - /// The set of attributes for the . - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative is " + nameof(ModelAttributes) + "." + nameof(GetAttributesForType) + ".")] - public ModelAttributes(IEnumerable typeAttributes) - : this(typeAttributes, null, null) - { - } - - /// - /// Creates a new for a property. - /// - /// The set of attributes for the property. - /// - /// The set of attributes for the property's . See . - /// - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative is " + nameof(ModelAttributes) + "." + nameof(GetAttributesForProperty) + ".")] - public ModelAttributes(IEnumerable propertyAttributes, IEnumerable typeAttributes) - : this(typeAttributes, propertyAttributes, null) - { - } - /// /// Creates a new . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ModelBinderFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ModelBinderFactory.cs index c9d973db2b..1cd59d4c72 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ModelBinderFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ModelBinderFactory.cs @@ -27,20 +27,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding private readonly ConcurrentDictionary _cache; private readonly IServiceProvider _serviceProvider; - /// - /// This constructor is obsolete and will be removed in a future version. The recommended alternative - /// is the overload that also takes an . - /// Creates a new . - /// - /// The . - /// The for . - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative" - + " is the overload that also takes an " + nameof(IServiceProvider) + ".")] - public ModelBinderFactory(IModelMetadataProvider metadataProvider, IOptions options) - : this(metadataProvider, options, GetDefaultServices()) - { - } - /// /// Creates a new . /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ParameterBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ParameterBinder.cs index 9486c663d2..77942ea538 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ParameterBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ParameterBinder.cs @@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Mvc.ModelBinding @@ -21,31 +20,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding private readonly IModelBinderFactory _modelBinderFactory; private readonly IObjectModelValidator _objectModelValidator; - /// - /// This constructor is obsolete and will be removed in a future version. The recommended alternative - /// is the overload that also takes a accessor and an . - /// - /// Initializes a new instance of . - /// - /// The . - /// The . - /// The . - [Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative" - + " is the overload that also takes a " + nameof(MvcOptions) + " accessor and an " - + nameof(ILoggerFactory) + " .")] - public ParameterBinder( - IModelMetadataProvider modelMetadataProvider, - IModelBinderFactory modelBinderFactory, - IObjectModelValidator validator) - : this( - modelMetadataProvider, - modelBinderFactory, - validator, - Options.Create(new MvcOptions()), - NullLoggerFactory.Instance) - { - } - /// /// Initializes a new instance of . /// @@ -98,85 +72,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// protected ILogger Logger { get; } - /// - /// - /// This method overload is obsolete and will be removed in a future version. The recommended alternative is - /// . - /// - /// Initializes and binds a model specified by . - /// - /// The . - /// The . - /// The - /// The result of model binding. - [Obsolete("This method overload is obsolete and will be removed in a future version. The recommended " + - "alternative is the overload that also takes " + nameof(IModelBinder) + ", " + nameof(ModelMetadata) + - " and " + nameof(Object) + " parameters.")] - public Task BindModelAsync( - ActionContext actionContext, - IValueProvider valueProvider, - ParameterDescriptor parameter) - { -#pragma warning disable CS0618 // Type or member is obsolete - return BindModelAsync(actionContext, valueProvider, parameter, value: null); -#pragma warning restore CS0618 // Type or member is obsolete - } - - /// - /// - /// This method overload is obsolete and will be removed in a future version. The recommended alternative is - /// . - /// - /// - /// Binds a model specified by using as the initial value. - /// - /// - /// The . - /// The . - /// The - /// The initial model value. - /// The result of model binding. - [Obsolete("This method overload is obsolete and will be removed in a future version. The recommended " + - "alternative is the overload that also takes " + nameof(IModelBinder) + " and " + nameof(ModelMetadata) + - " parameters.")] - public virtual Task BindModelAsync( - ActionContext actionContext, - IValueProvider valueProvider, - ParameterDescriptor parameter, - object value) - { - if (actionContext == null) - { - throw new ArgumentNullException(nameof(actionContext)); - } - - if (valueProvider == null) - { - throw new ArgumentNullException(nameof(valueProvider)); - } - - if (parameter == null) - { - throw new ArgumentNullException(nameof(parameter)); - } - - var metadata = _modelMetadataProvider.GetMetadataForType(parameter.ParameterType); - var binder = _modelBinderFactory.CreateBinder(new ModelBinderFactoryContext - { - BindingInfo = parameter.BindingInfo, - Metadata = metadata, - CacheToken = parameter, - }); - - return BindModelAsync( - actionContext, - binder, - valueProvider, - parameter, - metadata, - value); - } - /// /// Binds a model specified by using as the initial value. /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectResult.cs index 4fcd46a1d1..fdacf229e6 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectResult.cs @@ -3,14 +3,10 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Mvc { @@ -114,42 +110,5 @@ namespace Microsoft.AspNetCore.Mvc var executor = context.HttpContext.RequestServices.GetRequiredService>(); return executor.ExecuteAsync(context, this); } - -#pragma warning disable CS0809 - [Obsolete("This implementation will be removed in a future release, use ExecuteResultAsync.")] - public override void ExecuteResult(ActionContext context) - { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - - var services = context.HttpContext.RequestServices; - var urlHelperFactory = services.GetRequiredService(); - var logger = services.GetRequiredService>(); - - var urlHelper = UrlHelper ?? urlHelperFactory.GetUrlHelper(context); - - // IsLocalUrl is called to handle URLs starting with '~/'. - var destinationUrl = Url; - if (urlHelper.IsLocalUrl(destinationUrl)) - { - destinationUrl = urlHelper.Content(Url); - } - - logger.RedirectResultExecuting(destinationUrl); - - if (PreserveMethod) - { - context.HttpContext.Response.StatusCode = Permanent ? - StatusCodes.Status308PermanentRedirect : StatusCodes.Status307TemporaryRedirect; - context.HttpContext.Response.Headers[HeaderNames.Location] = destinationUrl; - } - else - { - context.HttpContext.Response.Redirect(destinationUrl, Permanent); - } - } -#pragma warning restore CS0809 } } \ No newline at end of file diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToActionResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToActionResult.cs index 06de942c13..3f6e33f599 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToActionResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToActionResult.cs @@ -3,15 +3,10 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Mvc { @@ -181,47 +176,5 @@ namespace Microsoft.AspNetCore.Mvc var executor = context.HttpContext.RequestServices.GetRequiredService>(); return executor.ExecuteAsync(context, this); } - -#pragma warning disable CS0809 - [Obsolete("This implementation will be removed in a future release, use ExecuteResultAsync.")] - public override void ExecuteResult(ActionContext context) - { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - - var services = context.HttpContext.RequestServices; - var urlHelperFactory = services.GetRequiredService(); - var logger = services.GetRequiredService>(); - - var urlHelper = UrlHelper ?? urlHelperFactory.GetUrlHelper(context); - - var destinationUrl = urlHelper.Action( - ActionName, - ControllerName, - RouteValues, - protocol: null, - host: null, - fragment: Fragment); - if (string.IsNullOrEmpty(destinationUrl)) - { - throw new InvalidOperationException(Resources.NoRoutesMatched); - } - - logger.RedirectToActionResultExecuting(destinationUrl); - - if (PreserveMethod) - { - context.HttpContext.Response.StatusCode = Permanent ? - StatusCodes.Status308PermanentRedirect : StatusCodes.Status307TemporaryRedirect; - context.HttpContext.Response.Headers[HeaderNames.Location] = destinationUrl; - } - else - { - context.HttpContext.Response.Redirect(destinationUrl, Permanent); - } - } -#pragma warning restore CS0809 } } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToPageResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToPageResult.cs index 5f82cd50df..e4ce064ae1 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToPageResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToPageResult.cs @@ -3,15 +3,10 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Mvc { @@ -220,47 +215,5 @@ namespace Microsoft.AspNetCore.Mvc var executor = context.HttpContext.RequestServices.GetRequiredService>(); return executor.ExecuteAsync(context, this); } - -#pragma warning disable CS0809 - [Obsolete("This implementation will be removed in a future release, use ExecuteResultAsync.")] - public override void ExecuteResult(ActionContext context) - { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - - var services = context.HttpContext.RequestServices; - var urlHelperFactory = services.GetRequiredService(); - var logger = services.GetRequiredService>(); - - var urlHelper = UrlHelper ?? urlHelperFactory.GetUrlHelper(context); - var destinationUrl = urlHelper.Page( - PageName, - PageHandler, - RouteValues, - Protocol, - Host, - fragment: Fragment); - - if (string.IsNullOrEmpty(destinationUrl)) - { - throw new InvalidOperationException(Resources.FormatNoRoutesMatchedForPage(PageName)); - } - - logger.RedirectToPageResultExecuting(PageName); - - if (PreserveMethod) - { - context.HttpContext.Response.StatusCode = Permanent ? - StatusCodes.Status308PermanentRedirect : StatusCodes.Status307TemporaryRedirect; - context.HttpContext.Response.Headers[HeaderNames.Location] = destinationUrl; - } - else - { - context.HttpContext.Response.Redirect(destinationUrl, Permanent); - } - } -#pragma warning restore CS0809 } } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToRouteResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToRouteResult.cs index 8966eab50e..81e13f9aa8 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToRouteResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToRouteResult.cs @@ -3,15 +3,10 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Mvc { @@ -173,46 +168,5 @@ namespace Microsoft.AspNetCore.Mvc var executor = context.HttpContext.RequestServices.GetRequiredService>(); return executor.ExecuteAsync(context, this); } - -#pragma warning disable CS0809 - [Obsolete("This implementation will be removed in a future release, use ExecuteResultAsync.")] - public override void ExecuteResult(ActionContext context) - { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - - var services = context.HttpContext.RequestServices; - var urlHelperFactory = services.GetRequiredService(); - var logger = services.GetRequiredService>(); - - var urlHelper = UrlHelper ?? urlHelperFactory.GetUrlHelper(context); - - var destinationUrl = urlHelper.RouteUrl( - RouteName, - RouteValues, - protocol: null, - host: null, - fragment: Fragment); - if (string.IsNullOrEmpty(destinationUrl)) - { - throw new InvalidOperationException(Resources.NoRoutesMatched); - } - - logger.RedirectToRouteResultExecuting(destinationUrl, RouteName); - - if (PreserveMethod) - { - context.HttpContext.Response.StatusCode = Permanent ? - StatusCodes.Status308PermanentRedirect : StatusCodes.Status307TemporaryRedirect; - context.HttpContext.Response.Headers[HeaderNames.Location] = destinationUrl; - } - else - { - context.HttpContext.Response.Redirect(destinationUrl, Permanent); - } - } -#pragma warning restore CS0809 } } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/KnownRouteValueConstraint.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/KnownRouteValueConstraint.cs index d3a7f5a32a..3278ed286f 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/KnownRouteValueConstraint.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/KnownRouteValueConstraint.cs @@ -18,13 +18,6 @@ namespace Microsoft.AspNetCore.Mvc.Routing private readonly IActionDescriptorCollectionProvider _actionDescriptorCollectionProvider; private RouteValuesCollection _cachedValuesCollection; - [Obsolete("This constructor is obsolete. Use KnownRouteValueConstraint.ctor(IActionDescriptorCollectionProvider) instead.")] - public KnownRouteValueConstraint() - { - // Empty constructor for backwards compatibility - // Services will need to be resolved from HttpContext when this ctor is used - } - public KnownRouteValueConstraint(IActionDescriptorCollectionProvider actionDescriptorCollectionProvider) { if (actionDescriptorCollectionProvider == null) diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/ProblemDetails21Wrapper.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/ProblemDetails21Wrapper.cs deleted file mode 100644 index 9a4dcf0bd7..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/ProblemDetails21Wrapper.cs +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Globalization; -using System.Xml; -using System.Xml.Schema; -using System.Xml.Serialization; - -namespace Microsoft.AspNetCore.Mvc.Formatters.Xml -{ - /// - /// Wrapper class for to enable it to be serialized by the xml formatters. - /// - [XmlRoot(nameof(ProblemDetails))] - [Obsolete("This type is deprecated and will be removed in a future version")] - public class ProblemDetails21Wrapper : IXmlSerializable, IUnwrappable - { - protected static readonly string EmptyKey = SerializableErrorWrapper.EmptyKey; - - public ProblemDetails21Wrapper() - : this(new ProblemDetails()) - { - } - - public ProblemDetails21Wrapper(ProblemDetails problemDetails) - { - ProblemDetails = problemDetails; - } - - internal ProblemDetails ProblemDetails { get; } - - /// - public XmlSchema GetSchema() => null; - - /// - public virtual void ReadXml(XmlReader reader) - { - if (reader == null) - { - throw new ArgumentNullException(nameof(reader)); - } - - if (reader.IsEmptyElement) - { - reader.Read(); - return; - } - - reader.ReadStartElement(); - while (reader.NodeType != XmlNodeType.EndElement) - { - var key = XmlConvert.DecodeName(reader.LocalName); - ReadValue(reader, key); - - reader.MoveToContent(); - } - - reader.ReadEndElement(); - } - - /// - /// Reads the value for the specified from the . - /// - /// The . - /// The name of the node. - protected virtual void ReadValue(XmlReader reader, string name) - { - if (reader == null) - { - throw new ArgumentNullException(nameof(reader)); - } - - var value = reader.ReadInnerXml(); - - switch (name) - { - case "Detail": - ProblemDetails.Detail = value; - break; - - case "Instance": - ProblemDetails.Instance = value; - break; - - case "Status": - ProblemDetails.Status = string.IsNullOrEmpty(value) ? - (int?)null : - int.Parse(value, CultureInfo.InvariantCulture); - break; - - case "Title": - ProblemDetails.Title = value; - break; - - case "Type": - ProblemDetails.Type = value; - break; - - default: - if (string.Equals(name, EmptyKey, StringComparison.Ordinal)) - { - name = string.Empty; - } - - ProblemDetails.Extensions.Add(name, value); - break; - } - } - - /// - public virtual void WriteXml(XmlWriter writer) - { - if (!string.IsNullOrEmpty(ProblemDetails.Detail)) - { - writer.WriteElementString( - XmlConvert.EncodeLocalName("Detail"), - ProblemDetails.Detail); - } - - if (!string.IsNullOrEmpty(ProblemDetails.Instance)) - { - writer.WriteElementString( - XmlConvert.EncodeLocalName("Instance"), - ProblemDetails.Instance); - } - - if (ProblemDetails.Status.HasValue) - { - writer.WriteStartElement(XmlConvert.EncodeLocalName("Status")); - writer.WriteValue(ProblemDetails.Status.Value); - writer.WriteEndElement(); - } - - if (!string.IsNullOrEmpty(ProblemDetails.Title)) - { - writer.WriteElementString( - XmlConvert.EncodeLocalName("Title"), - ProblemDetails.Title); - } - - if (!string.IsNullOrEmpty(ProblemDetails.Type)) - { - writer.WriteElementString( - XmlConvert.EncodeLocalName("Type"), - ProblemDetails.Type); - } - - foreach (var keyValuePair in ProblemDetails.Extensions) - { - var key = keyValuePair.Key; - var value = keyValuePair.Value; - - if (string.IsNullOrEmpty(key)) - { - key = EmptyKey; - } - - writer.WriteStartElement(XmlConvert.EncodeLocalName(key)); - if (value != null) - { - writer.WriteValue(value); - } - - writer.WriteEndElement(); - } - } - - object IUnwrappable.Unwrap(Type declaredType) - { - if (declaredType == null) - { - throw new ArgumentNullException(nameof(declaredType)); - } - - return ProblemDetails; - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/ValidationProblemDetails21Wrapper.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/ValidationProblemDetails21Wrapper.cs deleted file mode 100644 index e138c0f3d1..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/ValidationProblemDetails21Wrapper.cs +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Xml; -using System.Xml.Serialization; - -namespace Microsoft.AspNetCore.Mvc.Formatters.Xml -{ - /// - /// Wrapper class for to enable it to be serialized by the xml formatters. - /// - [XmlRoot(nameof(ValidationProblemDetails))] - [Obsolete("This type is deprecated and will be removed in a future version")] - public class ValidationProblemDetails21Wrapper : ProblemDetails21Wrapper, IUnwrappable - { - private static readonly string ErrorKey = "MVC-Errors"; - - /// - /// Initializes a new instance of . - /// - public ValidationProblemDetails21Wrapper() - : this(new ValidationProblemDetails()) - { - } - - /// - /// Initializes a new instance of for the specified - /// . - /// - /// The . - public ValidationProblemDetails21Wrapper(ValidationProblemDetails problemDetails) - : base(problemDetails) - { - ProblemDetails = problemDetails; - } - - internal new ValidationProblemDetails ProblemDetails { get; } - - /// - protected override void ReadValue(XmlReader reader, string name) - { - if (reader == null) - { - throw new ArgumentNullException(nameof(reader)); - } - - if (string.Equals(name, ErrorKey, StringComparison.Ordinal)) - { - reader.Read(); - ReadErrorProperty(reader); - } - else - { - base.ReadValue(reader, name); - } - } - - private void ReadErrorProperty(XmlReader reader) - { - if (reader.IsEmptyElement) - { - return; - } - - while (reader.NodeType != XmlNodeType.EndElement) - { - var key = XmlConvert.DecodeName(reader.LocalName); - var value = reader.ReadInnerXml(); - if (string.Equals(EmptyKey, key, StringComparison.Ordinal)) - { - key = string.Empty; - } - - ProblemDetails.Errors.Add(key, new[] { value }); - reader.MoveToContent(); - } - } - - /// - public override void WriteXml(XmlWriter writer) - { - if (writer == null) - { - throw new ArgumentNullException(nameof(writer)); - } - - base.WriteXml(writer); - - if (ProblemDetails.Errors.Count == 0) - { - return; - } - - writer.WriteStartElement(XmlConvert.EncodeLocalName(ErrorKey)); - - foreach (var keyValuePair in ProblemDetails.Errors) - { - var key = keyValuePair.Key; - var value = keyValuePair.Value; - if (string.IsNullOrEmpty(key)) - { - key = EmptyKey; - } - - writer.WriteStartElement(XmlConvert.EncodeLocalName(key)); - if (value != null) - { - writer.WriteValue(value); - } - - writer.WriteEndElement(); - } - writer.WriteEndElement(); - } - - object IUnwrappable.Unwrap(Type declaredType) - { - if (declaredType == null) - { - throw new ArgumentNullException(nameof(declaredType)); - } - - return ProblemDetails; - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerInputFormatter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerInputFormatter.cs index ac1b2a085e..a849abd151 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerInputFormatter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerInputFormatter.cs @@ -26,16 +26,17 @@ namespace Microsoft.AspNetCore.Mvc.Formatters { private readonly ConcurrentDictionary _serializerCache = new ConcurrentDictionary(); private readonly XmlDictionaryReaderQuotas _readerQuotas = FormattingUtilities.GetDefaultXmlReaderQuotas(); - private readonly bool _suppressInputFormatterBuffering; private readonly MvcOptions _options; private DataContractSerializerSettings _serializerSettings; /// /// Initializes a new instance of . /// - [Obsolete("This constructor is obsolete and will be removed in a future version.")] - public XmlDataContractSerializerInputFormatter() + /// The . + public XmlDataContractSerializerInputFormatter(MvcOptions options) { + _options = options; + SupportedEncodings.Add(UTF8EncodingWithoutBOM); SupportedEncodings.Add(UTF16EncodingLittleEndian); @@ -51,29 +52,6 @@ namespace Microsoft.AspNetCore.Mvc.Formatters }; } - /// - /// Initializes a new instance of . - /// - /// Flag to buffer entire request body before deserializing it. - [Obsolete("This constructor is obsolete and will be removed in a future version.")] - public XmlDataContractSerializerInputFormatter(bool suppressInputFormatterBuffering) - : this() - { - _suppressInputFormatterBuffering = suppressInputFormatterBuffering; - } - - /// - /// Initializes a new instance of . - /// - /// The . - public XmlDataContractSerializerInputFormatter(MvcOptions options) -#pragma warning disable CS0618 - : this() -#pragma warning restore CS0618 - { - _options = options; - } - /// /// Gets the list of to /// provide the wrapping type for de-serialization. @@ -141,9 +119,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters var request = context.HttpContext.Request; - var suppressInputFormatterBuffering = _options?.SuppressInputFormatterBuffering ?? _suppressInputFormatterBuffering; - - if (!request.Body.CanSeek && !suppressInputFormatterBuffering) + if (!request.Body.CanSeek && !_options.SuppressInputFormatterBuffering) { // XmlDataContractSerializer does synchronous reads. In order to avoid blocking on the stream, we asynchronously // read everything into a buffer, and then seek back to the beginning. diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerInputFormatter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerInputFormatter.cs index 336cea13a7..3dad1a7305 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerInputFormatter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerInputFormatter.cs @@ -26,15 +26,16 @@ namespace Microsoft.AspNetCore.Mvc.Formatters { private readonly ConcurrentDictionary _serializerCache = new ConcurrentDictionary(); private readonly XmlDictionaryReaderQuotas _readerQuotas = FormattingUtilities.GetDefaultXmlReaderQuotas(); - private readonly bool _suppressInputFormatterBuffering; private readonly MvcOptions _options; /// - /// Initializes a new instance of XmlSerializerInputFormatter. + /// Initializes a new instance of . /// - [Obsolete("This constructor is obsolete and will be removed in a future version.")] - public XmlSerializerInputFormatter() + /// The . + public XmlSerializerInputFormatter(MvcOptions options) { + _options = options; + SupportedEncodings.Add(UTF8EncodingWithoutBOM); SupportedEncodings.Add(UTF16EncodingLittleEndian); @@ -48,29 +49,6 @@ namespace Microsoft.AspNetCore.Mvc.Formatters }; } - /// - /// Initializes a new instance of . - /// - /// Flag to buffer entire request body before deserializing it. - [Obsolete("This constructor is obsolete and will be removed in a future version.")] - public XmlSerializerInputFormatter(bool suppressInputFormatterBuffering) - : this() - { - _suppressInputFormatterBuffering = suppressInputFormatterBuffering; - } - - /// - /// Initializes a new instance of . - /// - /// The . - public XmlSerializerInputFormatter(MvcOptions options) -#pragma warning disable CS0618 - : this() -#pragma warning restore CS0618 - { - _options = options; - } - /// /// Gets the list of to /// provide the wrapping type for de-serialization. @@ -122,9 +100,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters var request = context.HttpContext.Request; - var suppressInputFormatterBuffering = _options?.SuppressInputFormatterBuffering ?? _suppressInputFormatterBuffering; - - if (!request.Body.CanSeek && !suppressInputFormatterBuffering) + if (!request.Body.CanSeek && !_options.SuppressInputFormatterBuffering) { // XmlSerializer does synchronous reads. In order to avoid blocking on the stream, we asynchronously // read everything into a buffer, and then seek back to the beginning. diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.NewtonsoftJson/NewtonsoftJsonInputFormatter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.NewtonsoftJson/NewtonsoftJsonInputFormatter.cs index b778ae0dda..db1dab6b5a 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.NewtonsoftJson/NewtonsoftJsonInputFormatter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.NewtonsoftJson/NewtonsoftJsonInputFormatter.cs @@ -30,117 +30,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters private readonly MvcOptions _options; private readonly MvcNewtonsoftJsonOptions _jsonOptions; - // These fields are used when one of the legacy constructors is called that doesn't provide the MvcOptions or - // MvcJsonOptions. - private readonly bool _suppressInputFormatterBuffering; - private readonly bool _allowInputFormatterExceptionMessages; - private ObjectPool _jsonSerializerPool; - /// - /// Initializes a new instance of . - /// - /// The . - /// - /// The . Should be either the application-wide settings - /// () or an instance - /// initially returned. - /// - /// The . - /// The . - [Obsolete("This constructor is obsolete and will be removed in a future version.")] - public NewtonsoftJsonInputFormatter( - ILogger logger, - JsonSerializerSettings serializerSettings, - ArrayPool charPool, - ObjectPoolProvider objectPoolProvider) : - this(logger, serializerSettings, charPool, objectPoolProvider, suppressInputFormatterBuffering: false) - { - // This constructor by default buffers the request body as its the most secure setting - } - - /// - /// Initializes a new instance of . - /// - /// The . - /// - /// The . Should be either the application-wide settings - /// () or an instance - /// initially returned. - /// - /// The . - /// The . - /// Flag to buffer entire request body before deserializing it. - [Obsolete("This constructor is obsolete and will be removed in a future version.")] - public NewtonsoftJsonInputFormatter( - ILogger logger, - JsonSerializerSettings serializerSettings, - ArrayPool charPool, - ObjectPoolProvider objectPoolProvider, - bool suppressInputFormatterBuffering) - : this(logger, serializerSettings, charPool, objectPoolProvider, suppressInputFormatterBuffering, allowInputFormatterExceptionMessages: false) - { - // This constructor by default treats JSON deserialization exceptions as unsafe - // because this is the default in 2.0 - } - - /// - /// Initializes a new instance of . - /// - /// The . - /// - /// The . Should be either the application-wide settings - /// () or an instance - /// initially returned. - /// - /// The . - /// The . - /// Flag to buffer entire request body before deserializing it. - /// If , JSON deserialization exception messages will replaced by a generic message in model state. - [Obsolete("This constructor is obsolete and will be removed in a future version.")] - public NewtonsoftJsonInputFormatter( - ILogger logger, - JsonSerializerSettings serializerSettings, - ArrayPool charPool, - ObjectPoolProvider objectPoolProvider, - bool suppressInputFormatterBuffering, - bool allowInputFormatterExceptionMessages) - { - if (logger == null) - { - throw new ArgumentNullException(nameof(logger)); - } - - if (serializerSettings == null) - { - throw new ArgumentNullException(nameof(serializerSettings)); - } - - if (charPool == null) - { - throw new ArgumentNullException(nameof(charPool)); - } - - if (objectPoolProvider == null) - { - throw new ArgumentNullException(nameof(objectPoolProvider)); - } - - _logger = logger; - SerializerSettings = serializerSettings; - _charPool = new JsonArrayPool(charPool); - _objectPoolProvider = objectPoolProvider; - _suppressInputFormatterBuffering = suppressInputFormatterBuffering; - _allowInputFormatterExceptionMessages = allowInputFormatterExceptionMessages; - - SupportedEncodings.Add(UTF8EncodingWithoutBOM); - SupportedEncodings.Add(UTF16EncodingLittleEndian); - - SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationJson); - SupportedMediaTypes.Add(MediaTypeHeaderValues.TextJson); - SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationAnyJsonSyntax); - } - /// /// Initializes a new instance of . /// @@ -236,7 +127,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters var request = context.HttpContext.Request; - var suppressInputFormatterBuffering = _options?.SuppressInputFormatterBuffering ?? _suppressInputFormatterBuffering; + var suppressInputFormatterBuffering = _options.SuppressInputFormatterBuffering; if (!request.Body.CanSeek && !suppressInputFormatterBuffering) { @@ -431,7 +322,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters { // In 2.0 and earlier we always gave a generic error message for errors that come from JSON.NET // We only allow it in 2.1 and newer if the app opts-in. - if (!(_jsonOptions?.AllowInputFormatterExceptionMessages ?? _allowInputFormatterExceptionMessages)) + if (!_jsonOptions.AllowInputFormatterExceptionMessages) { // This app is not opted-in to JSON.NET messages, return the original exception. return exception; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.NewtonsoftJson/NewtonsoftJsonPatchInputFormatter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.NewtonsoftJson/NewtonsoftJsonPatchInputFormatter.cs index 74ba02a1ae..5ac18ed185 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.NewtonsoftJson/NewtonsoftJsonPatchInputFormatter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.NewtonsoftJson/NewtonsoftJsonPatchInputFormatter.cs @@ -19,81 +19,6 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// public class NewtonsoftJsonPatchInputFormatter : NewtonsoftJsonInputFormatter { - /// - /// Initializes a new instance. - /// - /// The . - /// - /// The . Should be either the application-wide settings - /// () or an instance - /// initially returned. - /// - /// The . - /// The . - [Obsolete("This constructor is obsolete and will be removed in a future version.")] - public NewtonsoftJsonPatchInputFormatter( - ILogger logger, - JsonSerializerSettings serializerSettings, - ArrayPool charPool, - ObjectPoolProvider objectPoolProvider) - : this(logger, serializerSettings, charPool, objectPoolProvider, suppressInputFormatterBuffering: false) - { - } - - /// - /// Initializes a new instance. - /// - /// The . - /// - /// The . Should be either the application-wide settings - /// () or an instance - /// initially returned. - /// - /// The . - /// The . - /// Flag to buffer entire request body before deserializing it. - [Obsolete("This constructor is obsolete and will be removed in a future version.")] - public NewtonsoftJsonPatchInputFormatter( - ILogger logger, - JsonSerializerSettings serializerSettings, - ArrayPool charPool, - ObjectPoolProvider objectPoolProvider, - bool suppressInputFormatterBuffering) - : this(logger, serializerSettings, charPool, objectPoolProvider, suppressInputFormatterBuffering, allowInputFormatterExceptionMessages: false) - { - } - - /// - /// Initializes a new instance. - /// - /// The . - /// - /// The . Should be either the application-wide settings - /// () or an instance - /// initially returned. - /// - /// The . - /// The . - /// Flag to buffer entire request body before deserializing it. - /// - /// If , JSON deserialization exception messages will replaced by a generic message in model state. - /// - [Obsolete("This constructor is obsolete and will be removed in a future version.")] - public NewtonsoftJsonPatchInputFormatter( - ILogger logger, - JsonSerializerSettings serializerSettings, - ArrayPool charPool, - ObjectPoolProvider objectPoolProvider, - bool suppressInputFormatterBuffering, - bool allowInputFormatterExceptionMessages) - : base(logger, serializerSettings, charPool, objectPoolProvider, suppressInputFormatterBuffering, allowInputFormatterExceptionMessages) - { - // Clear all values and only include json-patch+json value. - SupportedMediaTypes.Clear(); - - SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationJsonPatch); - } - /// /// Initializes a new instance. /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/ImageTagHelper.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/ImageTagHelper.cs index 97989b7754..2ba6cd719c 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/ImageTagHelper.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/ImageTagHelper.cs @@ -29,25 +29,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers private const string AppendVersionAttributeName = "asp-append-version"; private const string SrcAttributeName = "src"; - /// - /// Creates a new . - /// - /// The . - /// The . - /// The to use. - /// The . - [Obsolete("This constructor is obsolete and will be removed in a future version.")] - public ImageTagHelper( - IHostingEnvironment hostingEnvironment, - IMemoryCache cache, - HtmlEncoder htmlEncoder, - IUrlHelperFactory urlHelperFactory) - : base(urlHelperFactory, htmlEncoder) - { - HostingEnvironment = hostingEnvironment; - Cache = cache; - } - /// /// Creates a new . /// @@ -58,7 +39,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers /// The . // Decorated with ActivatorUtilitiesConstructor since we want to influence tag helper activation // to use this constructor in the default case. - [ActivatorUtilitiesConstructor] public ImageTagHelper( IHostingEnvironment hostingEnvironment, TagHelperMemoryCacheProvider cacheProvider, diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/LinkTagHelper.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/LinkTagHelper.cs index 34d4ef1fa1..0e56388796 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/LinkTagHelper.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/LinkTagHelper.cs @@ -95,28 +95,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers }; private StringWriter _stringWriter; - /// - /// Creates a new . - /// - /// The . - /// The . - /// The . - /// The . - /// The . - [Obsolete("This constructor is obsolete and will be removed in a future version.")] - public LinkTagHelper( - IHostingEnvironment hostingEnvironment, - IMemoryCache cache, - HtmlEncoder htmlEncoder, - JavaScriptEncoder javaScriptEncoder, - IUrlHelperFactory urlHelperFactory) - : base(urlHelperFactory, htmlEncoder) - { - HostingEnvironment = hostingEnvironment; - JavaScriptEncoder = javaScriptEncoder; - Cache = cache; - } - /// /// Creates a new . /// @@ -128,7 +106,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers /// The . // Decorated with ActivatorUtilitiesConstructor since we want to influence tag helper activation // to use this constructor in the default case. - [ActivatorUtilitiesConstructor] public LinkTagHelper( IHostingEnvironment hostingEnvironment, TagHelperMemoryCacheProvider cacheProvider, diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/ScriptTagHelper.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/ScriptTagHelper.cs index 5720d7cd62..e3f425ee6c 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/ScriptTagHelper.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/ScriptTagHelper.cs @@ -78,28 +78,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers }), }; - /// - /// Creates a new . - /// - /// The . - /// The . - /// The . - /// The . - /// The . - [Obsolete("This constructor is obsolete and will be removed in a future version.")] - public ScriptTagHelper( - IHostingEnvironment hostingEnvironment, - IMemoryCache cache, - HtmlEncoder htmlEncoder, - JavaScriptEncoder javaScriptEncoder, - IUrlHelperFactory urlHelperFactory) - : base(urlHelperFactory, htmlEncoder) - { - HostingEnvironment = hostingEnvironment; - Cache = cache; - JavaScriptEncoder = javaScriptEncoder; - } - /// /// Creates a new . /// @@ -111,7 +89,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers /// The . // Decorated with ActivatorUtilitiesConstructor since we want to influence tag helper activation // to use this constructor in the default case. - [ActivatorUtilitiesConstructor] public ScriptTagHelper( IHostingEnvironment hostingEnvironment, TagHelperMemoryCacheProvider cacheProvider, diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.ViewFeatures/CookieTempDataProviderOptions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.ViewFeatures/CookieTempDataProviderOptions.cs index 58ee79d044..952a0db75d 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.ViewFeatures/CookieTempDataProviderOptions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.ViewFeatures/CookieTempDataProviderOptions.cs @@ -54,42 +54,5 @@ namespace Microsoft.AspNetCore.Mvc get => _cookieBuilder; set => _cookieBuilder = value ?? throw new ArgumentNullException(nameof(value)); } - - #region Obsolete API - /// - /// - /// This property is obsolete and will be removed in a future version. The recommended alternative is on . - /// - /// - /// The path set on the cookie. If set to null, the "path" attribute on the cookie is set to the current - /// request's value. If the value of is - /// null or empty, then the "path" attribute is set to the value of . - /// - /// - [Obsolete("This property is obsolete and will be removed in a future version. The recommended alternative is " + nameof(Cookie) + "." + nameof(CookieBuilder.Path) + ".")] - public string Path { get => Cookie.Path; set => Cookie.Path = value; } - - /// - /// - /// This property is obsolete and will be removed in a future version. The recommended alternative is on . - /// - /// - /// The domain set on a cookie. Defaults to null. - /// - /// - [Obsolete("This property is obsolete and will be removed in a future version. The recommended alternative is " + nameof(Cookie) + "." + nameof(CookieBuilder.Domain) + ".")] - public string Domain { get => Cookie.Domain; set => Cookie.Domain = value; } - - /// - /// - /// This property is obsolete and will be removed in a future version. The recommended alternative is on . - /// - /// - /// The name of the cookie which stores TempData. Defaults to . - /// - /// - [Obsolete("This property is obsolete and will be removed in a future version. The recommended alternative is " + nameof(Cookie) + "." + nameof(CookieBuilder.Name) + ".")] - public string CookieName { get; set; } = CookieTempDataProvider.CookieName; - #endregion } } diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/HeaderModelBinderTests.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/HeaderModelBinderTests.cs index 171f9dac73..42e42846df 100644 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/HeaderModelBinderTests.cs +++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/HeaderModelBinderTests.cs @@ -18,28 +18,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { public class HeaderModelBinderTests { - public static TheoryData HeaderModelBinderWithoutInnerBinderData - { - get - { - var data = new TheoryData - { -#pragma warning disable CS0618 - new HeaderModelBinder(), -#pragma warning restore CS0618 - new HeaderModelBinder(NullLoggerFactory.Instance), - }; - - return data; - } - } - - [Theory] - [MemberData(nameof(HeaderModelBinderWithoutInnerBinderData))] - public async Task HeaderBinder_BindsHeaders_ToStringCollection_WithoutInnerModelBinder( - HeaderModelBinder binder) + [Fact] + public async Task HeaderBinder_BindsHeaders_ToStringCollection_WithoutInnerModelBinder() { // Arrange + var binder = new HeaderModelBinder(NullLoggerFactory.Instance); var type = typeof(string[]); var header = "Accept"; var headerValue = "application/json,text/json"; @@ -57,9 +40,8 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders Assert.Equal(headerValue.Split(','), bindingContext.Result.Model); } - [Theory] - [MemberData(nameof(HeaderModelBinderWithoutInnerBinderData))] - public async Task HeaderBinder_BindsHeaders_ToStringType_WithoutInnerModelBinder(HeaderModelBinder binder) + [Fact] + public async Task HeaderBinder_BindsHeaders_ToStringType_WithoutInnerModelBinder() { // Arrange var type = typeof(string); @@ -67,6 +49,8 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var headerValue = "UnitTest"; var bindingContext = CreateContext(type); + var binder = new HeaderModelBinder(NullLoggerFactory.Instance); + bindingContext.FieldName = header; bindingContext.HttpContext.Request.Headers.Add(header, new[] { headerValue }); @@ -91,9 +75,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders // Arrange var header = "Accept"; var headerValue = "application/json,text/json"; -#pragma warning disable CS0618 - var binder = new HeaderModelBinder(); -#pragma warning restore CS0618 + var binder = new HeaderModelBinder(NullLoggerFactory.Instance); var bindingContext = CreateContext(destinationType); bindingContext.FieldName = header; diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/ParameterBinderTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/ParameterBinderTest.cs index ac197da2d1..8952d61a1d 100644 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/ParameterBinderTest.cs +++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/ParameterBinderTest.cs @@ -56,128 +56,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding } } - [Theory] - [MemberData(nameof(BindModelAsyncData))] - public async Task ObsoleteBindModelAsync_PassesExpectedBindingInfoAndMetadata_IfPrefixDoesNotMatch( - BindingInfo parameterBindingInfo, - string metadataBinderModelName, - string parameterName, - string expectedModelName) - { - // Arrange - var binderExecuted = false; - var metadataProvider = new TestModelMetadataProvider(); - metadataProvider.ForType().BindingDetails(binding => - { - binding.BinderModelName = metadataBinderModelName; - }); - - var metadata = metadataProvider.GetMetadataForType(typeof(Person)); - var modelBinder = new Mock(); - modelBinder - .Setup(b => b.BindModelAsync(It.IsAny())) - .Callback((ModelBindingContext context) => - { - Assert.Equal(expectedModelName, context.ModelName, StringComparer.Ordinal); - }) - .Returns(Task.CompletedTask); - - var parameterDescriptor = new ParameterDescriptor - { - BindingInfo = parameterBindingInfo, - Name = parameterName, - ParameterType = typeof(Person), - }; - - var factory = new Mock(MockBehavior.Strict); - factory - .Setup(f => f.CreateBinder(It.IsAny())) - .Callback((ModelBinderFactoryContext context) => - { - binderExecuted = true; - // Confirm expected data is passed through to ModelBindingFactory. - Assert.Same(parameterDescriptor.BindingInfo, context.BindingInfo); - Assert.Same(parameterDescriptor, context.CacheToken); - Assert.Equal(metadata, context.Metadata); - }) - .Returns(modelBinder.Object); - - var parameterBinder = new ParameterBinder( - metadataProvider, - factory.Object, - Mock.Of(), - _optionsAccessor, - NullLoggerFactory.Instance); - - var controllerContext = GetControllerContext(); - - // Act & Assert -#pragma warning disable CS0618 // Type or member is obsolete - await parameterBinder.BindModelAsync(controllerContext, new SimpleValueProvider(), parameterDescriptor); -#pragma warning restore CS0618 // Type or member is obsolete - Assert.True(binderExecuted); - - } - - [Fact] - public async Task ObsoleteBindModelAsync_PassesExpectedBindingInfoAndMetadata_IfPrefixMatches() - { - // Arrange - var expectedModelName = "expectedName"; - var binderExecuted = false; - - var metadataProvider = new TestModelMetadataProvider(); - var metadata = metadataProvider.GetMetadataForType(typeof(Person)); - var modelBinder = new Mock(); - modelBinder - .Setup(b => b.BindModelAsync(It.IsAny())) - .Callback((ModelBindingContext context) => - { - Assert.Equal(expectedModelName, context.ModelName, StringComparer.Ordinal); - }) - .Returns(Task.CompletedTask); - - var parameterDescriptor = new ParameterDescriptor - { - Name = expectedModelName, - ParameterType = typeof(Person), - }; - - var factory = new Mock(MockBehavior.Strict); - factory - .Setup(f => f.CreateBinder(It.IsAny())) - .Callback((ModelBinderFactoryContext context) => - { - binderExecuted = true; - // Confirm expected data is passed through to ModelBindingFactory. - Assert.Null(context.BindingInfo); - Assert.Same(parameterDescriptor, context.CacheToken); - Assert.Equal(metadata, context.Metadata); - }) - .Returns(modelBinder.Object); - - var argumentBinder = new ParameterBinder( - metadataProvider, - factory.Object, - Mock.Of(), - _optionsAccessor, - NullLoggerFactory.Instance); - - var valueProvider = new SimpleValueProvider - { - { expectedModelName, new object() }, - }; - var valueProviderFactory = new SimpleValueProviderFactory(valueProvider); - - var controllerContext = GetControllerContext(); - - // Act & Assert -#pragma warning disable CS0618 // Type or member is obsolete - await argumentBinder.BindModelAsync(controllerContext, valueProvider, parameterDescriptor); -#pragma warning restore CS0618 // Type or member is obsolete - Assert.True(binderExecuted); - } - [Fact] public async Task BindModelAsync_EnforcesTopLevelBindRequired() { @@ -918,12 +796,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding .Returns(modelMetadata); var mockModelBinderFactory = new Mock(MockBehavior.Strict); -#pragma warning disable CS0618 // Type or member is obsolete return new ParameterBinder( mockModelMetadataProvider.Object, mockModelBinderFactory.Object, - validator); -#pragma warning restore CS0618 // Type or member is obsolete + validator, + _optionsAccessor, + NullLoggerFactory.Instance); } private static IValueProvider CreateMockValueProvider() diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Core.Test/Routing/KnownRouteValueConstraintTests.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Core.Test/Routing/KnownRouteValueConstraintTests.cs index 92bd76ae02..a28641f8b5 100644 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Core.Test/Routing/KnownRouteValueConstraintTests.cs +++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Core.Test/Routing/KnownRouteValueConstraintTests.cs @@ -17,10 +17,6 @@ namespace Microsoft.AspNetCore.Mvc.Routing { public class KnownRouteValueConstraintTests { -#pragma warning disable CS0618 // Type or member is obsolete - private readonly IRouteConstraint _constraint = new KnownRouteValueConstraint(); -#pragma warning restore CS0618 // Type or member is obsolete - [Fact] public void ResolveFromServices_InjectsServiceProvider_HttpContextNotNeeded() { @@ -72,11 +68,13 @@ namespace Microsoft.AspNetCore.Mvc.Routing { // Arrange var values = new RouteValueDictionary(); - var httpContext = GetHttpContext(new ActionDescriptor()); + var httpContext = GetHttpContext(); var route = Mock.Of(); + var descriptorCollectionProvider = CreateActionDescriptorCollectionProvider(new ActionDescriptor()); + var constraint = new KnownRouteValueConstraint(descriptorCollectionProvider); // Act - var match = _constraint.Match(httpContext, route, keyName, values, direction); + var match = constraint.Match(httpContext, route, keyName, values, direction); // Assert Assert.False(match); @@ -98,7 +96,9 @@ namespace Microsoft.AspNetCore.Mvc.Routing "testController", "testAction"); actionDescriptor.RouteValues.Add("randomKey", "testRandom"); - var httpContext = GetHttpContext(actionDescriptor); + var descriptorCollectionProvider = CreateActionDescriptorCollectionProvider(actionDescriptor); + + var httpContext = GetHttpContext(); var route = Mock.Of(); var values = new RouteValueDictionary() { @@ -107,9 +107,10 @@ namespace Microsoft.AspNetCore.Mvc.Routing { "action", "testAction" }, { "randomKey", "testRandom" } }; + var constraint = new KnownRouteValueConstraint(descriptorCollectionProvider); // Act - var match = _constraint.Match(httpContext, route, keyName, values, direction); + var match = constraint.Match(httpContext, route, keyName, values, direction); // Assert Assert.True(match); @@ -132,7 +133,9 @@ namespace Microsoft.AspNetCore.Mvc.Routing "testController", "testAction"); actionDescriptor.RouteValues.Add("randomKey", "testRandom"); - var httpContext = GetHttpContext(actionDescriptor); + var descriptorCollectionProvider = CreateActionDescriptorCollectionProvider(actionDescriptor); + + var httpContext = GetHttpContext(); var route = Mock.Of(); var values = new RouteValueDictionary() { @@ -142,8 +145,10 @@ namespace Microsoft.AspNetCore.Mvc.Routing { "randomKey", "invalidTestRandom" } }; + var constraint = new KnownRouteValueConstraint(descriptorCollectionProvider); + // Act - var match = _constraint.Match(httpContext, route, keyName, values, direction); + var match = constraint.Match(httpContext, route, keyName, values, direction); // Assert Assert.False(match); @@ -157,15 +162,18 @@ namespace Microsoft.AspNetCore.Mvc.Routing var actionDescriptor = CreateActionDescriptor("testArea", controller: null, action: null); - var httpContext = GetHttpContext(actionDescriptor); + var descriptorCollectionProvider = CreateActionDescriptorCollectionProvider(actionDescriptor); + + var httpContext = GetHttpContext(); var route = Mock.Of(); var values = new RouteValueDictionary() { { "area", 12 }, }; + var constraint = new KnownRouteValueConstraint(descriptorCollectionProvider); // Act - var match = _constraint.Match(httpContext, route, "area", values, direction); + var match = constraint.Match(httpContext, route, "area", values, direction); // Assert Assert.False(match); @@ -178,15 +186,12 @@ namespace Microsoft.AspNetCore.Mvc.Routing { // Arrange var actionDescriptorCollectionProvider = Mock.Of(); - var httpContext = new Mock(); - httpContext - .Setup(o => o.RequestServices.GetService(typeof(IActionDescriptorCollectionProvider))) - .Returns(actionDescriptorCollectionProvider); + var constraint = new KnownRouteValueConstraint(actionDescriptorCollectionProvider); // Act & Assert var ex = Assert.Throws( - () => _constraint.Match( - httpContext.Object, + () => constraint.Match( + GetHttpContext(), Mock.Of(), "area", new RouteValueDictionary { { "area", "area" } }, @@ -262,19 +267,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing Assert.True(match); } - private static HttpContext GetHttpContext(ActionDescriptor actionDescriptor, bool setupRequestServices = true) - { - var descriptorCollectionProvider = CreateActionDescriptorCollectionProvider(actionDescriptor); - - var context = new Mock(); - if (setupRequestServices) - { - context.Setup(o => o.RequestServices - .GetService(typeof(IActionDescriptorCollectionProvider))) - .Returns(descriptorCollectionProvider); - } - return context.Object; - } + private static HttpContext GetHttpContext() => new DefaultHttpContext(); private static IActionDescriptorCollectionProvider CreateActionDescriptorCollectionProvider(ActionDescriptor actionDescriptor) { diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/DataAnnotationsMetadataProviderTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/DataAnnotationsMetadataProviderTest.cs index 504d15976e..58516c4b6b 100644 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/DataAnnotationsMetadataProviderTest.cs +++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/DataAnnotationsMetadataProviderTest.cs @@ -1351,25 +1351,13 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations useStringLocalizer ? stringLocalizerFactory.Object : null); } - private ModelAttributes GetModelAttributes(IEnumerable typeAttributes) - { -#pragma warning disable CS0618 // Type or member is obsolete - var modelAttributes = new ModelAttributes(typeAttributes); -#pragma warning restore CS0618 // Type or member is obsolete - - return modelAttributes; - } + private ModelAttributes GetModelAttributes(IEnumerable typeAttributes) + => new ModelAttributes(typeAttributes, Array.Empty(), Array.Empty()); private ModelAttributes GetModelAttributes( IEnumerable typeAttributes, - IEnumerable propertyAttributes) - { -#pragma warning disable CS0618 // Type or member is obsolete - var modelAttributes = new ModelAttributes(propertyAttributes, typeAttributes); -#pragma warning restore CS0618 // Type or member is obsolete - - return modelAttributes; - } + IEnumerable propertyAttributes) + => new ModelAttributes(typeAttributes, propertyAttributes, Array.Empty()); private class KVPEnumGroupAndNameComparer : IEqualityComparer> { diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/DataMemberRequiredBindingMetadataProviderTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/DataMemberRequiredBindingMetadataProviderTest.cs index 728e559131..6c04151e41 100644 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/DataMemberRequiredBindingMetadataProviderTest.cs +++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/DataMemberRequiredBindingMetadataProviderTest.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Runtime.Serialization; using Microsoft.AspNetCore.Mvc.ModelBinding; @@ -141,14 +142,8 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations private ModelAttributes GetModelAttributes( IEnumerable typeAttributes, - IEnumerable propertyAttributes) - { -#pragma warning disable CS0618 // Type or member is obsolete - var modelAttributes = new ModelAttributes(propertyAttributes, typeAttributes); -#pragma warning restore CS0618 // Type or member is obsolete - - return modelAttributes; - } + IEnumerable propertyAttributes) + => new ModelAttributes(typeAttributes, propertyAttributes, Array.Empty()); [DataContract] private class ClassWithDataMemberIsRequiredTrue diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/ModelMetadataProviderTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/ModelMetadataProviderTest.cs index f4c1edbd99..fd5a9e75ee 100644 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/ModelMetadataProviderTest.cs +++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/ModelMetadataProviderTest.cs @@ -1066,9 +1066,10 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations { return new DefaultMetadataDetails( key, -#pragma warning disable CS0618 // Type or member is obsolete - new ModelAttributes(_attributes.Concat(entry.ModelAttributes.TypeAttributes).ToArray())); -#pragma warning restore CS0618 // Type or member is obsolete + new ModelAttributes( + _attributes.Concat(entry.ModelAttributes.TypeAttributes).ToArray(), + Array.Empty(), + Array.Empty())); } return entry; @@ -1081,11 +1082,10 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations { return new DefaultMetadataDetails( e.Key, -#pragma warning disable CS0618 // Type or member is obsolete new ModelAttributes( + e.ModelAttributes.TypeAttributes, _attributes.Concat(e.ModelAttributes.PropertyAttributes), - e.ModelAttributes.TypeAttributes)); -#pragma warning restore CS0618 // Type or member is obsolete + Array.Empty())); }) .ToArray(); } diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/ProblemDetails21WrapperTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/ProblemDetails21WrapperTest.cs deleted file mode 100644 index 933da23704..0000000000 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/ProblemDetails21WrapperTest.cs +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.IO; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Xml; -using Xunit; - -namespace Microsoft.AspNetCore.Mvc.Formatters.Xml -{ -#pragma warning disable CS0618 // Type or member is obsolete - public class ProblemDetails21WrapperTest - { - [Fact] - public void ReadXml_ReadsProblemDetailsXml() - { - // Arrange - var xml = "" + - "" + - "Some title" + - "403" + - "Some instance" + - "Test Value 1" + - "<_x005B_key2_x005D_>Test Value 2" + - "Test Value 3" + - ""; - var serializer = new DataContractSerializer(typeof(ProblemDetails21Wrapper)); - - // Act - var value = serializer.ReadObject( - new MemoryStream(Encoding.UTF8.GetBytes(xml))); - - // Assert - var problemDetails = Assert.IsType(value).ProblemDetails; - Assert.Equal("Some title", problemDetails.Title); - Assert.Equal("Some instance", problemDetails.Instance); - Assert.Equal(403, problemDetails.Status); - - Assert.Collection( - problemDetails.Extensions.OrderBy(kvp => kvp.Key), - kvp => - { - Assert.Empty(kvp.Key); - Assert.Equal("Test Value 3", kvp.Value); - }, - kvp => - { - Assert.Equal("[key2]", kvp.Key); - Assert.Equal("Test Value 2", kvp.Value); - }, - kvp => - { - Assert.Equal("key1", kvp.Key); - Assert.Equal("Test Value 1", kvp.Value); - }); - } - - [Fact] - public void WriteXml_WritesValidXml() - { - // Arrange - var problemDetails = new ProblemDetails - { - Title = "Some title", - Detail = "Some detail", - Extensions = - { - ["key1"] = "Test Value 1", - ["[Key2]"] = "Test Value 2", - [""] = "Test Value 3", - }, - }; - - var wrapper = new ProblemDetails21Wrapper(problemDetails); - var outputStream = new MemoryStream(); - var expectedContent = "" + - "" + - "Some detail" + - "Some title" + - "Test Value 1" + - "<_x005B_Key2_x005D_>Test Value 2" + - "Test Value 3" + - ""; - - // Act - using (var xmlWriter = XmlWriter.Create(outputStream)) - { - var dataContractSerializer = new DataContractSerializer(wrapper.GetType()); - dataContractSerializer.WriteObject(xmlWriter, wrapper); - } - outputStream.Position = 0; - var res = new StreamReader(outputStream, Encoding.UTF8).ReadToEnd(); - - // Assert - Assert.Equal(expectedContent, res); - } - } -#pragma warning restore CS0618 // Type or member is obsolete - -} diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/ValidationProblemDetails21WrapperTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/ValidationProblemDetails21WrapperTest.cs deleted file mode 100644 index 49b41afaf4..0000000000 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/ValidationProblemDetails21WrapperTest.cs +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.IO; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Xml; -using Xunit; - -namespace Microsoft.AspNetCore.Mvc.Formatters.Xml -{ -#pragma warning disable CS0618 // Type or member is obsolete - public class ValidationProblemDetails21WrapperTest - { - [Fact] - public void ReadXml_ReadsValidationProblemDetailsXml() - { - // Arrange - var xml = "" + - "" + - "Some title" + - "400" + - "Some instance" + - "Test Value 1" + - "<_x005B_key2_x005D_>Test Value 2" + - "" + - "Test error 1 Test error 2" + - "<_x005B_error2_x005D_>Test error 3" + - "Test error 4" + - "" + - ""; - var serializer = new DataContractSerializer(typeof(ValidationProblemDetails21Wrapper)); - - // Act - var value = serializer.ReadObject( - new MemoryStream(Encoding.UTF8.GetBytes(xml))); - - // Assert - var problemDetails = Assert.IsType(value).ProblemDetails; - Assert.Equal("Some title", problemDetails.Title); - Assert.Equal("Some instance", problemDetails.Instance); - Assert.Equal(400, problemDetails.Status); - - Assert.Collection( - problemDetails.Extensions.OrderBy(kvp => kvp.Key), - kvp => - { - Assert.Equal("[key2]", kvp.Key); - Assert.Equal("Test Value 2", kvp.Value); - }, - kvp => - { - Assert.Equal("key1", kvp.Key); - Assert.Equal("Test Value 1", kvp.Value); - }); - - Assert.Collection( - problemDetails.Errors.OrderBy(kvp => kvp.Key), - kvp => - { - Assert.Empty(kvp.Key); - Assert.Equal(new[] { "Test error 4" }, kvp.Value); - }, - kvp => - { - Assert.Equal("[error2]", kvp.Key); - Assert.Equal(new[] { "Test error 3" }, kvp.Value); - }, - kvp => - { - Assert.Equal("error1", kvp.Key); - Assert.Equal(new[] { "Test error 1 Test error 2" }, kvp.Value); - }); - } - - [Fact] - public void ReadXml_ReadsValidationProblemDetailsXml_WithNoErrors() - { - // Arrange - var xml = "" + - "" + - "Some title" + - "400" + - "Some instance" + - "Test Value 1" + - "<_x005B_key2_x005D_>Test Value 2" + - ""; - var serializer = new DataContractSerializer(typeof(ValidationProblemDetails21Wrapper)); - - // Act - var value = serializer.ReadObject( - new MemoryStream(Encoding.UTF8.GetBytes(xml))); - - // Assert - var problemDetails = Assert.IsType(value).ProblemDetails; - Assert.Equal("Some title", problemDetails.Title); - Assert.Equal("Some instance", problemDetails.Instance); - Assert.Equal(400, problemDetails.Status); - - Assert.Collection( - problemDetails.Extensions, - kvp => - { - Assert.Equal("key1", kvp.Key); - Assert.Equal("Test Value 1", kvp.Value); - }, - kvp => - { - Assert.Equal("[key2]", kvp.Key); - Assert.Equal("Test Value 2", kvp.Value); - }); - - Assert.Empty(problemDetails.Errors); - } - - [Fact] - public void ReadXml_ReadsValidationProblemDetailsXml_WithEmptyErrorsElement() - { - // Arrange - var xml = "" + - "" + - "Some title" + - "400" + - "" + - ""; - var serializer = new DataContractSerializer(typeof(ValidationProblemDetails21Wrapper)); - - // Act - var value = serializer.ReadObject( - new MemoryStream(Encoding.UTF8.GetBytes(xml))); - - // Assert - var problemDetails = Assert.IsType(value).ProblemDetails; - Assert.Equal("Some title", problemDetails.Title); - Assert.Equal(400, problemDetails.Status); - Assert.Empty(problemDetails.Errors); - } - - [Fact] - public void WriteXml_WritesValidXml() - { - // Arrange - var problemDetails = new ValidationProblemDetails - { - Title = "Some title", - Detail = "Some detail", - Extensions = - { - ["key1"] = "Test Value 1", - ["[Key2]"] = "Test Value 2" - }, - Errors = - { - { "error1", new[] {"Test error 1", "Test error 2" } }, - { "[error2]", new[] {"Test error 3" } }, - { "", new[] { "Test error 4" } }, - } - }; - - var wrapper = new ValidationProblemDetails21Wrapper(problemDetails); - var outputStream = new MemoryStream(); - var expectedContent = "" + - "" + - "Some detail" + - "Some title" + - "Test Value 1" + - "<_x005B_Key2_x005D_>Test Value 2" + - "" + - "Test error 1 Test error 2" + - "<_x005B_error2_x005D_>Test error 3" + - "Test error 4" + - "" + - ""; - - // Act - using (var xmlWriter = XmlWriter.Create(outputStream)) - { - var dataContractSerializer = new DataContractSerializer(wrapper.GetType()); - dataContractSerializer.WriteObject(xmlWriter, wrapper); - } - outputStream.Position = 0; - var res = new StreamReader(outputStream, Encoding.UTF8).ReadToEnd(); - - // Assert - Assert.Equal(expectedContent, res); - } - - [Fact] - public void WriteXml_WithNoValidationErrors() - { - // Arrange - var problemDetails = new ValidationProblemDetails - { - Title = "Some title", - Detail = "Some detail", - Extensions = - { - ["key1"] = "Test Value 1", - ["[Key2]"] = "Test Value 2" - }, - }; - - var wrapper = new ValidationProblemDetails21Wrapper(problemDetails); - var outputStream = new MemoryStream(); - var expectedContent = "" + - "" + - "Some detail" + - "Some title" + - "Test Value 1" + - "<_x005B_Key2_x005D_>Test Value 2" + - ""; - - // Act - using (var xmlWriter = XmlWriter.Create(outputStream)) - { - var dataContractSerializer = new DataContractSerializer(wrapper.GetType()); - dataContractSerializer.WriteObject(xmlWriter, wrapper); - } - outputStream.Position = 0; - var res = new StreamReader(outputStream, Encoding.UTF8).ReadToEnd(); - - // Assert - Assert.Equal(expectedContent, res); - } - } -#pragma warning restore CS0618 // Type or member is obsolete -} diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlDataContractSerializerInputFormatterTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlDataContractSerializerInputFormatterTest.cs index fdd09e318d..b8359803fc 100644 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlDataContractSerializerInputFormatterTest.cs +++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlDataContractSerializerInputFormatterTest.cs @@ -144,9 +144,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml "" + expectedInt + "" + "" + expectedString + ""; -#pragma warning disable CS0618 - var formatter = new XmlDataContractSerializerInputFormatter(); -#pragma warning restore CS0618 + var formatter = new XmlDataContractSerializerInputFormatter(new MvcOptions()); var contentBytes = Encoding.UTF8.GetBytes(input); var httpContext = new DefaultHttpContext(); @@ -191,9 +189,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml "" + expectedInt + "" + "" + expectedString + ""; -#pragma warning disable CS0618 - var formatter = new XmlDataContractSerializerInputFormatter(suppressInputFormatterBuffering: true); -#pragma warning restore CS0618 + var formatter = new XmlDataContractSerializerInputFormatter(new MvcOptions { SuppressInputFormatterBuffering = true }); var contentBytes = Encoding.UTF8.GetBytes(input); var httpContext = new DefaultHttpContext(); diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlSerializerInputFormatterTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlSerializerInputFormatterTest.cs index c1bf95ba46..172b49ce67 100644 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlSerializerInputFormatterTest.cs +++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Formatters.Xml.Test/XmlSerializerInputFormatterTest.cs @@ -52,9 +52,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml "" + expectedString + "" + "" + expectedDateTime + ""; -#pragma warning disable CS0618 - var formatter = new XmlSerializerInputFormatter(); -#pragma warning restore CS0618 + var formatter = new XmlSerializerInputFormatter(new MvcOptions()); var contentBytes = Encoding.UTF8.GetBytes(input); var httpContext = new DefaultHttpContext(); @@ -107,9 +105,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml "" + expectedString + "" + "" + expectedDateTime + ""; -#pragma warning disable CS0618 - var formatter = new XmlSerializerInputFormatter(suppressInputFormatterBuffering: true); -#pragma warning restore CS0618 + var formatter = new XmlSerializerInputFormatter(new MvcOptions { SuppressInputFormatterBuffering = true}); var contentBytes = Encoding.UTF8.GetBytes(input); var httpContext = new DefaultHttpContext(); diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.NewtonsoftJson.Test/NewtonsoftJsonInputFormatterTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.NewtonsoftJson.Test/NewtonsoftJsonInputFormatterTest.cs index dce1e939ab..35b2cadebf 100644 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.NewtonsoftJson.Test/NewtonsoftJsonInputFormatterTest.cs +++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.NewtonsoftJson.Test/NewtonsoftJsonInputFormatterTest.cs @@ -27,51 +27,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters private static readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings(); [Fact] - public async Task Version_2_0_Constructor_BuffersRequestBody_ByDefault() - { - // Arrange -#pragma warning disable CS0618 - var formatter = new NewtonsoftJsonInputFormatter( - GetLogger(), - _serializerSettings, - ArrayPool.Shared, - _objectPoolProvider); -#pragma warning restore CS0618 - - var content = "{name: 'Person Name', Age: '30'}"; - var contentBytes = Encoding.UTF8.GetBytes(content); - var httpContext = new DefaultHttpContext(); - httpContext.Features.Set(new TestResponseFeature()); - httpContext.Request.Body = new NonSeekableReadStream(contentBytes); - httpContext.Request.ContentType = "application/json"; - - var formatterContext = CreateInputFormatterContext(typeof(User), httpContext); - - // Act - var result = await formatter.ReadAsync(formatterContext); - - // Assert - Assert.False(result.HasError); - - var userModel = Assert.IsType(result.Model); - Assert.Equal("Person Name", userModel.Name); - Assert.Equal(30, userModel.Age); - - Assert.True(httpContext.Request.Body.CanSeek); - httpContext.Request.Body.Seek(0L, SeekOrigin.Begin); - - result = await formatter.ReadAsync(formatterContext); - - // Assert - Assert.False(result.HasError); - - userModel = Assert.IsType(result.Model); - Assert.Equal("Person Name", userModel.Name); - Assert.Equal(30, userModel.Age); - } - - [Fact] - public async Task Version_2_1_Constructor_BuffersRequestBody_UsingDefaultOptions() + public async Task Constructor_BuffersRequestBody_UsingDefaultOptions() { // Arrange var formatter = new NewtonsoftJsonInputFormatter( @@ -115,47 +71,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters } [Fact] - public async Task Version_2_0_Constructor_SuppressInputFormatterBufferingSetToTrue_DoesNotBufferRequestBody() - { - // Arrange -#pragma warning disable CS0618 - var formatter = new NewtonsoftJsonInputFormatter( - GetLogger(), - _serializerSettings, - ArrayPool.Shared, - _objectPoolProvider, - suppressInputFormatterBuffering: true); -#pragma warning restore CS0618 - - var content = "{name: 'Person Name', Age: '30'}"; - var contentBytes = Encoding.UTF8.GetBytes(content); - var httpContext = new DefaultHttpContext(); - httpContext.Features.Set(new TestResponseFeature()); - httpContext.Request.Body = new NonSeekableReadStream(contentBytes); - httpContext.Request.ContentType = "application/json"; - - var formatterContext = CreateInputFormatterContext(typeof(User), httpContext); - - // Act - var result = await formatter.ReadAsync(formatterContext); - - // Assert - Assert.False(result.HasError); - - var userModel = Assert.IsType(result.Model); - Assert.Equal("Person Name", userModel.Name); - Assert.Equal(30, userModel.Age); - - Assert.False(httpContext.Request.Body.CanSeek); - result = await formatter.ReadAsync(formatterContext); - - // Assert - Assert.False(result.HasError); - Assert.Null(result.Model); - } - - [Fact] - public async Task Version_2_1_Constructor_SuppressInputFormatterBuffering_UsingMvcOptions_DoesNotBufferRequestBody() + public async Task Constructor_SuppressInputFormatterBuffering_UsingMvcOptions_DoesNotBufferRequestBody() { // Arrange var mvcOptions = new MvcOptions() diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.NewtonsoftJson.Test/NewtonsoftJsonPatchInputFormatterTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.NewtonsoftJson.Test/NewtonsoftJsonPatchInputFormatterTest.cs index 0503d093a8..c451729acc 100644 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.NewtonsoftJson.Test/NewtonsoftJsonPatchInputFormatterTest.cs +++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.NewtonsoftJson.Test/NewtonsoftJsonPatchInputFormatterTest.cs @@ -25,52 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters private static readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings(); [Fact] - public async Task Version_2_0_Constructor_BuffersRequestBody_ByDefault() - { - // Arrange -#pragma warning disable CS0618 - var formatter = new NewtonsoftJsonPatchInputFormatter( - GetLogger(), - _serializerSettings, - ArrayPool.Shared, - _objectPoolProvider); -#pragma warning restore CS0618 - - var content = "[{\"op\":\"add\",\"path\":\"Customer/Name\",\"value\":\"John\"}]"; - var contentBytes = Encoding.UTF8.GetBytes(content); - - var httpContext = new DefaultHttpContext(); - httpContext.Features.Set(new TestResponseFeature()); - httpContext.Request.Body = new NonSeekableReadStream(contentBytes); - httpContext.Request.ContentType = "application/json"; - - var formatterContext = CreateInputFormatterContext(typeof(JsonPatchDocument), httpContext); - - // Act - var result = await formatter.ReadAsync(formatterContext); - - // Assert - Assert.False(result.HasError); - var patchDocument = Assert.IsType>(result.Model); - Assert.Equal("add", patchDocument.Operations[0].op); - Assert.Equal("Customer/Name", patchDocument.Operations[0].path); - Assert.Equal("John", patchDocument.Operations[0].value); - - Assert.True(httpContext.Request.Body.CanSeek); - httpContext.Request.Body.Seek(0L, SeekOrigin.Begin); - - result = await formatter.ReadAsync(formatterContext); - - // Assert - Assert.False(result.HasError); - patchDocument = Assert.IsType>(result.Model); - Assert.Equal("add", patchDocument.Operations[0].op); - Assert.Equal("Customer/Name", patchDocument.Operations[0].path); - Assert.Equal("John", patchDocument.Operations[0].value); - } - - [Fact] - public async Task Version_2_1_Constructor_BuffersRequestBody_ByDefault() + public async Task Constructor_BuffersRequestBody_ByDefault() { // Arrange var formatter = new NewtonsoftJsonPatchInputFormatter( @@ -115,49 +70,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters } [Fact] - public async Task Version_2_0_Constructor_SuppressInputFormatterBuffering_DoesNotBufferRequestBody() - { - // Arrange -#pragma warning disable CS0618 - var formatter = new NewtonsoftJsonPatchInputFormatter( - GetLogger(), - _serializerSettings, - ArrayPool.Shared, - _objectPoolProvider, - suppressInputFormatterBuffering: true); -#pragma warning restore CS0618 - - var content = "[{\"op\":\"add\",\"path\":\"Customer/Name\",\"value\":\"John\"}]"; - var contentBytes = Encoding.UTF8.GetBytes(content); - - var httpContext = new DefaultHttpContext(); - httpContext.Features.Set(new TestResponseFeature()); - httpContext.Request.Body = new NonSeekableReadStream(contentBytes); - httpContext.Request.ContentType = "application/json"; - - var context = CreateInputFormatterContext(typeof(JsonPatchDocument), httpContext); - - // Act - var result = await formatter.ReadAsync(context); - - // Assert - Assert.False(result.HasError); - - var patchDocument = Assert.IsType>(result.Model); - Assert.Equal("add", patchDocument.Operations[0].op); - Assert.Equal("Customer/Name", patchDocument.Operations[0].path); - Assert.Equal("John", patchDocument.Operations[0].value); - - Assert.False(httpContext.Request.Body.CanSeek); - result = await formatter.ReadAsync(context); - - // Assert - Assert.False(result.HasError); - Assert.Null(result.Model); - } - - [Fact] - public async Task Version_2_1_Constructor_SuppressInputFormatterBuffering_DoesNotBufferRequestBody() + public async Task Constructor_SuppressInputFormatterBuffering_DoesNotBufferRequestBody() { // Arrange var mvcOptions = new MvcOptions() diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/FormatWeekHelperTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/FormatWeekHelperTest.cs index a2bc939c84..e178839e3c 100644 --- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/FormatWeekHelperTest.cs +++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/FormatWeekHelperTest.cs @@ -25,9 +25,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures var detailsProvider = new DefaultCompositeMetadataDetailsProvider( Enumerable.Empty()); var key = ModelMetadataIdentity.ForType(typeof(DateTime)); -#pragma warning disable CS0618 // Type or member is obsolete - var cache = new DefaultMetadataDetails(key, new ModelAttributes(new object[0])); -#pragma warning restore CS0618 // Type or member is obsolete + var cache = new DefaultMetadataDetails(key, new ModelAttributes( + Array.Empty(), + Array.Empty(), + Array.Empty())); var provider = new EmptyModelMetadataProvider(); var metadata = new DefaultModelMetadata(provider, detailsProvider, cache);