public void GivenActorParameter_ValidateString_ReturnsValidMethodName(string queryProperty, string queryValue, ActorQueryParameters parameterObject) { // Arrange var logger = new Mock <ILogger <ActorsController> >(); var mockIDAL = new Mock <IDAL>(); var controller = new ActorsController(logger.Object, mockIDAL.Object) { ControllerContext = new ControllerContext() }; var request = new Dictionary <string, StringValues> { { queryProperty, queryValue } }; var queryCollection = new QueryCollection(request); var query = new QueryFeature(queryCollection); var features = new FeatureCollection(); features.Set <IQueryFeature>(query); controller.ControllerContext.HttpContext = new DefaultHttpContext(features); // Act var expectedResult = $"GetActors:{queryProperty}:{queryValue}"; var actualResult = parameterObject.GetMethodText(controller.HttpContext); // Assert Assert.Equal(expectedResult, actualResult); }
internal void RegisterQueryFeature(Type channelType, Type queryFeatureType, QueryFeature qf) { Known(channelType); var channeId = channelType.FullName; if (!_channelFeaturesQuery.ContainsKey(channeId)) { _channelFeaturesQuery[channeId] = new Dictionary <string, QueryFeature>(); } var features = _channelFeaturesQuery[channeId]; var featureId = queryFeatureType.FullName; if (!features.ContainsKey(featureId)) { features[featureId] = qf; } else { throw new TectureException($"Query feature {queryFeatureType.Name} is already implemented for {channelType.Name}"); } qf._aux = _auxilary.ForChannel(channelType); qf.CallOnRegister(); }
public void ParseEmptyOrNullQueryWorks(string queryString) { var features = new FeatureCollection(); features[typeof(IHttpRequestFeature)] = new HttpRequestFeature { QueryString = queryString }; var provider = new QueryFeature(features); var queryCollection = provider.Query; Assert.Empty(queryCollection); }
public void EmptyKeysNotAddedToQueryCollection(string queryString) { var features = new FeatureCollection(); features[typeof(IHttpRequestFeature)] = new HttpRequestFeature { QueryString = queryString }; var provider = new QueryFeature(features); var queryCollection = provider.Query; Assert.Equal(0, queryCollection.Count); }
public void ParseQueryWithEncodedKeyEncodedValuesWorks() { var features = new FeatureCollection(); features[typeof(IHttpRequestFeature)] = new HttpRequestFeature { QueryString = "?fields+%5BtodoItems%5D=%5B+1+%5D&fields+%5BtodoItems%5D=%5B+2+%5D" }; var provider = new QueryFeature(features); var queryCollection = provider.Query; Assert.Single(queryCollection); Assert.Equal(new[] { "[ 1 ]", "[ 2 ]" }, queryCollection["fields [todoItems]"]); }
public void ParseQueryWithEncodedKeyEmptyValueWorks() { var features = new FeatureCollection(); features[typeof(IHttpRequestFeature)] = new HttpRequestFeature { QueryString = "?fields+%5BtodoItems%5D=" }; var provider = new QueryFeature(features); var queryCollection = provider.Query; Assert.Single(queryCollection); Assert.Equal("", queryCollection["fields [todoItems]"].FirstOrDefault()); }
public void KeyWithoutValuesAddedToQueryCollection(string queryString, string emptyParam) { var features = new FeatureCollection(); features[typeof(IHttpRequestFeature)] = new HttpRequestFeature { QueryString = queryString }; var provider = new QueryFeature(features); var queryCollection = provider.Query; Assert.True(queryCollection.Keys.Contains(emptyParam)); Assert.Equal(string.Empty, queryCollection[emptyParam]); }
public void ParseQueryWithEmptyKeyWorks() { var features = new FeatureCollection(); features[typeof(IHttpRequestFeature)] = new HttpRequestFeature { QueryString = "?=value1&=" }; var provider = new QueryFeature(features); var queryCollection = provider.Query; Assert.Single(queryCollection); Assert.Equal(new[] { "value1", "" }, queryCollection[""]); }
public void ParseQueryWithEmptyValuesWorks() { var features = new FeatureCollection(); features[typeof(IHttpRequestFeature)] = new HttpRequestFeature { QueryString = "?key1=&key2=" }; var provider = new QueryFeature(features); var queryCollection = provider.Query; Assert.Equal(2, queryCollection.Count); Assert.Equal(string.Empty, queryCollection["key1"].FirstOrDefault()); Assert.Equal(string.Empty, queryCollection["key2"].FirstOrDefault()); }
public void ParseQueryWithThreefoldKeysGroups() { var features = new FeatureCollection(); features[typeof(IHttpRequestFeature)] = new HttpRequestFeature { QueryString = "?key1=valueA&key2=valueB&key1=valueC&key1=valueD" }; var provider = new QueryFeature(features); var queryCollection = provider.Query; Assert.Equal(2, queryCollection.Count); Assert.Equal(new[] { "valueA", "valueC", "valueD" }, queryCollection["key1"]); Assert.Equal("valueB", queryCollection["key2"].FirstOrDefault()); }
public void CaseInsensitiveWithFewKeys() { // need to use less than 10 keys to test array storage code path var features = new FeatureCollection(); features[typeof(IHttpRequestFeature)] = new HttpRequestFeature { QueryString = "?key=1&Key=2&key=3&Key=4&KEy=5" }; var provider = new QueryFeature(features); var queryCollection = provider.Query; Assert.Equal(1, queryCollection.Count); Assert.Equal(new[] { "1", "2", "3", "4", "5" }, queryCollection["KEY"]); }
public void ParseQueryWithUniqueKeysWorks(string queryString) { var features = new FeatureCollection(); features[typeof(IHttpRequestFeature)] = new HttpRequestFeature { QueryString = queryString }; var provider = new QueryFeature(features); var queryCollection = provider.Query; Assert.Equal(2, queryCollection.Count); Assert.Equal("value1", queryCollection["key1"].FirstOrDefault()); Assert.Equal("value2", queryCollection["key2"].FirstOrDefault()); }
public void SampleTest() { // var testTempData = new Mock<ITempDataDictionary>(); // testTempData // .SetupSet(dictionary => dictionary["myTestItem"] = It.IsAny<object>()) // .Throws<Exception>(); var logger = new Mock <ILogger <HomeController> >(); var context = new DefaultHttpContext(); var controller = new HomeController(logger.Object) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() } }; var formContent = new Dictionary <string, StringValues> { { "kam", "*****@*****.**" } }; var formCollection = new FormCollection(formContent); var formFeature = new FormFeature(formCollection); var queryContent = new Dictionary <string, StringValues> { { "first", "kam" }, { "second", "lagan" } }; var queryFeature = new QueryFeature(new QueryCollection(queryContent)); controller.ControllerContext.HttpContext.Request.Headers["x-name"] = "kam"; controller.ControllerContext.HttpContext.Features.Set <IFormFeature>(formFeature); controller.ControllerContext.HttpContext.Features.Set <IQueryFeature>(queryFeature); var result = controller.Index(); var response = result as ViewResult; Assert.NotNull(response); Assert.Same("Index", response.ViewName); Assert.Same($"kam testing", controller.ViewData["Message"]); }
public void QueryReturnsParsedQueryCollection() { // Arrange var features = new FeatureCollection(); features[typeof(IHttpRequestFeature)] = new HttpRequestFeature { QueryString = "foo=bar" }; var provider = new QueryFeature(features); // Act var queryCollection = provider.Query; // Assert Assert.Equal("bar", queryCollection["foo"]); }
public void CaseInsensitiveWithManyKeys() { // need to use over 10 keys to test dictionary storage code path var features = new FeatureCollection(); features[typeof(IHttpRequestFeature)] = new HttpRequestFeature { QueryString = "?a=0&b=0&c=1&d=2&e=3&f=4&g=5&h=6&i=7&j=8&k=9&" + "key=1&Key=2&key=3&Key=4&KEy=5&KEY=6&kEY=7&KeY=8&kEy=9&keY=10" }; var provider = new QueryFeature(features); var queryCollection = provider.Query; Assert.Equal(12, queryCollection.Count); Assert.Equal(new[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }, queryCollection["KEY"]); }
public void QueryReturnsParsedQueryCollection() { // Arrange var features = new Mock<IFeatureCollection>(); var request = new Mock<IHttpRequestFeature>(); request.SetupGet(r => r.QueryString).Returns("foo=bar"); object value = request.Object; features.Setup(f => f.TryGetValue(typeof(IHttpRequestFeature), out value)) .Returns(true); var provider = new QueryFeature(features.Object); // Act var queryCollection = provider.Query; // Assert Assert.Equal("bar", queryCollection["foo"]); }
public void QueryReturnsParsedQueryCollection() { // Arrange var features = new Mock<IFeatureCollection>(); var request = new Mock<IHttpRequestFeature>(); request.SetupGet(r => r.QueryString).Returns("foo=bar"); object value = request.Object; features.Setup(f => f.TryGetValue(typeof(IHttpRequestFeature), out value)) .Returns(true); var provider = new QueryFeature(features.Object); // Act var queryCollection = provider.Query; // Assert Assert.Equal("bar", queryCollection["foo"]); }
public void GetKey_ReturnsFirstKey1(string[] values) { // Arrange var keyProvider = new QueryStringApiKeyProvider("apikey"); var queryFeature = new QueryFeature(new QueryCollection(new Dictionary <string, StringValues>(StringComparer.OrdinalIgnoreCase) { { "apikey", values } })); var context = new DefaultHttpContext(); context.Features[typeof(IQueryFeature)] = queryFeature; // Act var result = keyProvider.GetApiKey(context); // Assert Assert.NotNull(result); Assert.Equal(values[0], result); }
private static NameValueCollection GetQueryString(IFeatureCollection feature) { NameValueCollection query = new NameValueCollection(); var requestfeature = feature.Get <IQueryFeature>(); if (requestfeature == null) { requestfeature = new QueryFeature(feature); } if (requestfeature.Query != null && requestfeature.Query.Any()) { foreach (var item in requestfeature.Query) { query.Add(item.Key, item.Value); } } return(query); }
public void ParseNewEncoded() { _ = QueryFeature.ParseNullableQueryInternal(_encoded); }
public void ParseNewSingleWithPlus() { _ = QueryFeature.ParseNullableQueryInternal(_singleValueWithPlus); }
public void ParseNew() { _ = QueryFeature.ParseNullableQueryInternal(_queryString); }
public void RegisterQueryFeature(Type queryFeatureType, QueryFeature feature) { _multiplexer.RegisterQueryFeature(_channelType, queryFeatureType, feature); }