Esempio n. 1
0
        public void GetQueryStringsFromContext()
        {
#if NETFULL
            var textWriter = new Mock <TextWriter>();
            var request    = new System.Web.HttpRequest("", "http://test.com", "prop1=abc&prop2=123");
            var context    = new System.Web.HttpContext(request, new System.Web.HttpResponse(textWriter.Object));

            System.Web.HttpContext.Current = context;
            var service = new RequestQueryStringService();
#else
            var collection = new Dictionary <string, StringValues>()
            {
                { "prop1", "abc" }, { "prop2", "123" }
            };
            var query = new Microsoft.AspNetCore.Http.Internal.QueryCollection(collection);
            var req   = new Mock <Microsoft.AspNetCore.Http.HttpRequest>();
            req.Setup(c => c.Query).Returns(query);

            var context = new Mock <Microsoft.AspNetCore.Http.HttpContext>();
            context.Setup(c => c.Request).Returns(req.Object);

            var contextAccess = new Mock <Microsoft.AspNetCore.Http.IHttpContextAccessor>();
            contextAccess.Setup(c => c.HttpContext).Returns(context.Object);

            var service = new RequestQueryStringService(contextAccess.Object);
#endif


            var results  = service.GetQueryStrings();
            var expected = new Dictionary <string, string>()
            {
                { "prop1", "abc" }, { "prop2", "123" }
            };
            CollectionAssert.AreEqual(expected, results.ToDictionary(c => c.Key, c => c.Value));
        }
            public void KeyFoundRendersValue()
            {
                var expectedResult = "value";
                var httpContext    = Substitute.For <HttpContextBase>();

#if !ASP_NET_CORE
                httpContext.Request.QueryString.Returns(new NameValueCollection {
                    { "key", expectedResult }
                });
#else
                var queryCollection = new Microsoft.AspNetCore.Http.Internal.QueryCollection(new Dictionary <string, StringValues>()
                {
                    { "key", expectedResult }
                });
                httpContext.Request.Query.Returns(queryCollection);
#endif

                var renderer = new AspNetRequestValueLayoutRenderer();
                renderer.HttpContextAccessor = new FakeHttpContextAccessor(httpContext);
                renderer.QueryString         = "key";

                string result = renderer.Render(new LogEventInfo());

                Assert.Equal(expectedResult, result);
            }
Esempio n. 3
0
        /// <summary>
        /// Applies to.
        /// </summary>
        /// <returns>Applies Dynamic Linq Filtering to an IQueryable using a string QueryString</returns>
        /// <param name="src">Source.</param>
        /// <param name="query">Query.</param>
        /// <typeparam name="TEntity">The 1st type parameter.</typeparam>
        public static IQueryable <TEntity> ApplyTo <TEntity>(this string src, IQueryable <TEntity> query)
        {
            if (string.IsNullOrEmpty(src))
            {
                return(query);
            }
            var dictQueryString = QueryHelpers.ParseQuery(src);
            var queryCollection = new Microsoft.AspNetCore.Http.Internal.QueryCollection(dictQueryString);
            var settings        = getSettings(queryCollection);
            var queryCount      = getItems(query, settings);

            return(queryCount.Items);
        }
Esempio n. 4
0
        public void Init()
        {
#if NETFULL
            request = new System.Net.Http.HttpRequestMessage
            {
                RequestUri = new Uri("http://test.com?prop1=abc&prop2=123")
            };
#else
            var collection = new Dictionary <string, StringValues>()
            {
                { "prop1", "abc" }, { "prop2", "123" }
            };

            var query = new Microsoft.AspNetCore.Http.Internal.QueryCollection(collection);

            var mock = new Mock <Microsoft.AspNetCore.Http.HttpRequest>();
            mock.Setup(c => c.Query).Returns(query);
            request = mock.Object;
#endif
        }
Esempio n. 5
0
 public QueryCollection(Microsoft.AspNetCore.Http.Internal.QueryCollection store)
 {
 }