コード例 #1
0
        public void BuildRouteParameters_Can_Use_Case_Sensitive_Query_String_Matching()
        {
            var route = Route_Tests.CreateRoute(typeof(QueryStringController), nameof(QueryStringController.StringParam));

            _RouteMapper.AreQueryStringNamesCaseSensitive = true;
            _RouteMapper.Initialise(new Route[] { route });

            _Environment.SetRequestPath(route.PathParts[0].Part);

            _Environment.RequestQueryString = "PARAM=1";
            var parameters = _RouteMapper.BuildRouteParameters(route, _Environment.Environment);

            Assert.IsFalse(parameters.IsValid);

            _Environment.RequestQueryString = "param=1";
            parameters = _RouteMapper.BuildRouteParameters(route, _Environment.Environment);
            Assert.IsTrue(parameters.IsValid);
            Assert.AreEqual("1", parameters.Parameters[0]);
        }
コード例 #2
0
        public void Issue_1_Not_Choosing_Correct_Multipart_Route()
        {
            // This was found in an alpha build
            var getServerConfigRoute = Route_Tests.CreateRoute <Issue_1_Controller1>(nameof(Issue_1_Controller1.GetServerConfig));
            var getPolarPlotRoute    = Route_Tests.CreateRoute <Issue_1_Controller2>(nameof(Issue_1_Controller2.GetPolarPlot));

            _RouteMapper.Initialise(new Route[] {
                getPolarPlotRoute,
                getServerConfigRoute,
            });

            _Environment.RequestMethod = "GET";
            _Environment.RequestPath   = "/api/3.00/settings/server";

            var actual = _RouteMapper.FindRouteForRequest(_Environment.Environment);

            Assert.IsNotNull(actual);
            Assert.AreSame(getServerConfigRoute, actual);   // Bug is that it's returning the GetPolarPlot route
        }
コード例 #3
0
        public void FindRouteForRequest_Matches_MultiPart_Paths(string httpMethod, Type controllerType, string[] pathParts, bool expectMatch)
        {
            var route = Route_Tests.CreateRoute(controllerType, "Method");

            _RouteMapper.Initialise(new Route[] { route });
            _Environment.Environment[EnvironmentKey.RequestMethod] = httpMethod;
            _Environment.SetRequestPath(pathParts);

            var actual = _RouteMapper.FindRouteForRequest(_Environment.Environment);

            if (!expectMatch)
            {
                Assert.IsNull(actual);
            }
            else
            {
                Assert.IsNotNull(actual);
            }
        }
コード例 #4
0
        public void FindRouteForRequest_Returns_Correct_Candidates(string httpMethod, string pathPart, bool expectResult)
        {
            var expected = Route_Tests.CreateRoute <SimplePathController>(nameof(SimplePathController.Method));

            _RouteMapper.Initialise(new Route[] { expected });
            _Environment.Environment[EnvironmentKey.RequestMethod] = httpMethod;
            _Environment.Environment[EnvironmentKey.RequestPath]   = pathPart;

            var actual = _RouteMapper.FindRouteForRequest(_Environment.Environment);

            if (!expectResult)
            {
                Assert.IsNull(actual);
            }
            else
            {
                Assert.AreSame(expected, actual);
            }
        }
コード例 #5
0
        [DataRow(true, true, false)]        // Has null status code, is null outcome, should NOT pass to responder
        public void Middleware_Handles_NullStatusCode_Correctly(bool hasNullStatusCode, bool hasNullOutcome, bool expectResponderCall)
        {
            _RouteOutcome = hasNullOutcome ? null : new Object();
            _FoundRoute   = Route_Tests.CreateRoute <Controller>(
                hasNullStatusCode
                    ? nameof(Controller.HasNullStatusCode)
                    : nameof(Controller.DoesNotHaveNullStatusCode)
                );

            _Pipeline.BuildAndCallMiddleware(_WebApi.AppFuncBuilder, _Environment.Environment);

            if (expectResponderCall)
            {
                _Responder.Verify(r => r.ReturnJsonObject(_Environment.Environment, _RouteOutcome), Times.Once());
                Assert.AreEqual(200, _Environment.ResponseStatusCode);
            }
            else
            {
                _Responder.Verify(r => r.ReturnJsonObject(_Environment.Environment, _RouteOutcome), Times.Never());
                Assert.AreEqual((int)HttpStatusCode.Conflict, _Environment.ResponseStatusCode);
            }
        }
コード例 #6
0
        public void BuildRouteParameters_Uses_Limited_TypeParserResolver_When_Building_Bodies_From_Json()
        {
            // Only dates, byte arrays and guids go through the parser, everything else must be as per JSON spec

            var resolver = new TypeParserResolver(new JsonSerialiser_Tests.DateTime_JustDigits_Parser());
            var route    = Route_Tests.CreateRoute(typeof(JsonBodyModelController), nameof(JsonBodyModelController.DateModelFunc), parserResolver: resolver);

            _RouteMapper.Initialise(new Route[] { route });
            _Environment.RequestMethod = "POST";
            _Environment.SetRequestPath(route.PathParts[0].Part);
            var expected = new DateTime(2019, 12, 17, 21, 52, 19, 123);

            _Environment.SetRequestBody($"{{ \"DateValue\": \"{expected.ToString("yyyyMMddHHmmssfff")}\" }}", contentType: "application/json");

            var parameters = _RouteMapper.BuildRouteParameters(route, _Environment.Environment);

            Assert.IsTrue(parameters.IsValid);
            Assert.AreEqual(1, parameters.Parameters.Length);
            var model = parameters.Parameters[0] as DateModel;

            Assert.AreEqual(expected, model.DateValue);
        }
コード例 #7
0
        public void BuildRouteParameters_Can_Parse_Parameter_From_Query_String(string methodName, string parameterName, string queryString, string culture, object rawExpected)
        {
            using (new CultureSwap(culture)) {
                var route = Route_Tests.CreateRoute(typeof(QueryStringController), methodName);
                _RouteMapper.Initialise(new Route[] { route });
                _Environment.RequestQueryString = queryString;

                _Environment.SetRequestPath(route.PathParts[0].Part);
                var parameters = _RouteMapper.BuildRouteParameters(route, _Environment.Environment);

                var expected = rawExpected;
                switch (methodName)
                {
                case nameof(QueryStringController.DateParam):       expected = DataRowParser.DateTime((string)expected); break;

                case nameof(QueryStringController.DateOffsetParam): expected = DataRowParser.DateTimeOffset((string)expected); break;
                }

                Assert.IsTrue(parameters.IsValid);
                Assert.AreEqual(1, parameters.Parameters.Length);
                var param = parameters.Parameters[0];

                if (expected is IList expectedList)
                {
                    var actualList = (IList)param;
                    Assert.AreEqual(expectedList.Count, actualList.Count);
                    for (var i = 0; i < expectedList.Count; ++i)
                    {
                        Assert.AreEqual(expectedList[i], actualList[i]);
                    }
                }
                else
                {
                    Assert.AreEqual(expected, param);
                }
            }
        }
コード例 #8
0
ファイル: RouteCaller_Tests.cs プロジェクト: awhewell/owin
        public void CallRoute_Throws_If_RouteParameters_Are_Null()
        {
            var route = Route_Tests.CreateRoute <Controller>(nameof(Controller.Route_1));

            _RouteCaller.CallRoute(_Environment.Environment, route, null);
        }
コード例 #9
0
ファイル: RouteCaller_Tests.cs プロジェクト: awhewell/owin
        public void CallRoute_Throws_If_Route_Is_Null()
        {
            var routeParameters = Route_Tests.CreateRouteParameters(41);

            _RouteCaller.CallRoute(_Environment.Environment, null, routeParameters);
        }