diff --git a/src/Microsoft.AspNet.PipelineCore/DefaultCanHasQuery.cs b/src/Microsoft.AspNet.PipelineCore/DefaultCanHasQuery.cs index fa3069d427..9a3e45e5fb 100644 --- a/src/Microsoft.AspNet.PipelineCore/DefaultCanHasQuery.cs +++ b/src/Microsoft.AspNet.PipelineCore/DefaultCanHasQuery.cs @@ -27,8 +27,7 @@ namespace Microsoft.AspNet.PipelineCore if (_query == null || _queryString != queryString) { _queryString = queryString; - // TODO - _query = new ReadableStringCollection(new Dictionary()); + _query = new ReadableStringCollection(ParsingHelpers.GetQuery(queryString)); } return _query; } diff --git a/src/Microsoft.AspNet.PipelineCore/Infrastructure/ParsingHelpers.cs b/src/Microsoft.AspNet.PipelineCore/Infrastructure/ParsingHelpers.cs index 91254955f7..18153db162 100644 --- a/src/Microsoft.AspNet.PipelineCore/Infrastructure/ParsingHelpers.cs +++ b/src/Microsoft.AspNet.PipelineCore/Infrastructure/ParsingHelpers.cs @@ -1,9 +1,9 @@ -using Microsoft.AspNet.Abstractions; -using Microsoft.AspNet.PipelineCore.Collections; using System; using System.Collections; using System.Collections.Generic; using System.Linq; +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.PipelineCore.Collections; namespace Microsoft.AspNet.PipelineCore.Infrastructure { @@ -799,28 +799,14 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure private static readonly char[] AmpersandAndSemicolon = new[] { '&', ';' }; - internal static IDictionary GetQuery(HttpRequest request) + internal static IDictionary GetQuery(string queryString) { - var query = GetItem>(request, "Microsoft.Owin.Query#dictionary"); - if (query == null) - { - query = new Dictionary(StringComparer.OrdinalIgnoreCase); - SetItem(request, "Microsoft.Owin.Query#dictionary", query); - } - - string text = request.QueryString.Value; - if (GetItem(request, "Microsoft.Owin.Query#text") != text) - { - query.Clear(); - var accumulator = new Dictionary>(StringComparer.OrdinalIgnoreCase); - ParseDelimited(text, AmpersandAndSemicolon, AppendItemCallback, accumulator); - foreach (var kv in accumulator) - { - query.Add(kv.Key, kv.Value.ToArray()); - } - SetItem(request, "Microsoft.Owin.Query#text", text); - } - return query; + var accumulator = new Dictionary>(StringComparer.OrdinalIgnoreCase); + ParseDelimited(queryString, AmpersandAndSemicolon, AppendItemCallback, accumulator); + return accumulator.ToDictionary( + item => item.Key, + item => item.Value.ToArray(), + StringComparer.OrdinalIgnoreCase); } #if !NET40 diff --git a/test/Microsoft.AspNet.PipelineCore.Tests/DefaultCanHasQueryTests.cs b/test/Microsoft.AspNet.PipelineCore.Tests/DefaultCanHasQueryTests.cs new file mode 100644 index 0000000000..5bef67e18d --- /dev/null +++ b/test/Microsoft.AspNet.PipelineCore.Tests/DefaultCanHasQueryTests.cs @@ -0,0 +1,31 @@ +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.HttpFeature; +using Moq; +using Xunit; + +namespace Microsoft.AspNet.PipelineCore.Tests +{ + public class DefaultCanHasQueryTests + { + [Fact] + public void QueryReturnsParsedQueryCollection() + { + // Arrange + var features = new Mock(); + var request = new Mock(); + request.SetupGet(r => r.QueryString).Returns("foo=bar"); + + object value = request.Object; + features.Setup(f => f.TryGetValue(typeof(IHttpRequestInformation), out value)) + .Returns(true); + + var provider = new DefaultCanHasQuery(features.Object); + + // Act + var queryCollection = provider.Query; + + // Assert + Assert.Equal("bar", queryCollection["foo"]); + } + } +}