Remove obsolete APIs from MVC (#7444)
* Remove obsolete APIs from MVC Fixes https://github.com/aspnet/AspNetCore/issues/7322
This commit is contained in:
parent
dfddc4e8ff
commit
88ae930fad
|
|
@ -12,20 +12,6 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
|||
/// </summary>
|
||||
public abstract class OutputFormatterCanWriteContext
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// This constructor is obsolete and will be removed in a future version.
|
||||
/// Please use <see cref="OutputFormatterCanWriteContext(Http.HttpContext)"/> instead.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Creates a new <see cref="OutputFormatterCanWriteContext"/>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[Obsolete("This constructor is obsolete and will be removed in a future version. Please use the constructor taking a HttpContext instead.")]
|
||||
protected OutputFormatterCanWriteContext()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="OutputFormatterCanWriteContext"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -29,44 +29,6 @@ namespace Microsoft.AspNetCore.Mvc.ApiExplorer
|
|||
private readonly IInlineConstraintResolver _constraintResolver;
|
||||
private readonly IModelMetadataProvider _modelMetadataProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="DefaultApiDescriptionProvider"/>.
|
||||
/// </summary>
|
||||
/// <param name="optionsAccessor">The accessor for <see cref="MvcOptions"/>.</param>
|
||||
/// <param name="constraintResolver">The <see cref="IInlineConstraintResolver"/> used for resolving inline
|
||||
/// constraints.</param>
|
||||
/// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider"/>.</param>
|
||||
[Obsolete("This constructor is obsolete and will be removed in a future release.")]
|
||||
public DefaultApiDescriptionProvider(
|
||||
IOptions<MvcOptions> optionsAccessor,
|
||||
IInlineConstraintResolver constraintResolver,
|
||||
IModelMetadataProvider modelMetadataProvider)
|
||||
: this(optionsAccessor, constraintResolver, modelMetadataProvider, null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="DefaultApiDescriptionProvider"/>.
|
||||
/// </summary>
|
||||
/// <param name="optionsAccessor">The accessor for <see cref="MvcOptions"/>.</param>
|
||||
/// <param name="constraintResolver">The <see cref="IInlineConstraintResolver"/> used for resolving inline
|
||||
/// constraints.</param>
|
||||
/// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider"/>.</param>
|
||||
/// <param name="mapper">The <see cref="IActionResultTypeMapper"/>.</param>
|
||||
/// <remarks>The <paramref name="mapper"/> parameter is currently ignored.</remarks>
|
||||
[Obsolete("This constructor is obsolete and will be removed in a future release.")]
|
||||
public DefaultApiDescriptionProvider(
|
||||
IOptions<MvcOptions> optionsAccessor,
|
||||
IInlineConstraintResolver constraintResolver,
|
||||
IModelMetadataProvider modelMetadataProvider,
|
||||
IActionResultTypeMapper mapper)
|
||||
{
|
||||
_mvcOptions = optionsAccessor.Value;
|
||||
_constraintResolver = constraintResolver;
|
||||
_modelMetadataProvider = modelMetadataProvider;
|
||||
_responseTypeProvider = new ApiResponseTypeProvider(modelMetadataProvider, mapper, _mvcOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="DefaultApiDescriptionProvider"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -21,16 +21,6 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
|||
private readonly MvcOptions _options;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an instance of <see cref="FormatFilter"/>.
|
||||
/// </summary>
|
||||
/// <param name="options">The <see cref="IOptions{MvcOptions}"/></param>
|
||||
[Obsolete("This constructor is obsolete and will be removed in a future version.")]
|
||||
public FormatFilter(IOptions<MvcOptions> options)
|
||||
: this(options, NullLoggerFactory.Instance)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an instance of <see cref="FormatFilter"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -104,42 +104,5 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
var executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<LocalRedirectResult>>();
|
||||
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<IUrlHelperFactory>();
|
||||
var logger = services.GetRequiredService<ILogger<LocalRedirectResult>>();
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
|||
/// <typeparam name="TElement">Type of elements in the array.</typeparam>
|
||||
public class ArrayModelBinder<TElement> : CollectionModelBinder<TElement>
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>This constructor is obsolete and will be removed in a future version. The recommended alternative
|
||||
/// is the overload that also takes an <see cref="ILoggerFactory"/>.</para>
|
||||
/// <para>Creates a new <see cref="ArrayModelBinder{TElement}"/>.</para>
|
||||
/// </summary>
|
||||
/// <param name="elementBinder">
|
||||
/// The <see cref="IModelBinder"/> for binding <typeparamref name="TElement"/>.
|
||||
/// </param>
|
||||
[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)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ArrayModelBinder{TElement}"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// <para>This constructor is obsolete and will be removed in a future version. The recommended alternative
|
||||
/// is the overload that takes an <see cref="ILoggerFactory"/>.</para>
|
||||
/// <para>Initializes a new instance of <see cref="ByteArrayModelBinder"/>.</para>
|
||||
/// </summary>
|
||||
[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)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="ByteArrayModelBinder"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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<object> _modelCreator;
|
||||
|
||||
/// <summary>
|
||||
/// <para>This constructor is obsolete and will be removed in a future version. The recommended alternative
|
||||
/// is the overload that also takes an <see cref="ILoggerFactory"/>.</para>
|
||||
/// <para>Creates a new <see cref="CollectionModelBinder{TElement}"/>.</para>
|
||||
/// </summary>
|
||||
/// <param name="elementBinder">The <see cref="IModelBinder"/> for binding elements.</param>
|
||||
[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)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="CollectionModelBinder{TElement}"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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<object> _modelCreator;
|
||||
|
||||
/// <summary>
|
||||
/// <para>This constructor is obsolete and will be removed in a future version. The recommended alternative
|
||||
/// is the overload that also takes an <see cref="ILoggerFactory"/>.</para>
|
||||
/// <para>Creates a new <see cref="ComplexTypeModelBinder"/>.</para>
|
||||
/// </summary>
|
||||
/// <param name="propertyBinders">
|
||||
/// The <see cref="IDictionary{TKey, TValue}"/> of binders to use for binding properties.
|
||||
/// </param>
|
||||
[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<ModelMetadata, IModelBinder> propertyBinders)
|
||||
: this(propertyBinders, NullLoggerFactory.Instance)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ComplexTypeModelBinder"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// <para>This constructor is obsolete and will be removed in a future version. The recommended alternative
|
||||
/// is the overload that also takes an <see cref="ILoggerFactory"/>.</para>
|
||||
/// <para>Initializes a new instance of <see cref="DecimalModelBinder"/>.</para>
|
||||
/// </summary>
|
||||
/// <param name="supportedStyles">The <see cref="NumberStyles"/>.</param>
|
||||
[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)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="DecimalModelBinder"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// <para>This constructor is obsolete and will be removed in a future version. The recommended alternative
|
||||
/// is the overload that also takes an <see cref="ILoggerFactory"/>.</para>
|
||||
/// <para>Creates a new <see cref="DictionaryModelBinder{TKey, TValue}"/>.</para>
|
||||
/// </summary>
|
||||
/// <param name="keyBinder">The <see cref="IModelBinder"/> for <typeparamref name="TKey"/>.</param>
|
||||
/// <param name="valueBinder">The <see cref="IModelBinder"/> for <typeparamref name="TValue"/>.</param>
|
||||
[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)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DictionaryModelBinder{TKey, TValue}"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// <para>This constructor is obsolete and will be removed in a future version. The recommended alternative
|
||||
/// is the overload that also takes an <see cref="ILoggerFactory"/>.</para>
|
||||
/// <para>Initializes a new instance of <see cref="DoubleModelBinder"/>.</para>
|
||||
/// </summary>
|
||||
/// <param name="supportedStyles">The <see cref="NumberStyles"/>.</param>
|
||||
[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)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="DoubleModelBinder"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// <para>This constructor is obsolete and will be removed in a future version. The recommended alternative
|
||||
/// is the overload that also takes an <see cref="ILoggerFactory"/>.</para>
|
||||
/// <para>Initializes a new instance of <see cref="FloatModelBinder"/>.</para>
|
||||
/// </summary>
|
||||
/// <param name="supportedStyles">The <see cref="NumberStyles"/>.</param>
|
||||
[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)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="FloatModelBinder"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// <para>This constructor is obsolete and will be removed in a future version. The recommended alternative
|
||||
/// is the overload that takes an <see cref="ILoggerFactory"/>.</para>
|
||||
/// <para>Initializes a new instance of <see cref="FormCollectionModelBinder"/>.</para>
|
||||
/// </summary>
|
||||
[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)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="FormCollectionModelBinder"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// <para>This constructor is obsolete and will be removed in a future version. The recommended alternative
|
||||
/// is the overload that takes an <see cref="ILoggerFactory"/>.</para>
|
||||
/// <para>Initializes a new instance of <see cref="FormFileModelBinder"/>.</para>
|
||||
/// </summary>
|
||||
[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)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="FormFileModelBinder"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// <para>This constructor is obsolete and will be removed in a future version. The recommended alternative
|
||||
/// is the overload that takes an <see cref="ILoggerFactory"/> and an <see cref="IModelBinder"/>.</para>
|
||||
/// <para>Initializes a new instance of <see cref="HeaderModelBinder"/>.</para>
|
||||
/// </summary>
|
||||
[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)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="HeaderModelBinder"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// <para>This constructor is obsolete and will be removed in a future version. The recommended alternative
|
||||
/// is the overload that also takes an <see cref="ILoggerFactory"/>.</para>
|
||||
/// <para>Creates a new <see cref="KeyValuePair{TKey, TValue}"/>.</para>
|
||||
/// </summary>
|
||||
/// <param name="keyBinder">The <see cref="IModelBinder"/> for <typeparamref name="TKey"/>.</param>
|
||||
/// <param name="valueBinder">The <see cref="IModelBinder"/> for <typeparamref name="TValue"/>.</param>
|
||||
[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)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="KeyValuePair{TKey, TValue}"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// <para>This constructor is obsolete and will be removed in a future version. The recommended alternative
|
||||
/// is the overload that also takes an <see cref="ILoggerFactory"/>.</para>
|
||||
/// <para>Initializes a new instance of <see cref="SimpleTypeModelBinder"/>.</para>
|
||||
/// </summary>
|
||||
/// <param name="type">The type to create binder for.</param>
|
||||
[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)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="SimpleTypeModelBinder"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -13,31 +13,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
|
|||
/// </summary>
|
||||
public class ModelAttributes
|
||||
{
|
||||
private static readonly IEnumerable<object> _emptyAttributesCollection = Enumerable.Empty<object>();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ModelAttributes"/> for a <see cref="Type"/>.
|
||||
/// </summary>
|
||||
/// <param name="typeAttributes">The set of attributes for the <see cref="Type"/>.</param>
|
||||
[Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative is " + nameof(ModelAttributes) + "." + nameof(GetAttributesForType) + ".")]
|
||||
public ModelAttributes(IEnumerable<object> typeAttributes)
|
||||
: this(typeAttributes, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ModelAttributes"/> for a property.
|
||||
/// </summary>
|
||||
/// <param name="propertyAttributes">The set of attributes for the property.</param>
|
||||
/// <param name="typeAttributes">
|
||||
/// The set of attributes for the property's <see cref="Type"/>. See <see cref="PropertyInfo.PropertyType"/>.
|
||||
/// </param>
|
||||
[Obsolete("This constructor is obsolete and will be removed in a future version. The recommended alternative is " + nameof(ModelAttributes) + "." + nameof(GetAttributesForProperty) + ".")]
|
||||
public ModelAttributes(IEnumerable<object> propertyAttributes, IEnumerable<object> typeAttributes)
|
||||
: this(typeAttributes, propertyAttributes, null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ModelAttributes"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -27,20 +27,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
|
|||
private readonly ConcurrentDictionary<Key, IModelBinder> _cache;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
/// <summary>
|
||||
/// <para>This constructor is obsolete and will be removed in a future version. The recommended alternative
|
||||
/// is the overload that also takes an <see cref="IServiceProvider"/>.</para>
|
||||
/// <para>Creates a new <see cref="ModelBinderFactory"/>.</para>
|
||||
/// </summary>
|
||||
/// <param name="metadataProvider">The <see cref="IModelMetadataProvider"/>.</param>
|
||||
/// <param name="options">The <see cref="IOptions{TOptions}"/> for <see cref="MvcOptions"/>.</param>
|
||||
[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<MvcOptions> options)
|
||||
: this(metadataProvider, options, GetDefaultServices())
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ModelBinderFactory"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// <para>This constructor is obsolete and will be removed in a future version. The recommended alternative
|
||||
/// is the overload that also takes a <see cref="MvcOptions"/> accessor and an <see cref="ILoggerFactory"/>.
|
||||
/// </para>
|
||||
/// <para>Initializes a new instance of <see cref="ParameterBinder"/>.</para>
|
||||
/// </summary>
|
||||
/// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider"/>.</param>
|
||||
/// <param name="modelBinderFactory">The <see cref="IModelBinderFactory"/>.</param>
|
||||
/// <param name="validator">The <see cref="IObjectModelValidator"/>.</param>
|
||||
[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)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="ParameterBinder"/>.
|
||||
/// </summary>
|
||||
|
|
@ -98,85 +72,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
|
|||
/// </summary>
|
||||
protected ILogger Logger { get; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// This method overload is obsolete and will be removed in a future version. The recommended alternative is
|
||||
/// <see cref="BindModelAsync(ActionContext, IModelBinder, IValueProvider, ParameterDescriptor, ModelMetadata, object)" />.
|
||||
/// </para>
|
||||
/// <para>Initializes and binds a model specified by <paramref name="parameter"/>.</para>
|
||||
/// </summary>
|
||||
/// <param name="actionContext">The <see cref="ActionContext"/>.</param>
|
||||
/// <param name="valueProvider">The <see cref="IValueProvider"/>.</param>
|
||||
/// <param name="parameter">The <see cref="ParameterDescriptor"/></param>
|
||||
/// <returns>The result of model binding.</returns>
|
||||
[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<ModelBindingResult> 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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// This method overload is obsolete and will be removed in a future version. The recommended alternative is
|
||||
/// <see cref="BindModelAsync(ActionContext, IModelBinder, IValueProvider, ParameterDescriptor, ModelMetadata, object)" />.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Binds a model specified by <paramref name="parameter"/> using <paramref name="value"/> as the initial value.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="actionContext">The <see cref="ActionContext"/>.</param>
|
||||
/// <param name="valueProvider">The <see cref="IValueProvider"/>.</param>
|
||||
/// <param name="parameter">The <see cref="ParameterDescriptor"/></param>
|
||||
/// <param name="value">The initial model value.</param>
|
||||
/// <returns>The result of model binding.</returns>
|
||||
[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<ModelBindingResult> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Binds a model specified by <paramref name="parameter"/> using <paramref name="value"/> as the initial value.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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<IActionResultExecutor<RedirectResult>>();
|
||||
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<IUrlHelperFactory>();
|
||||
var logger = services.GetRequiredService<ILogger<RedirectResult>>();
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
@ -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<IActionResultExecutor<RedirectToActionResult>>();
|
||||
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<IUrlHelperFactory>();
|
||||
var logger = services.GetRequiredService<ILogger<RedirectToActionResultExecutor>>();
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<IActionResultExecutor<RedirectToPageResult>>();
|
||||
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<IUrlHelperFactory>();
|
||||
var logger = services.GetRequiredService<ILogger<RedirectToPageResult>>();
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<IActionResultExecutor<RedirectToRouteResult>>();
|
||||
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<IUrlHelperFactory>();
|
||||
var logger = services.GetRequiredService<ILogger<RedirectToRouteResult>>();
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Wrapper class for <see cref="Mvc.ProblemDetails"/> to enable it to be serialized by the xml formatters.
|
||||
/// </summary>
|
||||
[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; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public XmlSchema GetSchema() => null;
|
||||
|
||||
/// <inheritdoc />
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the value for the specified <paramref name="name"/> from the <paramref name="reader"/>.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="XmlReader"/>.</param>
|
||||
/// <param name="name">The name of the node.</param>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Wrapper class for <see cref="ValidationProblemDetails"/> to enable it to be serialized by the xml formatters.
|
||||
/// </summary>
|
||||
[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";
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="ValidationProblemDetailsWrapper"/>.
|
||||
/// </summary>
|
||||
public ValidationProblemDetails21Wrapper()
|
||||
: this(new ValidationProblemDetails())
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="ValidationProblemDetailsWrapper"/> for the specified
|
||||
/// <paramref name="problemDetails"/>.
|
||||
/// </summary>
|
||||
/// <param name="problemDetails">The <see cref="ProblemDetails"/>.</param>
|
||||
public ValidationProblemDetails21Wrapper(ValidationProblemDetails problemDetails)
|
||||
: base(problemDetails)
|
||||
{
|
||||
ProblemDetails = problemDetails;
|
||||
}
|
||||
|
||||
internal new ValidationProblemDetails ProblemDetails { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,16 +26,17 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
|||
{
|
||||
private readonly ConcurrentDictionary<Type, object> _serializerCache = new ConcurrentDictionary<Type, object>();
|
||||
private readonly XmlDictionaryReaderQuotas _readerQuotas = FormattingUtilities.GetDefaultXmlReaderQuotas();
|
||||
private readonly bool _suppressInputFormatterBuffering;
|
||||
private readonly MvcOptions _options;
|
||||
private DataContractSerializerSettings _serializerSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="XmlDataContractSerializerInputFormatter"/>.
|
||||
/// </summary>
|
||||
[Obsolete("This constructor is obsolete and will be removed in a future version.")]
|
||||
public XmlDataContractSerializerInputFormatter()
|
||||
/// <param name="options">The <see cref="MvcOptions"/>.</param>
|
||||
public XmlDataContractSerializerInputFormatter(MvcOptions options)
|
||||
{
|
||||
_options = options;
|
||||
|
||||
SupportedEncodings.Add(UTF8EncodingWithoutBOM);
|
||||
SupportedEncodings.Add(UTF16EncodingLittleEndian);
|
||||
|
||||
|
|
@ -51,29 +52,6 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
|||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="XmlDataContractSerializerInputFormatter"/>.
|
||||
/// </summary>
|
||||
/// <param name="suppressInputFormatterBuffering">Flag to buffer entire request body before deserializing it.</param>
|
||||
[Obsolete("This constructor is obsolete and will be removed in a future version.")]
|
||||
public XmlDataContractSerializerInputFormatter(bool suppressInputFormatterBuffering)
|
||||
: this()
|
||||
{
|
||||
_suppressInputFormatterBuffering = suppressInputFormatterBuffering;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="XmlDataContractSerializerInputFormatter"/>.
|
||||
/// </summary>
|
||||
/// <param name="options">The <see cref="MvcOptions"/>.</param>
|
||||
public XmlDataContractSerializerInputFormatter(MvcOptions options)
|
||||
#pragma warning disable CS0618
|
||||
: this()
|
||||
#pragma warning restore CS0618
|
||||
{
|
||||
_options = options;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of <see cref="IWrapperProviderFactory"/> 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.
|
||||
|
|
|
|||
|
|
@ -26,15 +26,16 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
|||
{
|
||||
private readonly ConcurrentDictionary<Type, object> _serializerCache = new ConcurrentDictionary<Type, object>();
|
||||
private readonly XmlDictionaryReaderQuotas _readerQuotas = FormattingUtilities.GetDefaultXmlReaderQuotas();
|
||||
private readonly bool _suppressInputFormatterBuffering;
|
||||
private readonly MvcOptions _options;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of XmlSerializerInputFormatter.
|
||||
/// Initializes a new instance of <see cref="XmlSerializerInputFormatter"/>.
|
||||
/// </summary>
|
||||
[Obsolete("This constructor is obsolete and will be removed in a future version.")]
|
||||
public XmlSerializerInputFormatter()
|
||||
/// <param name="options">The <see cref="MvcOptions"/>.</param>
|
||||
public XmlSerializerInputFormatter(MvcOptions options)
|
||||
{
|
||||
_options = options;
|
||||
|
||||
SupportedEncodings.Add(UTF8EncodingWithoutBOM);
|
||||
SupportedEncodings.Add(UTF16EncodingLittleEndian);
|
||||
|
||||
|
|
@ -48,29 +49,6 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
|||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="XmlSerializerInputFormatter"/>.
|
||||
/// </summary>
|
||||
/// <param name="suppressInputFormatterBuffering">Flag to buffer entire request body before deserializing it.</param>
|
||||
[Obsolete("This constructor is obsolete and will be removed in a future version.")]
|
||||
public XmlSerializerInputFormatter(bool suppressInputFormatterBuffering)
|
||||
: this()
|
||||
{
|
||||
_suppressInputFormatterBuffering = suppressInputFormatterBuffering;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="XmlSerializerInputFormatter"/>.
|
||||
/// </summary>
|
||||
/// <param name="options">The <see cref="MvcOptions"/>.</param>
|
||||
public XmlSerializerInputFormatter(MvcOptions options)
|
||||
#pragma warning disable CS0618
|
||||
: this()
|
||||
#pragma warning restore CS0618
|
||||
{
|
||||
_options = options;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of <see cref="IWrapperProviderFactory"/> 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.
|
||||
|
|
|
|||
|
|
@ -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<JsonSerializer> _jsonSerializerPool;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="NewtonsoftJsonInputFormatter"/>.
|
||||
/// </summary>
|
||||
/// <param name="logger">The <see cref="ILogger"/>.</param>
|
||||
/// <param name="serializerSettings">
|
||||
/// The <see cref="JsonSerializerSettings"/>. Should be either the application-wide settings
|
||||
/// (<see cref="MvcNewtonsoftJsonOptions.SerializerSettings"/>) or an instance
|
||||
/// <see cref="JsonSerializerSettingsProvider.CreateSerializerSettings"/> initially returned.
|
||||
/// </param>
|
||||
/// <param name="charPool">The <see cref="ArrayPool{Char}"/>.</param>
|
||||
/// <param name="objectPoolProvider">The <see cref="ObjectPoolProvider"/>.</param>
|
||||
[Obsolete("This constructor is obsolete and will be removed in a future version.")]
|
||||
public NewtonsoftJsonInputFormatter(
|
||||
ILogger logger,
|
||||
JsonSerializerSettings serializerSettings,
|
||||
ArrayPool<char> charPool,
|
||||
ObjectPoolProvider objectPoolProvider) :
|
||||
this(logger, serializerSettings, charPool, objectPoolProvider, suppressInputFormatterBuffering: false)
|
||||
{
|
||||
// This constructor by default buffers the request body as its the most secure setting
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="NewtonsoftJsonInputFormatter"/>.
|
||||
/// </summary>
|
||||
/// <param name="logger">The <see cref="ILogger"/>.</param>
|
||||
/// <param name="serializerSettings">
|
||||
/// The <see cref="JsonSerializerSettings"/>. Should be either the application-wide settings
|
||||
/// (<see cref="MvcNewtonsoftJsonOptions.SerializerSettings"/>) or an instance
|
||||
/// <see cref="JsonSerializerSettingsProvider.CreateSerializerSettings"/> initially returned.
|
||||
/// </param>
|
||||
/// <param name="charPool">The <see cref="ArrayPool{Char}"/>.</param>
|
||||
/// <param name="objectPoolProvider">The <see cref="ObjectPoolProvider"/>.</param>
|
||||
/// <param name="suppressInputFormatterBuffering">Flag to buffer entire request body before deserializing it.</param>
|
||||
[Obsolete("This constructor is obsolete and will be removed in a future version.")]
|
||||
public NewtonsoftJsonInputFormatter(
|
||||
ILogger logger,
|
||||
JsonSerializerSettings serializerSettings,
|
||||
ArrayPool<char> 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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="NewtonsoftJsonInputFormatter"/>.
|
||||
/// </summary>
|
||||
/// <param name="logger">The <see cref="ILogger"/>.</param>
|
||||
/// <param name="serializerSettings">
|
||||
/// The <see cref="JsonSerializerSettings"/>. Should be either the application-wide settings
|
||||
/// (<see cref="MvcNewtonsoftJsonOptions.SerializerSettings"/>) or an instance
|
||||
/// <see cref="JsonSerializerSettingsProvider.CreateSerializerSettings"/> initially returned.
|
||||
/// </param>
|
||||
/// <param name="charPool">The <see cref="ArrayPool{Char}"/>.</param>
|
||||
/// <param name="objectPoolProvider">The <see cref="ObjectPoolProvider"/>.</param>
|
||||
/// <param name="suppressInputFormatterBuffering">Flag to buffer entire request body before deserializing it.</param>
|
||||
/// <param name="allowInputFormatterExceptionMessages">If <see langword="true"/>, JSON deserialization exception messages will replaced by a generic message in model state.</param>
|
||||
[Obsolete("This constructor is obsolete and will be removed in a future version.")]
|
||||
public NewtonsoftJsonInputFormatter(
|
||||
ILogger logger,
|
||||
JsonSerializerSettings serializerSettings,
|
||||
ArrayPool<char> 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<char>(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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="NewtonsoftJsonInputFormatter"/>.
|
||||
/// </summary>
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -19,81 +19,6 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
|||
/// </summary>
|
||||
public class NewtonsoftJsonPatchInputFormatter : NewtonsoftJsonInputFormatter
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="NewtonsoftJsonPatchInputFormatter"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="logger">The <see cref="ILogger"/>.</param>
|
||||
/// <param name="serializerSettings">
|
||||
/// The <see cref="JsonSerializerSettings"/>. Should be either the application-wide settings
|
||||
/// (<see cref="MvcNewtonsoftJsonOptions.SerializerSettings"/>) or an instance
|
||||
/// <see cref="JsonSerializerSettingsProvider.CreateSerializerSettings"/> initially returned.
|
||||
/// </param>
|
||||
/// <param name="charPool">The <see cref="ArrayPool{Char}"/>.</param>
|
||||
/// <param name="objectPoolProvider">The <see cref="ObjectPoolProvider"/>.</param>
|
||||
[Obsolete("This constructor is obsolete and will be removed in a future version.")]
|
||||
public NewtonsoftJsonPatchInputFormatter(
|
||||
ILogger logger,
|
||||
JsonSerializerSettings serializerSettings,
|
||||
ArrayPool<char> charPool,
|
||||
ObjectPoolProvider objectPoolProvider)
|
||||
: this(logger, serializerSettings, charPool, objectPoolProvider, suppressInputFormatterBuffering: false)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="NewtonsoftJsonPatchInputFormatter"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="logger">The <see cref="ILogger"/>.</param>
|
||||
/// <param name="serializerSettings">
|
||||
/// The <see cref="JsonSerializerSettings"/>. Should be either the application-wide settings
|
||||
/// (<see cref="MvcNewtonsoftJsonOptions.SerializerSettings"/>) or an instance
|
||||
/// <see cref="JsonSerializerSettingsProvider.CreateSerializerSettings"/> initially returned.
|
||||
/// </param>
|
||||
/// <param name="charPool">The <see cref="ArrayPool{Char}"/>.</param>
|
||||
/// <param name="objectPoolProvider">The <see cref="ObjectPoolProvider"/>.</param>
|
||||
/// <param name="suppressInputFormatterBuffering">Flag to buffer entire request body before deserializing it.</param>
|
||||
[Obsolete("This constructor is obsolete and will be removed in a future version.")]
|
||||
public NewtonsoftJsonPatchInputFormatter(
|
||||
ILogger logger,
|
||||
JsonSerializerSettings serializerSettings,
|
||||
ArrayPool<char> charPool,
|
||||
ObjectPoolProvider objectPoolProvider,
|
||||
bool suppressInputFormatterBuffering)
|
||||
: this(logger, serializerSettings, charPool, objectPoolProvider, suppressInputFormatterBuffering, allowInputFormatterExceptionMessages: false)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="NewtonsoftJsonPatchInputFormatter"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="logger">The <see cref="ILogger"/>.</param>
|
||||
/// <param name="serializerSettings">
|
||||
/// The <see cref="JsonSerializerSettings"/>. Should be either the application-wide settings
|
||||
/// (<see cref="MvcNewtonsoftJsonOptions.SerializerSettings"/>) or an instance
|
||||
/// <see cref="JsonSerializerSettingsProvider.CreateSerializerSettings"/> initially returned.
|
||||
/// </param>
|
||||
/// <param name="charPool">The <see cref="ArrayPool{Char}"/>.</param>
|
||||
/// <param name="objectPoolProvider">The <see cref="ObjectPoolProvider"/>.</param>
|
||||
/// <param name="suppressInputFormatterBuffering">Flag to buffer entire request body before deserializing it.</param>
|
||||
/// <param name="allowInputFormatterExceptionMessages">
|
||||
/// If <see langword="false"/>, JSON deserialization exception messages will replaced by a generic message in model state.
|
||||
/// </param>
|
||||
[Obsolete("This constructor is obsolete and will be removed in a future version.")]
|
||||
public NewtonsoftJsonPatchInputFormatter(
|
||||
ILogger logger,
|
||||
JsonSerializerSettings serializerSettings,
|
||||
ArrayPool<char> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="NewtonsoftJsonPatchInputFormatter"/> instance.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -29,25 +29,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
|||
private const string AppendVersionAttributeName = "asp-append-version";
|
||||
private const string SrcAttributeName = "src";
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ImageTagHelper"/>.
|
||||
/// </summary>
|
||||
/// <param name="hostingEnvironment">The <see cref="IHostingEnvironment"/>.</param>
|
||||
/// <param name="cache">The <see cref="IMemoryCache"/>.</param>
|
||||
/// <param name="htmlEncoder">The <see cref="HtmlEncoder"/> to use.</param>
|
||||
/// <param name="urlHelperFactory">The <see cref="IUrlHelperFactory"/>.</param>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ImageTagHelper"/>.
|
||||
/// </summary>
|
||||
|
|
@ -58,7 +39,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
|||
/// <param name="urlHelperFactory">The <see cref="IUrlHelperFactory"/>.</param>
|
||||
// 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,
|
||||
|
|
|
|||
|
|
@ -95,28 +95,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
|||
};
|
||||
private StringWriter _stringWriter;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="LinkTagHelper"/>.
|
||||
/// </summary>
|
||||
/// <param name="hostingEnvironment">The <see cref="IHostingEnvironment"/>.</param>
|
||||
/// <param name="cache">The <see cref="IMemoryCache"/>.</param>
|
||||
/// <param name="htmlEncoder">The <see cref="HtmlEncoder"/>.</param>
|
||||
/// <param name="javaScriptEncoder">The <see cref="JavaScriptEncoder"/>.</param>
|
||||
/// <param name="urlHelperFactory">The <see cref="IUrlHelperFactory"/>.</param>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="LinkTagHelper"/>.
|
||||
/// </summary>
|
||||
|
|
@ -128,7 +106,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
|||
/// <param name="urlHelperFactory">The <see cref="IUrlHelperFactory"/>.</param>
|
||||
// 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,
|
||||
|
|
|
|||
|
|
@ -78,28 +78,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
|||
}),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ScriptTagHelper"/>.
|
||||
/// </summary>
|
||||
/// <param name="hostingEnvironment">The <see cref="IHostingEnvironment"/>.</param>
|
||||
/// <param name="cache">The <see cref="IMemoryCache"/>.</param>
|
||||
/// <param name="htmlEncoder">The <see cref="HtmlEncoder"/>.</param>
|
||||
/// <param name="javaScriptEncoder">The <see cref="JavaScriptEncoder"/>.</param>
|
||||
/// <param name="urlHelperFactory">The <see cref="IUrlHelperFactory"/>.</param>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ScriptTagHelper"/>.
|
||||
/// </summary>
|
||||
|
|
@ -111,7 +89,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
|||
/// <param name="urlHelperFactory">The <see cref="IUrlHelperFactory"/>.</param>
|
||||
// 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,
|
||||
|
|
|
|||
|
|
@ -54,42 +54,5 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
get => _cookieBuilder;
|
||||
set => _cookieBuilder = value ?? throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
#region Obsolete API
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// This property is obsolete and will be removed in a future version. The recommended alternative is <seealso cref="CookieBuilder.Path"/> on <see cref="Cookie"/>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The path set on the cookie. If set to <c>null</c>, the "path" attribute on the cookie is set to the current
|
||||
/// request's <see cref="HttpRequest.PathBase"/> value. If the value of <see cref="HttpRequest.PathBase"/> is
|
||||
/// <c>null</c> or empty, then the "path" attribute is set to the value of <see cref="CookieOptions.Path"/>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[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; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// This property is obsolete and will be removed in a future version. The recommended alternative is <seealso cref="CookieBuilder.Domain"/> on <see cref="Cookie"/>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The domain set on a cookie. Defaults to <c>null</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[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; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// This property is obsolete and will be removed in a future version. The recommended alternative is <seealso cref="CookieBuilder.Name"/> on <see cref="Cookie"/>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The name of the cookie which stores TempData. Defaults to <see cref="CookieTempDataProvider.CookieName"/>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,28 +18,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
|
|||
{
|
||||
public class HeaderModelBinderTests
|
||||
{
|
||||
public static TheoryData<HeaderModelBinder> HeaderModelBinderWithoutInnerBinderData
|
||||
{
|
||||
get
|
||||
{
|
||||
var data = new TheoryData<HeaderModelBinder>
|
||||
{
|
||||
#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;
|
||||
|
|
|
|||
|
|
@ -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<Person>().BindingDetails(binding =>
|
||||
{
|
||||
binding.BinderModelName = metadataBinderModelName;
|
||||
});
|
||||
|
||||
var metadata = metadataProvider.GetMetadataForType(typeof(Person));
|
||||
var modelBinder = new Mock<IModelBinder>();
|
||||
modelBinder
|
||||
.Setup(b => b.BindModelAsync(It.IsAny<ModelBindingContext>()))
|
||||
.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<IModelBinderFactory>(MockBehavior.Strict);
|
||||
factory
|
||||
.Setup(f => f.CreateBinder(It.IsAny<ModelBinderFactoryContext>()))
|
||||
.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<IObjectModelValidator>(),
|
||||
_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<IModelBinder>();
|
||||
modelBinder
|
||||
.Setup(b => b.BindModelAsync(It.IsAny<ModelBindingContext>()))
|
||||
.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<IModelBinderFactory>(MockBehavior.Strict);
|
||||
factory
|
||||
.Setup(f => f.CreateBinder(It.IsAny<ModelBinderFactoryContext>()))
|
||||
.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<IObjectModelValidator>(),
|
||||
_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<IModelBinderFactory>(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()
|
||||
|
|
|
|||
|
|
@ -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<IRouter>();
|
||||
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<IRouter>();
|
||||
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<IRouter>();
|
||||
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<IRouter>();
|
||||
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<IActionDescriptorCollectionProvider>();
|
||||
var httpContext = new Mock<HttpContext>();
|
||||
httpContext
|
||||
.Setup(o => o.RequestServices.GetService(typeof(IActionDescriptorCollectionProvider)))
|
||||
.Returns(actionDescriptorCollectionProvider);
|
||||
var constraint = new KnownRouteValueConstraint(actionDescriptorCollectionProvider);
|
||||
|
||||
// Act & Assert
|
||||
var ex = Assert.Throws<InvalidOperationException>(
|
||||
() => _constraint.Match(
|
||||
httpContext.Object,
|
||||
() => constraint.Match(
|
||||
GetHttpContext(),
|
||||
Mock.Of<IRouter>(),
|
||||
"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<HttpContext>();
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1351,25 +1351,13 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations
|
|||
useStringLocalizer ? stringLocalizerFactory.Object : null);
|
||||
}
|
||||
|
||||
private ModelAttributes GetModelAttributes(IEnumerable<object> 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<object> typeAttributes)
|
||||
=> new ModelAttributes(typeAttributes, Array.Empty<object>(), Array.Empty<object>());
|
||||
|
||||
private ModelAttributes GetModelAttributes(
|
||||
IEnumerable<object> typeAttributes,
|
||||
IEnumerable<object> 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<object> propertyAttributes)
|
||||
=> new ModelAttributes(typeAttributes, propertyAttributes, Array.Empty<object>());
|
||||
|
||||
private class KVPEnumGroupAndNameComparer : IEqualityComparer<KeyValuePair<EnumGroupAndName, string>>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<object> typeAttributes,
|
||||
IEnumerable<object> 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<object> propertyAttributes)
|
||||
=> new ModelAttributes(typeAttributes, propertyAttributes, Array.Empty<object>());
|
||||
|
||||
[DataContract]
|
||||
private class ClassWithDataMemberIsRequiredTrue
|
||||
|
|
|
|||
|
|
@ -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<object>(),
|
||||
Array.Empty<object>()));
|
||||
}
|
||||
|
||||
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<object>()));
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
|
||||
"<ProblemDetails>" +
|
||||
"<Title>Some title</Title>" +
|
||||
"<Status>403</Status>" +
|
||||
"<Instance>Some instance</Instance>" +
|
||||
"<key1>Test Value 1</key1>" +
|
||||
"<_x005B_key2_x005D_>Test Value 2</_x005B_key2_x005D_>" +
|
||||
"<MVC-Empty>Test Value 3</MVC-Empty>" +
|
||||
"</ProblemDetails>";
|
||||
var serializer = new DataContractSerializer(typeof(ProblemDetails21Wrapper));
|
||||
|
||||
// Act
|
||||
var value = serializer.ReadObject(
|
||||
new MemoryStream(Encoding.UTF8.GetBytes(xml)));
|
||||
|
||||
// Assert
|
||||
var problemDetails = Assert.IsType<ProblemDetails21Wrapper>(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 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
|
||||
"<ProblemDetails>" +
|
||||
"<Detail>Some detail</Detail>" +
|
||||
"<Title>Some title</Title>" +
|
||||
"<key1>Test Value 1</key1>" +
|
||||
"<_x005B_Key2_x005D_>Test Value 2</_x005B_Key2_x005D_>" +
|
||||
"<MVC-Empty>Test Value 3</MVC-Empty>" +
|
||||
"</ProblemDetails>";
|
||||
|
||||
// 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
|
||||
|
||||
}
|
||||
|
|
@ -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 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
|
||||
"<ValidationProblemDetails>" +
|
||||
"<Title>Some title</Title>" +
|
||||
"<Status>400</Status>" +
|
||||
"<Instance>Some instance</Instance>" +
|
||||
"<key1>Test Value 1</key1>" +
|
||||
"<_x005B_key2_x005D_>Test Value 2</_x005B_key2_x005D_>" +
|
||||
"<MVC-Errors>" +
|
||||
"<error1>Test error 1 Test error 2</error1>" +
|
||||
"<_x005B_error2_x005D_>Test error 3</_x005B_error2_x005D_>" +
|
||||
"<MVC-Empty>Test error 4</MVC-Empty>" +
|
||||
"</MVC-Errors>" +
|
||||
"</ValidationProblemDetails>";
|
||||
var serializer = new DataContractSerializer(typeof(ValidationProblemDetails21Wrapper));
|
||||
|
||||
// Act
|
||||
var value = serializer.ReadObject(
|
||||
new MemoryStream(Encoding.UTF8.GetBytes(xml)));
|
||||
|
||||
// Assert
|
||||
var problemDetails = Assert.IsType<ValidationProblemDetails21Wrapper>(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 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
|
||||
"<ValidationProblemDetails>" +
|
||||
"<Title>Some title</Title>" +
|
||||
"<Status>400</Status>" +
|
||||
"<Instance>Some instance</Instance>" +
|
||||
"<key1>Test Value 1</key1>" +
|
||||
"<_x005B_key2_x005D_>Test Value 2</_x005B_key2_x005D_>" +
|
||||
"</ValidationProblemDetails>";
|
||||
var serializer = new DataContractSerializer(typeof(ValidationProblemDetails21Wrapper));
|
||||
|
||||
// Act
|
||||
var value = serializer.ReadObject(
|
||||
new MemoryStream(Encoding.UTF8.GetBytes(xml)));
|
||||
|
||||
// Assert
|
||||
var problemDetails = Assert.IsType<ValidationProblemDetails21Wrapper>(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 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
|
||||
"<ValidationProblemDetails>" +
|
||||
"<Title>Some title</Title>" +
|
||||
"<Status>400</Status>" +
|
||||
"<MVC-Errors />" +
|
||||
"</ValidationProblemDetails>";
|
||||
var serializer = new DataContractSerializer(typeof(ValidationProblemDetails21Wrapper));
|
||||
|
||||
// Act
|
||||
var value = serializer.ReadObject(
|
||||
new MemoryStream(Encoding.UTF8.GetBytes(xml)));
|
||||
|
||||
// Assert
|
||||
var problemDetails = Assert.IsType<ValidationProblemDetails21Wrapper>(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 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
|
||||
"<ValidationProblemDetails>" +
|
||||
"<Detail>Some detail</Detail>" +
|
||||
"<Title>Some title</Title>" +
|
||||
"<key1>Test Value 1</key1>" +
|
||||
"<_x005B_Key2_x005D_>Test Value 2</_x005B_Key2_x005D_>" +
|
||||
"<MVC-Errors>" +
|
||||
"<error1>Test error 1 Test error 2</error1>" +
|
||||
"<_x005B_error2_x005D_>Test error 3</_x005B_error2_x005D_>" +
|
||||
"<MVC-Empty>Test error 4</MVC-Empty>" +
|
||||
"</MVC-Errors>" +
|
||||
"</ValidationProblemDetails>";
|
||||
|
||||
// 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 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
|
||||
"<ValidationProblemDetails>" +
|
||||
"<Detail>Some detail</Detail>" +
|
||||
"<Title>Some title</Title>" +
|
||||
"<key1>Test Value 1</key1>" +
|
||||
"<_x005B_Key2_x005D_>Test Value 2</_x005B_Key2_x005D_>" +
|
||||
"</ValidationProblemDetails>";
|
||||
|
||||
// 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
|
||||
}
|
||||
|
|
@ -144,9 +144,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
"<TestLevelOne><SampleInt>" + expectedInt + "</SampleInt>" +
|
||||
"<sampleString>" + expectedString + "</sampleString></TestLevelOne>";
|
||||
|
||||
#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
|
|||
"<TestLevelOne><SampleInt>" + expectedInt + "</SampleInt>" +
|
||||
"<sampleString>" + expectedString + "</sampleString></TestLevelOne>";
|
||||
|
||||
#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();
|
||||
|
|
|
|||
|
|
@ -52,9 +52,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
"<sampleString>" + expectedString + "</sampleString>" +
|
||||
"<SampleDate>" + expectedDateTime + "</SampleDate></TestLevelOne>";
|
||||
|
||||
#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
|
|||
"<sampleString>" + expectedString + "</sampleString>" +
|
||||
"<SampleDate>" + expectedDateTime + "</SampleDate></TestLevelOne>";
|
||||
|
||||
#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();
|
||||
|
|
|
|||
|
|
@ -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<char>.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<IHttpResponseFeature>(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<User>(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<User>(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<char>.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<IHttpResponseFeature>(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<User>(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()
|
||||
|
|
|
|||
|
|
@ -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<char>.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<IHttpResponseFeature>(new TestResponseFeature());
|
||||
httpContext.Request.Body = new NonSeekableReadStream(contentBytes);
|
||||
httpContext.Request.ContentType = "application/json";
|
||||
|
||||
var formatterContext = CreateInputFormatterContext(typeof(JsonPatchDocument<Customer>), httpContext);
|
||||
|
||||
// Act
|
||||
var result = await formatter.ReadAsync(formatterContext);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.HasError);
|
||||
var patchDocument = Assert.IsType<JsonPatchDocument<Customer>>(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<JsonPatchDocument<Customer>>(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<char>.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<IHttpResponseFeature>(new TestResponseFeature());
|
||||
httpContext.Request.Body = new NonSeekableReadStream(contentBytes);
|
||||
httpContext.Request.ContentType = "application/json";
|
||||
|
||||
var context = CreateInputFormatterContext(typeof(JsonPatchDocument<Customer>), httpContext);
|
||||
|
||||
// Act
|
||||
var result = await formatter.ReadAsync(context);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.HasError);
|
||||
|
||||
var patchDocument = Assert.IsType<JsonPatchDocument<Customer>>(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()
|
||||
|
|
|
|||
|
|
@ -25,9 +25,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
|||
var detailsProvider = new DefaultCompositeMetadataDetailsProvider(
|
||||
Enumerable.Empty<IMetadataDetailsProvider>());
|
||||
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<object>(),
|
||||
Array.Empty<object>(),
|
||||
Array.Empty<object>()));
|
||||
|
||||
var provider = new EmptyModelMetadataProvider();
|
||||
var metadata = new DefaultModelMetadata(provider, detailsProvider, cache);
|
||||
|
|
|
|||
Loading…
Reference in New Issue