React to string[] -> StringValues changes.
This commit is contained in:
parent
a2d58ba4ea
commit
f2db0d1483
|
|
@ -385,26 +385,22 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
/// </param>
|
||||
public void SetModelValue([NotNull] string key, ValueProviderResult valueProviderResult)
|
||||
{
|
||||
// Avoid creating a new array for rawvalue if there's only one value.
|
||||
// Avoid creating a new array for rawValue if there's only one value.
|
||||
object rawValue;
|
||||
if (valueProviderResult == ValueProviderResult.None)
|
||||
{
|
||||
rawValue = null;
|
||||
}
|
||||
else if (valueProviderResult.Value != null)
|
||||
{
|
||||
rawValue = valueProviderResult.Value;
|
||||
}
|
||||
else if (valueProviderResult.Length == 1)
|
||||
{
|
||||
rawValue = valueProviderResult.Values[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
rawValue = valueProviderResult.Values;
|
||||
rawValue = valueProviderResult.Values.ToArray();
|
||||
}
|
||||
|
||||
SetModelValue(key, rawValue, (string)valueProviderResult);
|
||||
SetModelValue(key, rawValue, valueProviderResult.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.Primitives;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
{
|
||||
|
|
@ -38,9 +37,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
/// <summary>
|
||||
/// Creates a new <see cref="ValueProviderResult"/> using <see cref="CultureInfo.InvariantCulture"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The submitted value.</param>
|
||||
public ValueProviderResult(string value)
|
||||
: this(value, _invariantCulture)
|
||||
/// <param name="values">The submitted values.</param>
|
||||
public ValueProviderResult(StringValues values)
|
||||
: this(values, _invariantCulture)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -49,88 +48,36 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
/// </summary>
|
||||
/// <param name="value">The submitted value.</param>
|
||||
/// <param name="culture">The <see cref="CultureInfo"/> associated with this value.</param>
|
||||
public ValueProviderResult(string value, CultureInfo culture)
|
||||
public ValueProviderResult(StringValues values, CultureInfo culture)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
Value = null;
|
||||
Values = None.Values;
|
||||
}
|
||||
else
|
||||
{
|
||||
Value = value;
|
||||
Values = null;
|
||||
}
|
||||
|
||||
Values = values;
|
||||
Culture = culture ?? _invariantCulture;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ValueProviderResult"/> using <see cref="CultureInfo.InvariantCulture"/>.
|
||||
/// </summary>
|
||||
/// <param name="values">The submitted values.</param>
|
||||
public ValueProviderResult(string[] values)
|
||||
: this(values, _invariantCulture)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ValueProviderResult"/>.
|
||||
/// </summary>
|
||||
/// <param name="values">The submitted values.</param>
|
||||
/// <param name="culture">The <see cref="CultureInfo"/> associated with these values.</param>
|
||||
public ValueProviderResult(string[] values, CultureInfo culture)
|
||||
{
|
||||
if (values == null)
|
||||
{
|
||||
Value = null;
|
||||
Values = None.Values;
|
||||
}
|
||||
else
|
||||
{
|
||||
Value = null;
|
||||
Values = values;
|
||||
}
|
||||
|
||||
Culture = culture;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="CultureInfo"/> associated with the values.
|
||||
/// </summary>
|
||||
public CultureInfo Culture { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a single value. Will be <c>null</c> if multiple values are present.
|
||||
/// Gets or sets the values.
|
||||
/// </summary>
|
||||
public string Value { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an array of values. Will be <c>null</c> if only a single value was provided.
|
||||
/// </summary>
|
||||
public string[] Values { get; private set; }
|
||||
public StringValues Values { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the first value based on the order values were provided in the request. Use <see cref="FirstValue"/>
|
||||
/// to get a single value for processing regarless of whether a single or multiple values were provided
|
||||
/// to get a single value for processing regardless of whether a single or multiple values were provided
|
||||
/// in the request.
|
||||
/// </summary>
|
||||
public string FirstValue
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Value != null)
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
else if (Values != null && Values.Length > 0)
|
||||
{
|
||||
return Values[0];
|
||||
}
|
||||
else
|
||||
if (Values.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return Values[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -141,18 +88,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
{
|
||||
get
|
||||
{
|
||||
if (Values != null)
|
||||
{
|
||||
return Values.Length;
|
||||
}
|
||||
else if (Value != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return Values.Count;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -172,9 +108,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
}
|
||||
else
|
||||
{
|
||||
var x = (string[])this;
|
||||
var y = (string[])other;
|
||||
for (var i = 0; i < x.Length; i++)
|
||||
var x = Values;
|
||||
var y = other.Values;
|
||||
for (var i = 0; i < x.Count; i++)
|
||||
{
|
||||
if (!string.Equals(x[i], y[i], StringComparison.Ordinal))
|
||||
{
|
||||
|
|
@ -188,28 +124,22 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
/// <inheritdoc />
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ((string)this)?.GetHashCode() ?? 0;
|
||||
return ToString().GetHashCode();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return (string)this;
|
||||
return Values.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Enumerator"/> for this <see cref="ValueProviderResult"/>.
|
||||
/// Gets an <see cref="IEnumerator<string>"/> for this <see cref="ValueProviderResult"/>.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="Enumerator"/>.</returns>
|
||||
public Enumerator GetEnumerator()
|
||||
/// <returns>An <see cref="IEnumerator<string>"/>.</returns>
|
||||
public IEnumerator<string> GetEnumerator()
|
||||
{
|
||||
return new Enumerator(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerator<string> IEnumerable<string>.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
return ((IEnumerable<string>)Values).GetEnumerator();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -225,22 +155,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
/// <param name="result">The <see cref="ValueProviderResult"/>.</param>
|
||||
public static explicit operator string(ValueProviderResult result)
|
||||
{
|
||||
if (result.Values == null)
|
||||
{
|
||||
return result.Value;
|
||||
}
|
||||
else if (result.Values.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (result.Values.Length == 1)
|
||||
{
|
||||
return result.Values[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Join(",", result.Values);
|
||||
}
|
||||
return result.Values;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -250,18 +165,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
/// <param name="result">The <see cref="ValueProviderResult"/>.</param>
|
||||
public static explicit operator string[](ValueProviderResult result)
|
||||
{
|
||||
if (result.Values != null)
|
||||
{
|
||||
return result.Values;
|
||||
}
|
||||
else if (result.Value != null)
|
||||
{
|
||||
return new string[] { result.Value };
|
||||
}
|
||||
else
|
||||
{
|
||||
return None.Values;
|
||||
}
|
||||
return result.Values;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -285,71 +189,5 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
{
|
||||
return !x.Equals(y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An enumerator for <see cref="ValueProviderResult"/>.
|
||||
/// </summary>
|
||||
public struct Enumerator : IEnumerator<string>
|
||||
{
|
||||
private readonly ValueProviderResult _result;
|
||||
private readonly int _length;
|
||||
private int _index;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Enumerator"/>.
|
||||
/// </summary>
|
||||
/// <param name="result">The <see cref="ValueProviderResult"/>.</param>
|
||||
public Enumerator(ValueProviderResult result)
|
||||
{
|
||||
_result = result;
|
||||
_index = -1;
|
||||
_length = result.Length;
|
||||
Current = null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Current { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
object IEnumerator.Current => Current;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool MoveNext()
|
||||
{
|
||||
++_index;
|
||||
if (_index < _length)
|
||||
{
|
||||
if (_result.Values != null)
|
||||
{
|
||||
Debug.Assert(_index < _result.Values.Length);
|
||||
Current = _result.Values[_index];
|
||||
return true;
|
||||
}
|
||||
else if (_result.Value != null && _index == 0)
|
||||
{
|
||||
Current = _result.Value;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Current = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Reset()
|
||||
{
|
||||
_index = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using Microsoft.AspNet.Http;
|
|||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -73,7 +74,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
throw new InvalidOperationException(Resources.NoRoutesMatched);
|
||||
}
|
||||
|
||||
context.HttpContext.Response.Headers.Set("Location", url);
|
||||
context.HttpContext.Response.Headers[HeaderNames.Location] = url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ using Microsoft.AspNet.Http;
|
|||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -70,7 +71,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
throw new InvalidOperationException(Resources.NoRoutesMatched);
|
||||
}
|
||||
|
||||
context.HttpContext.Response.Headers.Set("Location", url);
|
||||
context.HttpContext.Response.Headers[HeaderNames.Location] = url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -50,7 +51,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
/// <inheritdoc />
|
||||
protected override void OnFormatting([NotNull] ActionContext context)
|
||||
{
|
||||
context.HttpContext.Response.Headers.Set("Location", Location);
|
||||
context.HttpContext.Response.Headers[HeaderNames.Location] = Location;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -68,7 +68,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
// basis for the actual filename, where possible.
|
||||
var cd = new ContentDispositionHeaderValue("attachment");
|
||||
cd.SetHttpFileName(FileDownloadName);
|
||||
context.HttpContext.Response.Headers.Set(HeaderNames.ContentDisposition, cd.ToString());
|
||||
context.HttpContext.Response.Headers[HeaderNames.ContentDisposition] = cd.ToString();
|
||||
}
|
||||
|
||||
// We aren't flowing the cancellation token appropriately, see
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.Primitives;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -62,12 +63,12 @@ namespace Microsoft.AspNet.Mvc
|
|||
if (request.Headers.ContainsKey(OriginHeader))
|
||||
{
|
||||
// Update the http method if it is preflight request.
|
||||
var accessControlRequestMethod = request.Headers.Get(AccessControlRequestMethod);
|
||||
var accessControlRequestMethod = request.Headers[AccessControlRequestMethod];
|
||||
if (string.Equals(
|
||||
request.Method,
|
||||
PreflightHttpMethod,
|
||||
StringComparison.Ordinal) &&
|
||||
accessControlRequestMethod != null)
|
||||
!StringValues.IsNullOrEmpty(accessControlRequestMethod))
|
||||
{
|
||||
method = accessControlRequestMethod;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using System.Linq;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.Primitives;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
{
|
||||
|
|
@ -51,11 +52,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
|
||||
private class EmptyFormCollection : IFormCollection
|
||||
{
|
||||
public string this[string key]
|
||||
public StringValues this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
return StringValues.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,12 +94,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
return null;
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<string, string[]>> GetEnumerator()
|
||||
public IEnumerator<KeyValuePair<string, StringValues>> GetEnumerator()
|
||||
{
|
||||
return Enumerable.Empty<KeyValuePair<string, string[]>>().GetEnumerator();
|
||||
return Enumerable.Empty<KeyValuePair<string, StringValues>>().GetEnumerator();
|
||||
}
|
||||
|
||||
public IList<string> GetValues(string key)
|
||||
public IList<StringValues> GetValues(string key)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#if DNXCORE50
|
||||
using System.Reflection;
|
||||
#endif
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
|
|
@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
object model = null;
|
||||
if (bindingContext.ModelType == typeof(string))
|
||||
{
|
||||
var value = request.Headers.Get(headerName);
|
||||
string value = request.Headers[headerName];
|
||||
if (value != null)
|
||||
{
|
||||
model = value;
|
||||
|
|
@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
else if (typeof(IEnumerable<string>).IsAssignableFrom(bindingContext.ModelType))
|
||||
{
|
||||
var values = request.Headers.GetCommaSeparatedValues(headerName);
|
||||
if (values != null)
|
||||
if (values.Length > 0)
|
||||
{
|
||||
model = ModelBindingHelper.ConvertValuesToCollectionType(
|
||||
bindingContext.ModelType,
|
||||
|
|
@ -60,11 +60,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
bindingContext.ModelName,
|
||||
bindingContext.ModelMetadata,
|
||||
model);
|
||||
|
||||
|
||||
bindingContext.ModelState.SetModelValue(
|
||||
bindingContext.ModelName,
|
||||
request.Headers.GetCommaSeparatedValues(headerName).ToArray(),
|
||||
request.Headers.Get(headerName));
|
||||
bindingContext.ModelName,
|
||||
request.Headers.GetCommaSeparatedValues(headerName),
|
||||
request.Headers[headerName]);
|
||||
}
|
||||
|
||||
return Task.FromResult(
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
// 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.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.Primitives;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
{
|
||||
|
|
@ -14,8 +15,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
/// </summary>
|
||||
public class JQueryFormValueProvider : BindingSourceValueProvider, IEnumerableValueProvider
|
||||
{
|
||||
private readonly IDictionary<string, StringValues> _values;
|
||||
private PrefixContainer _prefixContainer;
|
||||
private readonly IDictionary<string, string[]> _values;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DictionaryBasedValueProvider"/> class.
|
||||
|
|
@ -25,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
/// <param name="culture">The culture to return with ValueProviderResult instances.</param>
|
||||
public JQueryFormValueProvider(
|
||||
[NotNull] BindingSource bindingSource,
|
||||
[NotNull] IDictionary<string, string[]> values,
|
||||
[NotNull] IDictionary<string, StringValues> values,
|
||||
CultureInfo culture)
|
||||
: base(bindingSource)
|
||||
{
|
||||
|
|
@ -64,8 +65,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
/// <inheritdoc />
|
||||
public override ValueProviderResult GetValue(string key)
|
||||
{
|
||||
string[] values;
|
||||
if (_values.TryGetValue(key, out values) && values != null && values.Length > 0)
|
||||
StringValues values;
|
||||
if (_values.TryGetValue(key, out values) && values.Count > 0)
|
||||
{
|
||||
return new ValueProviderResult(values, Culture);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.Primitives;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
{
|
||||
|
|
@ -29,11 +30,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
return null;
|
||||
}
|
||||
|
||||
private static async Task<IDictionary<string, string[]>> GetValueCollectionAsync(HttpRequest request)
|
||||
private static async Task<IDictionary<string, StringValues>> GetValueCollectionAsync(HttpRequest request)
|
||||
{
|
||||
var formCollection = await request.ReadFormAsync();
|
||||
|
||||
var dictionary = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
|
||||
var dictionary = new Dictionary<string, StringValues>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var entry in formCollection)
|
||||
{
|
||||
var key = NormalizeJQueryToMvc(entry.Key);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
// 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.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
|
|
@ -73,14 +69,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
/// <inheritdoc />
|
||||
public override ValueProviderResult GetValue([NotNull] string key)
|
||||
{
|
||||
var values = _values.GetValues(key);
|
||||
if (values == null)
|
||||
var values = _values[key];
|
||||
if (values.Count == 0)
|
||||
{
|
||||
return ValueProviderResult.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ValueProviderResult(values.ToArray(), _culture);
|
||||
return new ValueProviderResult(values, _culture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,15 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
/// </returns>
|
||||
public static T ConvertTo<T>(this ValueProviderResult result)
|
||||
{
|
||||
var valueToConvert = (object)result.Values ?? (object)result.Value;
|
||||
object valueToConvert = null;
|
||||
if (result.Values.Count == 1)
|
||||
{
|
||||
valueToConvert = result.Values[0];
|
||||
}
|
||||
else if (result.Values.Count > 1)
|
||||
{
|
||||
valueToConvert = result.Values.ToArray();
|
||||
}
|
||||
return ModelBindingHelper.ConvertTo<T>(valueToConvert, result.Culture);
|
||||
}
|
||||
|
||||
|
|
@ -35,7 +43,15 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
/// </returns>
|
||||
public static object ConvertTo(this ValueProviderResult result, [NotNull] Type type)
|
||||
{
|
||||
var valueToConvert = (object)result.Values ?? (object)result.Value;
|
||||
object valueToConvert = null;
|
||||
if (result.Values.Count == 1)
|
||||
{
|
||||
valueToConvert = result.Values[0];
|
||||
}
|
||||
else if (result.Values.Count > 1)
|
||||
{
|
||||
valueToConvert = result.Values.ToArray();
|
||||
}
|
||||
return ModelBindingHelper.ConvertTo(valueToConvert, type, result.Culture);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -94,24 +96,24 @@ namespace Microsoft.AspNet.Mvc
|
|||
var headers = context.HttpContext.Response.Headers;
|
||||
|
||||
// Clear all headers
|
||||
headers.Remove("Vary");
|
||||
headers.Remove("Cache-control");
|
||||
headers.Remove("Pragma");
|
||||
headers.Remove(HeaderNames.Vary);
|
||||
headers.Remove(HeaderNames.CacheControl);
|
||||
headers.Remove(HeaderNames.Pragma);
|
||||
|
||||
if (!string.IsNullOrEmpty(VaryByHeader))
|
||||
{
|
||||
headers.Set("Vary", VaryByHeader);
|
||||
headers[HeaderNames.Vary] = VaryByHeader;
|
||||
}
|
||||
|
||||
if (NoStore)
|
||||
{
|
||||
headers.Set("Cache-control", "no-store");
|
||||
headers[HeaderNames.CacheControl] = "no-store";
|
||||
|
||||
// Cache-control: no-store, no-cache is valid.
|
||||
if (Location == ResponseCacheLocation.None)
|
||||
{
|
||||
headers.Append("Cache-control", "no-cache");
|
||||
headers.Set("Pragma", "no-cache");
|
||||
headers.AppendCommaSeparatedValues(HeaderNames.CacheControl, "no-cache");
|
||||
headers[HeaderNames.Pragma] = "no-cache";
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -127,7 +129,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
break;
|
||||
case ResponseCacheLocation.None:
|
||||
cacheControlValue = "no-cache";
|
||||
headers.Set("Pragma", "no-cache");
|
||||
headers[HeaderNames.Pragma] = "no-cache";
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -140,7 +142,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
if (cacheControlValue != null)
|
||||
{
|
||||
headers.Set("Cache-control", cacheControlValue);
|
||||
headers[HeaderNames.CacheControl] = cacheControlValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNet.Cors.Core;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.Primitives;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -20,7 +21,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
private ICorsPolicyProvider _corsPolicyProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instace of <see cref="CorsAuthorizationFilter"/>.
|
||||
/// Creates a new instance of <see cref="CorsAuthorizationFilter"/>.
|
||||
/// </summary>
|
||||
/// <param name="corsService">The <see cref="ICorsService"/>.</param>
|
||||
/// <param name="policyProvider">The <see cref="ICorsPolicyProvider"/>.</param>
|
||||
|
|
@ -63,12 +64,12 @@ namespace Microsoft.AspNet.Mvc
|
|||
_corsService.ApplyResult(result, context.HttpContext.Response);
|
||||
|
||||
var accessControlRequestMethod =
|
||||
httpContext.Request.Headers.Get(CorsConstants.AccessControlRequestMethod);
|
||||
httpContext.Request.Headers[CorsConstants.AccessControlRequestMethod];
|
||||
if (string.Equals(
|
||||
request.Method,
|
||||
CorsConstants.PreflightHttpMethod,
|
||||
StringComparison.Ordinal) &&
|
||||
accessControlRequestMethod != null)
|
||||
!StringValues.IsNullOrEmpty(accessControlRequestMethod))
|
||||
{
|
||||
// If this was a preflight, there is no need to run anything else.
|
||||
// Also the response is always 200 so that anyone after mvc can handle the pre flight request.
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNet.Cors.Core;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.Primitives;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -27,12 +28,12 @@ namespace Microsoft.AspNet.Mvc
|
|||
public Task OnAuthorizationAsync([NotNull] AuthorizationContext context)
|
||||
{
|
||||
var accessControlRequestMethod =
|
||||
context.HttpContext.Request.Headers.Get(CorsConstants.AccessControlRequestMethod);
|
||||
context.HttpContext.Request.Headers[CorsConstants.AccessControlRequestMethod];
|
||||
if (string.Equals(
|
||||
context.HttpContext.Request.Method,
|
||||
CorsConstants.PreflightHttpMethod,
|
||||
StringComparison.Ordinal) &&
|
||||
accessControlRequestMethod != null)
|
||||
!StringValues.IsNullOrEmpty(accessControlRequestMethod))
|
||||
{
|
||||
// Short circuit if the request is preflight as that should not result in action execution.
|
||||
context.Result = new HttpStatusCodeResult(StatusCodes.Status200OK);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
|
|
@ -53,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
|||
|
||||
foreach (var header in responseHeaders)
|
||||
{
|
||||
response.Headers.AppendValues(header.Key, header.Value.ToArray());
|
||||
response.Headers.Append(header.Key, header.Value.ToArray());
|
||||
}
|
||||
|
||||
if (responseMessage.Content != null)
|
||||
|
|
@ -67,7 +68,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
|||
|
||||
foreach (var header in contentHeaders)
|
||||
{
|
||||
response.Headers.AppendValues(header.Key, header.Value.ToArray());
|
||||
response.Headers.Append(header.Key, header.Value.ToArray());
|
||||
}
|
||||
|
||||
await responseMessage.Content.CopyToAsync(response.Body);
|
||||
|
|
|
|||
|
|
@ -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.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
|
@ -58,9 +59,9 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
|||
{
|
||||
// Every header should be able to fit into one of the two header collections.
|
||||
// Try message.Headers first since that accepts more of them.
|
||||
if (!message.Headers.TryAddWithoutValidation(header.Key, header.Value))
|
||||
if (!message.Headers.TryAddWithoutValidation(header.Key, (IEnumerable<string>)header.Value))
|
||||
{
|
||||
var added = message.Content.Headers.TryAddWithoutValidation(header.Key, header.Value);
|
||||
var added = message.Content.Headers.TryAddWithoutValidation(header.Key, (IEnumerable<string>)header.Value);
|
||||
Debug.Assert(added);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 Microsoft.Framework.Primitives;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
|
|
@ -15,12 +16,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
|
||||
// Assert
|
||||
Assert.Equal(0, result.Length);
|
||||
Assert.Null(result.Value);
|
||||
Assert.Empty(result.Values);
|
||||
Assert.Null(result.FirstValue);
|
||||
Assert.Equal(ValueProviderResult.None, result);
|
||||
Assert.Null((string)result);
|
||||
Assert.Empty((string[])result);
|
||||
Assert.Null((string[])result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -31,12 +31,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
|
||||
// Assert
|
||||
Assert.Equal(0, result.Length);
|
||||
Assert.Null(result.Value);
|
||||
Assert.Empty(result.Values);
|
||||
Assert.Null(result.FirstValue);
|
||||
Assert.Equal(ValueProviderResult.None, result);
|
||||
Assert.Null((string)result);
|
||||
Assert.Empty((string[])result);
|
||||
Assert.Null((string[])result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -47,10 +46,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
|
||||
// Assert
|
||||
Assert.Equal(0, result.Length);
|
||||
Assert.Null(result.Value);
|
||||
Assert.Empty(result.Values);
|
||||
Assert.Null(result.FirstValue);
|
||||
Assert.Equal(ValueProviderResult.None, result);
|
||||
Assert.Equal(ValueProviderResult.None, new ValueProviderResult(new StringValues()));
|
||||
Assert.Null((string)result);
|
||||
Assert.Empty((string[])result);
|
||||
}
|
||||
|
|
@ -63,8 +62,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
|
||||
// Assert
|
||||
Assert.Equal(1, result.Length);
|
||||
Assert.Equal("Hi There", result.Value);
|
||||
Assert.Null(result.Values);
|
||||
Assert.Equal("Hi There", result.Values);
|
||||
Assert.Equal("Hi There", result.FirstValue);
|
||||
Assert.NotEqual(ValueProviderResult.None, result);
|
||||
Assert.Equal("Hi There", (string)result);
|
||||
|
|
@ -79,7 +77,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
|
||||
// Assert
|
||||
Assert.Equal(2, result.Length);
|
||||
Assert.Null(result.Value);
|
||||
Assert.Equal(new string[] { "Hi", "There" }, result.Values);
|
||||
Assert.Equal("Hi", result.FirstValue);
|
||||
Assert.NotEqual(ValueProviderResult.None, result);
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var httpResponse = new Mock<HttpResponse>();
|
||||
httpResponse.SetupProperty(o => o.StatusCode);
|
||||
httpResponse.Setup(o => o.Headers).Returns(
|
||||
new HeaderDictionary(new Dictionary<string, string[]>()));
|
||||
new HeaderDictionary());
|
||||
httpResponse.SetupGet(o => o.Body).Returns(stream);
|
||||
return httpResponse.Object;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var location = "/test/";
|
||||
var httpContext = GetHttpContext();
|
||||
var actionContext = GetActionContext(httpContext);
|
||||
httpContext.Response.Headers.Set("Location", "/different/location/");
|
||||
httpContext.Response.Headers["Location"] = "/different/location/";
|
||||
var result = new CreatedResult(location, "testInput");
|
||||
|
||||
// Act
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
// Query contains xml
|
||||
httpContext.Setup(c => c.Request.Query.ContainsKey("format")).Returns(true);
|
||||
httpContext.Setup(c => c.Request.Query.Get("format")).Returns("xml");
|
||||
httpContext.Setup(c => c.Request.Query["format"]).Returns("xml");
|
||||
|
||||
// Routedata contains json
|
||||
var data = new RouteData();
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using System.Collections.Generic;
|
|||
using System.Globalization;
|
||||
#if DNX451
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Framework.Primitives;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
#endif
|
||||
|
|
@ -18,11 +19,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
{
|
||||
protected override IEnumerableValueProvider GetEnumerableValueProvider(
|
||||
BindingSource bindingSource,
|
||||
IDictionary<string, string[]> values,
|
||||
IDictionary<string, StringValues> values,
|
||||
CultureInfo culture)
|
||||
{
|
||||
var emptyValueProvider =
|
||||
new JQueryFormValueProvider(bindingSource, new Dictionary<string, string[]>(), culture);
|
||||
new JQueryFormValueProvider(bindingSource, new Dictionary<string, StringValues>(), culture);
|
||||
var valueProvider = new JQueryFormValueProvider(bindingSource, values, culture);
|
||||
|
||||
return new CompositeValueProvider(new[] { emptyValueProvider, valueProvider });
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using System.Globalization;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
using Microsoft.Framework.Primitives;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -453,10 +454,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
|
|||
string keyFormat,
|
||||
IDictionary<string, string> dictionary)
|
||||
{
|
||||
// Convert to an IDictionary<string, string[]> then wrap it up.
|
||||
// Convert to an IDictionary<string, StringValues> then wrap it up.
|
||||
var backingStore = dictionary.ToDictionary(
|
||||
kvp => string.Format(keyFormat, kvp.Key),
|
||||
kvp => new[] { kvp.Value });
|
||||
kvp => (StringValues)kvp.Value);
|
||||
var stringCollection = new ReadableStringCollection(backingStore);
|
||||
|
||||
return new ReadableStringCollectionValueProvider(
|
||||
|
|
|
|||
|
|
@ -5,34 +5,35 @@ using System.Collections.Generic;
|
|||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Framework.Primitives;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
{
|
||||
public abstract class EnumerableValueProviderTest
|
||||
{
|
||||
private static readonly IDictionary<string, string[]> _backingStore = new Dictionary<string, string[]>
|
||||
private static readonly IDictionary<string, StringValues> _backingStore = new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "some", new[] { "someValue1", "someValue2" } },
|
||||
{ "null_value", null },
|
||||
{ "null_value", StringValues.Empty },
|
||||
{ "prefix.name", new[] { "someOtherValue" } },
|
||||
{ "prefix.null_value", null },
|
||||
{ "prefix.property1.property", null },
|
||||
{ "prefix.property2[index]", null },
|
||||
{ "prefix[index1]", null },
|
||||
{ "prefix[index1].property1", null },
|
||||
{ "prefix[index1].property2", null },
|
||||
{ "prefix[index2].property", null },
|
||||
{ "[index]", null },
|
||||
{ "[index].property", null },
|
||||
{ "[index][anotherIndex]", null },
|
||||
{ "prefix.null_value", StringValues.Empty },
|
||||
{ "prefix.property1.property", StringValues.Empty },
|
||||
{ "prefix.property2[index]", StringValues.Empty },
|
||||
{ "prefix[index1]", StringValues.Empty },
|
||||
{ "prefix[index1].property1", StringValues.Empty },
|
||||
{ "prefix[index1].property2", StringValues.Empty },
|
||||
{ "prefix[index2].property", StringValues.Empty },
|
||||
{ "[index]", StringValues.Empty },
|
||||
{ "[index].property", StringValues.Empty },
|
||||
{ "[index][anotherIndex]", StringValues.Empty },
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void ContainsPrefix_WithEmptyCollection_ReturnsFalseForEmptyPrefix()
|
||||
{
|
||||
// Arrange
|
||||
var backingStore = new Dictionary<string, string[]>();
|
||||
var backingStore = new Dictionary<string, StringValues>();
|
||||
var valueProvider = GetEnumerableValueProvider(BindingSource.Query, backingStore, culture: null);
|
||||
|
||||
// Act
|
||||
|
|
@ -209,7 +210,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
public void GetValue_NullMultipleValue()
|
||||
{
|
||||
// Arrange
|
||||
var backingStore = new Dictionary<string, string[]>
|
||||
var backingStore = new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "key", new string[] { null, null, "value" } },
|
||||
};
|
||||
|
|
@ -278,7 +279,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
|
||||
private IBindingSourceValueProvider GetBindingSourceValueProvider(
|
||||
BindingSource bindingSource,
|
||||
IDictionary<string, string[]> values,
|
||||
IDictionary<string, StringValues> values,
|
||||
CultureInfo culture)
|
||||
{
|
||||
var provider = GetEnumerableValueProvider(bindingSource, values, culture) as IBindingSourceValueProvider;
|
||||
|
|
@ -291,7 +292,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
|
||||
protected abstract IEnumerableValueProvider GetEnumerableValueProvider(
|
||||
BindingSource bindingSource,
|
||||
IDictionary<string, string[]> values,
|
||||
IDictionary<string, StringValues> values,
|
||||
CultureInfo culture);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
using Microsoft.Framework.Primitives;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -20,10 +21,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
public async Task FormCollectionModelBinder_ValidType_BindSuccessful()
|
||||
{
|
||||
// Arrange
|
||||
var formCollection = new FormCollection(new Dictionary<string, string[]>
|
||||
var formCollection = new FormCollection(new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "field1", new string[] { "value1" } },
|
||||
{ "field2", new string[] { "value2" } }
|
||||
{ "field1", "value1" },
|
||||
{ "field2", "value2" }
|
||||
});
|
||||
var httpContext = GetMockHttpContext(formCollection);
|
||||
var bindingContext = GetBindingContext(typeof(IFormCollection), httpContext);
|
||||
|
|
@ -48,10 +49,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
public async Task FormCollectionModelBinder_InvalidType_BindFails()
|
||||
{
|
||||
// Arrange
|
||||
var formCollection = new FormCollection(new Dictionary<string, string[]>
|
||||
var formCollection = new FormCollection(new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "field1", new string[] { "value1" } },
|
||||
{ "field2", new string[] { "value2" } }
|
||||
{ "field1", "value1" },
|
||||
{ "field2", "value2" }
|
||||
});
|
||||
var httpContext = GetMockHttpContext(formCollection);
|
||||
var bindingContext = GetBindingContext(typeof(string), httpContext);
|
||||
|
|
@ -69,9 +70,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
public async Task FormCollectionModelBinder_FormCollectionConcreteType_BindFails()
|
||||
{
|
||||
// Arrange
|
||||
var formCollection = new FormCollection(new Dictionary<string, string[]>
|
||||
var formCollection = new FormCollection(new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "field1", new string[] { "value1" } },
|
||||
{ "field1", "value1" },
|
||||
{ "field2", new string[] { "value2" } }
|
||||
});
|
||||
var httpContext = GetMockHttpContext(formCollection);
|
||||
|
|
@ -131,11 +132,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
|
||||
private class MyFormCollection : ReadableStringCollection, IFormCollection
|
||||
{
|
||||
public MyFormCollection(IDictionary<string, string[]> store) : this(store, new FormFileCollection())
|
||||
public MyFormCollection(IDictionary<string, StringValues> store) : this(store, new FormFileCollection())
|
||||
{
|
||||
}
|
||||
|
||||
public MyFormCollection(IDictionary<string, string[]> store, IFormFileCollection files) : base(store)
|
||||
public MyFormCollection(IDictionary<string, StringValues> store, IFormFileCollection files) : base(store)
|
||||
{
|
||||
Files = files;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
using Microsoft.Framework.Primitives;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding.Test
|
||||
|
|
@ -52,7 +53,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
|
|||
|
||||
if (context.Request.HasFormContentType)
|
||||
{
|
||||
context.Request.Form = new FormCollection(new Dictionary<string, string[]>());
|
||||
context.Request.Form = new FormCollection(new Dictionary<string, StringValues>());
|
||||
}
|
||||
|
||||
return new ValueProviderFactoryContext(
|
||||
|
|
|
|||
|
|
@ -6,13 +6,14 @@ using System.Collections.Generic;
|
|||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
using Microsoft.Framework.Primitives;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding.Test
|
||||
{
|
||||
public class JQueryFormValueProviderFactoryTest
|
||||
{
|
||||
private static readonly IDictionary<string, string[]> _backingStore = new Dictionary<string, string[]>
|
||||
private static readonly IDictionary<string, StringValues> _backingStore = new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "[]", new[] { "found" } },
|
||||
{ "[]property1", new[] { "found" } },
|
||||
|
|
@ -115,14 +116,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
|
|||
|
||||
private static ValueProviderFactoryContext CreateContext(
|
||||
string contentType,
|
||||
IDictionary<string, string[]> formValues)
|
||||
IDictionary<string, StringValues> formValues)
|
||||
{
|
||||
var context = new DefaultHttpContext();
|
||||
context.Request.ContentType = contentType;
|
||||
|
||||
if (context.Request.HasFormContentType)
|
||||
{
|
||||
context.Request.Form = new FormCollection(formValues ?? new Dictionary<string, string[]>());
|
||||
context.Request.Form = new FormCollection(formValues ?? new Dictionary<string, StringValues>());
|
||||
}
|
||||
|
||||
return new ValueProviderFactoryContext(
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Microsoft.Framework.Primitives;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
{
|
||||
|
|
@ -10,7 +11,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
{
|
||||
protected override IEnumerableValueProvider GetEnumerableValueProvider(
|
||||
BindingSource bindingSource,
|
||||
IDictionary<string, string[]> values,
|
||||
IDictionary<string, StringValues> values,
|
||||
CultureInfo culture)
|
||||
{
|
||||
return new JQueryFormValueProvider(bindingSource, values, culture);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
using Microsoft.Framework.Primitives;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
{
|
||||
|
|
@ -11,7 +12,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
{
|
||||
protected override IEnumerableValueProvider GetEnumerableValueProvider(
|
||||
BindingSource bindingSource,
|
||||
IDictionary<string, string[]> values,
|
||||
IDictionary<string, StringValues> values,
|
||||
CultureInfo culture)
|
||||
{
|
||||
var backingStore = new ReadableStringCollection(values);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
cache.OnActionExecuting(context);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("no-store", context.HttpContext.Response.Headers.Get("Cache-control"));
|
||||
Assert.Equal("no-store", context.HttpContext.Response.Headers["Cache-control"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -157,7 +157,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
cache.OnActionExecuting(context);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(output, context.HttpContext.Response.Headers.Get("Cache-control"));
|
||||
Assert.Equal(output, context.HttpContext.Response.Headers["Cache-control"]);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> NoStoreData
|
||||
|
|
@ -205,7 +205,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
cache.OnActionExecuting(context);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(output, context.HttpContext.Response.Headers.Get("Cache-control"));
|
||||
Assert.Equal(output, context.HttpContext.Response.Headers["Cache-control"]);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> VaryData
|
||||
|
|
@ -275,8 +275,8 @@ namespace Microsoft.AspNet.Mvc
|
|||
cache.OnActionExecuting(context);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(varyOutput, context.HttpContext.Response.Headers.Get("Vary"));
|
||||
Assert.Equal(cacheControlOutput, context.HttpContext.Response.Headers.Get("Cache-control"));
|
||||
Assert.Equal(varyOutput, context.HttpContext.Response.Headers["Vary"]);
|
||||
Assert.Equal(cacheControlOutput, context.HttpContext.Response.Headers["Cache-control"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -294,8 +294,8 @@ namespace Microsoft.AspNet.Mvc
|
|||
cache.OnActionExecuting(context);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("no-store,no-cache", context.HttpContext.Response.Headers.Get("Cache-control"));
|
||||
Assert.Equal("no-cache", context.HttpContext.Response.Headers.Get("Pragma"));
|
||||
Assert.Equal("no-store,no-cache", context.HttpContext.Response.Headers["Cache-control"]);
|
||||
Assert.Equal("no-cache", context.HttpContext.Response.Headers["Pragma"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -339,7 +339,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
cache.OnActionExecuting(context);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("public,max-age=20", context.HttpContext.Response.Headers.Get("Cache-control"));
|
||||
Assert.Equal("public,max-age=20", context.HttpContext.Response.Headers["Cache-control"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -359,7 +359,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
cache.OnActionExecuting(context);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("private,max-age=10", context.HttpContext.Response.Headers.Get("Cache-control"));
|
||||
Assert.Equal("private,max-age=10", context.HttpContext.Response.Headers["Cache-control"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -379,7 +379,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
cache.OnActionExecuting(context);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("public,max-age=10", context.HttpContext.Response.Headers.Get("Cache-control"));
|
||||
Assert.Equal("public,max-age=10", context.HttpContext.Response.Headers["Cache-control"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -399,7 +399,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
cache.OnActionExecuting(context);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Test", context.HttpContext.Response.Headers.Get("Vary"));
|
||||
Assert.Equal("Test", context.HttpContext.Response.Headers["Vary"]);
|
||||
}
|
||||
|
||||
private ActionExecutingContext GetActionExecutingContext(List<IFilterMetadata> filters = null)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"warningsAsErrors": "true"
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Http": "1.0.0-*",
|
||||
"Microsoft.AspNet.Mvc": "6.0.0-*",
|
||||
"Microsoft.AspNet.Mvc.TestCommon": {
|
||||
"version": "6.0.0-*",
|
||||
|
|
|
|||
|
|
@ -186,10 +186,9 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
.Callback<CorsResult, HttpResponse>((result1, response1) =>
|
||||
{
|
||||
var headers = response1.Headers;
|
||||
headers.Set(
|
||||
CorsConstants.AccessControlMaxAge,
|
||||
result1.PreflightMaxAge.Value.TotalSeconds.ToString());
|
||||
headers.Add(CorsConstants.AccessControlAllowOrigin, new[] { result1.AllowedOrigin });
|
||||
headers[CorsConstants.AccessControlMaxAge] =
|
||||
result1.PreflightMaxAge.Value.TotalSeconds.ToString();
|
||||
headers[CorsConstants.AccessControlAllowOrigin] = result1.AllowedOrigin;
|
||||
if (result1.SupportsCredentials)
|
||||
{
|
||||
headers.Add(CorsConstants.AccessControlAllowCredentials, new[] { "true" });
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"warningsAsErrors": "true"
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Http": "1.0.0-*",
|
||||
"Microsoft.AspNet.Mvc": "6.0.0-*",
|
||||
"Microsoft.AspNet.Mvc.Formatters.Xml" : "6.0.0-*",
|
||||
"Microsoft.AspNet.Mvc.TestCommon": { "version": "6.0.0-*", "type": "build" },
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"warningsAsErrors": "true"
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Http": "1.0.0-*",
|
||||
"Microsoft.AspNet.Mvc": "6.0.0-*",
|
||||
"Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*",
|
||||
"Microsoft.AspNet.Mvc.TestCommon": { "version": "6.0.0-*", "type": "build" },
|
||||
|
|
|
|||
|
|
@ -621,7 +621,7 @@ namespace Microsoft.AspNet.Mvc.Formatters.Xml
|
|||
{
|
||||
var request = new Mock<HttpRequest>();
|
||||
|
||||
var headers = new HeaderDictionary(new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase));
|
||||
var headers = new HeaderDictionary();
|
||||
headers["Accept-Charset"] = MediaTypeHeaderValue.Parse(contentType).Charset;
|
||||
request.Setup(r => r.ContentType).Returns(contentType);
|
||||
request.SetupGet(r => r.Headers).Returns(headers);
|
||||
|
|
|
|||
|
|
@ -375,7 +375,7 @@ namespace Microsoft.AspNet.Mvc.Formatters.Xml
|
|||
{
|
||||
var request = new Mock<HttpRequest>();
|
||||
|
||||
var headers = new HeaderDictionary(new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase));
|
||||
var headers = new HeaderDictionary();
|
||||
headers["Accept-Charset"] = MediaTypeHeaderValue.Parse(contentType).Charset;
|
||||
request.Setup(r => r.ContentType).Returns(contentType);
|
||||
request.SetupGet(r => r.Headers).Returns(headers);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"warningsAsErrors": "true"
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Http": "1.0.0-*",
|
||||
"Microsoft.AspNet.Mvc" : "6.0.0-*",
|
||||
"Microsoft.AspNet.Mvc.Formatters.Xml" : "6.0.0-*",
|
||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||
|
|
|
|||
|
|
@ -68,12 +68,12 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
|
||||
var filters = response.Headers.GetValues("filters").Single().Split(',');
|
||||
var filters = response.Headers.GetValues("filters").ToArray();
|
||||
|
||||
var i = 0;
|
||||
foreach (var filter in filters)
|
||||
{
|
||||
Assert.Equal(filter, expected[i++]);
|
||||
Assert.Equal(expected[i++], filter);
|
||||
}
|
||||
|
||||
Assert.Equal(expected.Length, filters.Length);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.Framework.Primitives;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.IntegrationTests
|
||||
|
|
@ -604,7 +605,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
|
||||
var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request =>
|
||||
{
|
||||
var formCollection = new FormCollection(new Dictionary<string, string[]>()
|
||||
var formCollection = new FormCollection(new Dictionary<string, StringValues>()
|
||||
{
|
||||
{ "Addresses.index", new [] { "Key1", "Key2" } },
|
||||
{ "Addresses[Key1].Street", new [] { "Street1" } },
|
||||
|
|
@ -663,7 +664,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
|
||||
var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request =>
|
||||
{
|
||||
var formCollection = new FormCollection(new Dictionary<string, string[]>()
|
||||
var formCollection = new FormCollection(new Dictionary<string, StringValues>()
|
||||
{
|
||||
{ "Addresses.index", new [] { "Key1" } },
|
||||
{ "Addresses[Key1].Street", new [] { "Street1" } },
|
||||
|
|
@ -733,15 +734,15 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
}
|
||||
|
||||
// parameter type, form content, expected type
|
||||
public static TheoryData<Type, IDictionary<string, string[]>, Type> CollectionTypeData
|
||||
public static TheoryData<Type, IDictionary<string, StringValues>, Type> CollectionTypeData
|
||||
{
|
||||
get
|
||||
{
|
||||
return new TheoryData<Type, IDictionary<string, string[]>, Type>
|
||||
return new TheoryData<Type, IDictionary<string, StringValues>, Type>
|
||||
{
|
||||
{
|
||||
typeof(IEnumerable<string>),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "[0]", new[] { "hello" } },
|
||||
{ "[1]", new[] { "world" } },
|
||||
|
|
@ -750,7 +751,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(ICollection<string>),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "index", new[] { "low", "high" } },
|
||||
{ "[low]", new[] { "hello" } },
|
||||
|
|
@ -760,7 +761,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(IList<string>),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "[0]", new[] { "hello" } },
|
||||
{ "[1]", new[] { "world" } },
|
||||
|
|
@ -769,7 +770,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(List<string>),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "index", new[] { "low", "high" } },
|
||||
{ "[low]", new[] { "hello" } },
|
||||
|
|
@ -779,7 +780,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(ClosedGenericCollection),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "[0]", new[] { "hello" } },
|
||||
{ "[1]", new[] { "world" } },
|
||||
|
|
@ -788,7 +789,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(ClosedGenericList),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "index", new[] { "low", "high" } },
|
||||
{ "[low]", new[] { "hello" } },
|
||||
|
|
@ -798,7 +799,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(ExplicitClosedGenericCollection),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "[0]", new[] { "hello" } },
|
||||
{ "[1]", new[] { "world" } },
|
||||
|
|
@ -807,7 +808,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(ExplicitClosedGenericList),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "index", new[] { "low", "high" } },
|
||||
{ "[low]", new[] { "hello" } },
|
||||
|
|
@ -817,7 +818,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(ExplicitCollection<string>),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "[0]", new[] { "hello" } },
|
||||
{ "[1]", new[] { "world" } },
|
||||
|
|
@ -826,7 +827,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(ExplicitList<string>),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "index", new[] { "low", "high" } },
|
||||
{ "[low]", new[] { "hello" } },
|
||||
|
|
@ -836,7 +837,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(IEnumerable<string>),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ string.Empty, new[] { "hello", "world" } },
|
||||
},
|
||||
|
|
@ -844,7 +845,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(ICollection<string>),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "[]", new[] { "hello", "world" } },
|
||||
},
|
||||
|
|
@ -852,7 +853,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(IList<string>),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ string.Empty, new[] { "hello", "world" } },
|
||||
},
|
||||
|
|
@ -860,7 +861,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(List<string>),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "[]", new[] { "hello", "world" } },
|
||||
},
|
||||
|
|
@ -868,7 +869,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(ClosedGenericCollection),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ string.Empty, new[] { "hello", "world" } },
|
||||
},
|
||||
|
|
@ -876,7 +877,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(ClosedGenericList),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "[]", new[] { "hello", "world" } },
|
||||
},
|
||||
|
|
@ -884,7 +885,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(ExplicitClosedGenericCollection),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ string.Empty, new[] { "hello", "world" } },
|
||||
},
|
||||
|
|
@ -892,7 +893,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(ExplicitClosedGenericList),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "[]", new[] { "hello", "world" } },
|
||||
},
|
||||
|
|
@ -900,7 +901,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(ExplicitCollection<string>),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ string.Empty, new[] { "hello", "world" } },
|
||||
},
|
||||
|
|
@ -908,7 +909,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
},
|
||||
{
|
||||
typeof(ExplicitList<string>),
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "[]", new[] { "hello", "world" } },
|
||||
},
|
||||
|
|
@ -922,7 +923,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
[MemberData(nameof(CollectionTypeData))]
|
||||
public async Task CollectionModelBinder_BindsParameterToExpectedType(
|
||||
Type parameterType,
|
||||
IDictionary<string, string[]> formContent,
|
||||
IDictionary<string, StringValues> formContent,
|
||||
Type expectedType)
|
||||
{
|
||||
// Arrange
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using Microsoft.AspNet.Http;
|
|||
using Microsoft.AspNet.Http.Features.Internal;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.Framework.Primitives;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.IntegrationTests
|
||||
|
|
@ -163,7 +164,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
private void UpdateRequest(HttpRequest request, string data, string name)
|
||||
{
|
||||
var fileCollection = new FormFileCollection();
|
||||
var formCollection = new FormCollection(new Dictionary<string, string[]>(), fileCollection);
|
||||
var formCollection = new FormCollection(new Dictionary<string, StringValues>(), fileCollection);
|
||||
var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(data));
|
||||
|
||||
request.Form = formCollection;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using Microsoft.AspNet.Http;
|
|||
using Microsoft.AspNet.Http.Features.Internal;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.Framework.Primitives;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.IntegrationTests
|
||||
|
|
@ -164,7 +165,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
private void UpdateRequest(HttpRequest request, string data, string name)
|
||||
{
|
||||
var fileCollection = new FormFileCollection();
|
||||
var formCollection = new FormCollection(new Dictionary<string, string[]>(), fileCollection);
|
||||
var formCollection = new FormCollection(new Dictionary<string, StringValues>(), fileCollection);
|
||||
|
||||
request.Form = formCollection;
|
||||
request.ContentType = "multipart/form-data; boundary=----WebKitFormBoundarymx2fSWqWSd0OxQqq";
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using Microsoft.AspNet.Http;
|
|||
using Microsoft.AspNet.Http.Features.Internal;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.Framework.Primitives;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.IntegrationTests
|
||||
|
|
@ -2129,7 +2130,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
private static void SetFormFileBodyContent(HttpRequest request, string content, string name)
|
||||
{
|
||||
var fileCollection = new FormFileCollection();
|
||||
var formCollection = new FormCollection(new Dictionary<string, string[]>(), fileCollection);
|
||||
var formCollection = new FormCollection(new Dictionary<string, StringValues>(), fileCollection);
|
||||
var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(content));
|
||||
|
||||
request.Form = formCollection;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Internal;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.Framework.Primitives;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.IntegrationTests
|
||||
|
|
@ -366,19 +367,19 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
Assert.Empty(modelState.Keys);
|
||||
}
|
||||
|
||||
public static TheoryData<IDictionary<string, string[]>> PersonStoreData
|
||||
public static TheoryData<IDictionary<string, StringValues>> PersonStoreData
|
||||
{
|
||||
get
|
||||
{
|
||||
return new TheoryData<IDictionary<string, string[]>>
|
||||
return new TheoryData<IDictionary<string, StringValues>>
|
||||
{
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "name", new[] { "Fred" } },
|
||||
{ "address.zip", new[] { "98052" } },
|
||||
{ "address.lines", new[] { "line 1", "line 2" } },
|
||||
},
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "address.lines[]", new[] { "line 1", "line 2" } },
|
||||
{ "address[].zip", new[] { "98052" } },
|
||||
|
|
@ -390,7 +391,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
|
|||
|
||||
[Theory]
|
||||
[MemberData(nameof(PersonStoreData))]
|
||||
public async Task BindParameter_FromFormData_BindsCorrectly(IDictionary<string, string[]> personStore)
|
||||
public async Task BindParameter_FromFormData_BindsCorrectly(IDictionary<string, StringValues> personStore)
|
||||
{
|
||||
// Arrange
|
||||
var argumentBinder = ModelBindingTestHelper.GetArgumentBinder();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"warningsAsErrors": "true"
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Http": "1.0.0-*",
|
||||
"Microsoft.AspNet.Mvc": "6.0.0-*",
|
||||
"Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*",
|
||||
"Microsoft.AspNet.Mvc.TestCommon": {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"warningsAsErrors": "true"
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Http": "1.0.0-*",
|
||||
"Microsoft.AspNet.Mvc": "6.0.0-*",
|
||||
"Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*",
|
||||
"Microsoft.AspNet.Mvc.TestCommon": { "version": "6.0.0-*", "type": "build" },
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShimTest
|
|||
// Assert
|
||||
Assert.True(httpContext.Response.Headers.ContainsKey(transferEncodingHeaderKey));
|
||||
Assert.Equal(new string[] { "identity", "chunked" },
|
||||
httpContext.Response.Headers.GetValues(transferEncodingHeaderKey));
|
||||
httpContext.Response.Headers[transferEncodingHeaderKey]);
|
||||
Assert.NotNull(httpContext.Response.ContentLength);
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +141,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShimTest
|
|||
// Assert
|
||||
Assert.True(httpContext.Response.Headers.ContainsKey(transferEncodingHeaderKey));
|
||||
Assert.Equal(new string[] { "identity", "chunked" },
|
||||
httpContext.Response.Headers.GetValues(transferEncodingHeaderKey));
|
||||
httpContext.Response.Headers[transferEncodingHeaderKey]);
|
||||
Assert.NotNull(httpContext.Response.ContentLength);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ namespace CustomRouteWebSite
|
|||
private string GetLocale(HttpContext context)
|
||||
{
|
||||
string locale;
|
||||
_users.TryGetValue(context.Request.Headers.Get("User"), out locale);
|
||||
_users.TryGetValue(context.Request.Headers["User"], out locale);
|
||||
return locale;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
|
||||
namespace FiltersWebSite
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
|
||||
namespace FiltersWebSite
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
|
||||
namespace FiltersWebSite
|
||||
|
|
|
|||
|
|
@ -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 Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
|
||||
namespace FiltersWebSite
|
||||
|
|
|
|||
|
|
@ -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 Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
|
||||
namespace FiltersWebSite
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
|
||||
namespace FiltersWebSite
|
||||
|
|
|
|||
|
|
@ -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 Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
|
||||
namespace FiltersWebSite
|
||||
|
|
|
|||
|
|
@ -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 Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
|
||||
namespace FiltersWebSite
|
||||
|
|
|
|||
|
|
@ -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 Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
|
||||
namespace FiltersWebSite
|
||||
|
|
|
|||
|
|
@ -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 Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
|
||||
namespace FiltersWebSite
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
|
||||
namespace FiltersWebSite
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Framework.Primitives;
|
||||
|
||||
namespace LoggingWebSite
|
||||
{
|
||||
|
|
@ -22,10 +21,10 @@ namespace LoggingWebSite
|
|||
|
||||
public string Protocol { get; set; }
|
||||
|
||||
public IEnumerable<KeyValuePair<string, string[]>> Headers { get; set; }
|
||||
public IEnumerable<KeyValuePair<string, StringValues>> Headers { get; set; }
|
||||
|
||||
public string Query { get; set; }
|
||||
|
||||
public IEnumerable<KeyValuePair<string, string[]>> Cookies { get; set; }
|
||||
public IEnumerable<KeyValuePair<string, StringValues>> Cookies { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ namespace ModelBindingWebSite.Controllers
|
|||
// Doing something slightly different here to make sure we don't get accidentally bound
|
||||
// by the type converter binder.
|
||||
OrderStatus model;
|
||||
var isModelSet = Enum.TryParse<OrderStatus>("Status" + request.Query.Get("status"), out model);
|
||||
var isModelSet = Enum.TryParse<OrderStatus>("Status" + request.Query["status"], out model);
|
||||
var validationNode =
|
||||
new ModelValidationNode(bindingContext.ModelName, bindingContext.ModelMetadata, model);
|
||||
return Task.FromResult(new ModelBindingResult(model, "status", isModelSet, validationNode));
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using Microsoft.AspNet.Http;
|
|||
using Microsoft.AspNet.Http.Internal;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.Framework.Primitives;
|
||||
using ModelBindingWebSite.Models;
|
||||
|
||||
namespace ModelBindingWebSite.Controllers
|
||||
|
|
@ -107,7 +108,7 @@ namespace ModelBindingWebSite.Controllers
|
|||
public async Task<Employee> GetEmployeeAsync_BindToBaseDeclaredType()
|
||||
{
|
||||
var backingStore = new ReadableStringCollection(
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "Parent.Name", new[] { "fatherName"} },
|
||||
{ "Parent.Parent.Name", new[] {"grandFatherName" } },
|
||||
|
|
@ -131,7 +132,7 @@ namespace ModelBindingWebSite.Controllers
|
|||
public async Task<User> GetUserAsync_ModelType_IncludeAll(int id)
|
||||
{
|
||||
var backingStore = new ReadableStringCollection(
|
||||
new Dictionary<string, string[]>
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
{ "Key", new[] { "123"} },
|
||||
{ "RegisterationMonth", new[] {"March" } },
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace ResponseCacheWebSite
|
|||
[ResponseCache(Duration = 40)]
|
||||
public IActionResult SetHeadersInAction()
|
||||
{
|
||||
Response.Headers.Set("Cache-control", "max-age=10");
|
||||
Response.Headers["Cache-control"] = "max-age=10";
|
||||
return Content("Hello World!");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace VersioningWebSite
|
|||
|
||||
public static string GetVersion(HttpRequest request)
|
||||
{
|
||||
return request.Query.Get("version");
|
||||
return request.Query["version"];
|
||||
}
|
||||
|
||||
public bool Accept(ActionConstraintContext context)
|
||||
|
|
|
|||
Loading…
Reference in New Issue