public void ParseQueryString_Null() { // Act NameValueCollection result = QueryStringValueProvider.ParseQueryString(null); // Assert Assert.Equal(0, result.Count); }
public void ParseQueryString_MultipleValuesForSingleName() { // Arrange Uri uri = new Uri("http://localhost/?key1=value1&key1=value2"); // Act NameValueCollection result = QueryStringValueProvider.ParseQueryString(uri); // Assert Assert.Equal("value1,value2", result["key1"]); Assert.Equal(new[] { "value1", "value2" }, result.GetValues("key1")); }
public void ParseQueryString_EncodedUrlValues() { // Arrange Uri uri = new Uri("http://localhost/?key%31=value%31"); // Act NameValueCollection result = QueryStringValueProvider.ParseQueryString(uri); // Assert Assert.Single(result); Assert.Equal("value1", result["key1"]); }
public void ParseQueryString_LeadingAmpersand() { // Arrange Uri uri = new Uri("http://localhost/?&key1=value1"); // Act NameValueCollection result = QueryStringValueProvider.ParseQueryString(uri); // Assert Assert.Equal(2, result.Count); Assert.Equal("value1", result["key1"]); Assert.Equal("", result[""]); }
public void ParseQueryString_TwoNamedValues() { // Arrange Uri uri = new Uri("http://localhost/?key1=value1&key2=value2"); // Act NameValueCollection result = QueryStringValueProvider.ParseQueryString(uri); // Assert Assert.Equal(2, result.Count); Assert.Equal("value1", result["key1"]); Assert.Equal("value2", result["key2"]); }
public void ParseQueryString_SingleNamedValue() { // Arrange Uri uri = new Uri("http://localhost/?key1=value1"); // Act NameValueCollection result = QueryStringValueProvider.ParseQueryString(uri); // Assert string key = Assert.Single(result) as string; Assert.Equal("key1", key); Assert.Equal("value1", result[key]); }
public void ParseQueryString_IntermediateDoubleAmpersand() { // Arrange Uri uri = new Uri("http://localhost/?key1=value1&&key2=value2"); // Act NameValueCollection result = QueryStringValueProvider.ParseQueryString(uri); // Assert Assert.Equal(3, result.Count); Assert.Equal("value1", result["key1"]); Assert.Equal("value2", result["key2"]); Assert.Equal("", result[""]); }
/// <summary> /// Asynchronously executes the binding for the given request. /// </summary> /// <returns> /// A task object representing the asynchronous operation. /// </returns> /// <param name="metadataProvider">Metadata provider to use for validation.</param> /// <param name="actionContext">The action context for the binding. The action context contains the parameter dictionary that will get populated with the parameter.</param> /// <param name="cancellationToken">Cancellation token for cancelling the binding operation.</param> public override Task ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken) { // TODO: 本当はどうやってやるべきなのかがわからない… var queryString = new QueryStringValueProvider(actionContext, CultureInfo.CurrentCulture); var parameterName = Descriptor.ParameterName; var value = queryString.GetValue(parameterName).Maybe(x => x.AttemptedValue) ?? actionContext.ControllerContext.RouteData.Values[parameterName] as string; Version version; if (Version.TryParse(value, out version)) { SetValue(actionContext, version); } return _completed; }
public override IValueProvider GetValueProvider(HttpActionContext actionContext) { if (actionContext == null) { throw Error.ArgumentNull("actionContext"); } // Only parse the query string once-per request. QueryStringValueProvider provider; IDictionary <string, object> storage = actionContext.Request.Properties; if (!storage.TryGetValue(RequestLocalStorageKey, out provider)) { provider = new QueryStringValueProvider(actionContext, CultureInfo.InvariantCulture); storage[RequestLocalStorageKey] = provider; } return(provider); }
public override IValueProvider GetValueProvider(HttpActionContext actionContext) { if (actionContext == null) { throw Error.ArgumentNull("actionContext"); } // Only parse the query string once-per request. QueryStringValueProvider provider; IDictionary<string, object> storage = actionContext.Request.Properties; if (!storage.TryGetValue(RequestLocalStorageKey, out provider)) { provider = new QueryStringValueProvider(actionContext, CultureInfo.InvariantCulture); storage[RequestLocalStorageKey] = provider; } return provider; }