コード例 #1
0
        public void InvalidRulesParamsMatchesNoRules()
        {
            _controller = ConfigureControllerContext("http://localhost/api/flights?rules=notexpectingthis",
                new FlightsController(_rulesService, _builder));

            var rules = _controller.GetRulesToApply();
            A.CallTo(() => _rulesService.GetRules()).MustHaveHappened();
            Assert.AreEqual(0, rules.Count());
        }
コード例 #2
0
        public void FilterControllerCallsFilterBuilder()
        {
            _controller = ConfigureControllerContext("http://localhost/api/flights?rules=1,2,3",
                new FlightsController(_rulesService, _builder));

            var flights = _controller.Get();
            A.CallTo(() => _builder.GetFlights()).MustHaveHappened();
            A.CallTo(() => _rulesService.GetRules()).MustHaveHappened();
        }
コード例 #3
0
        public void NoRulesParamAppliesAllRules()
        {
            _controller = ConfigureControllerContext("http://localhost/api/flights",
                new FlightsController(_rulesService, _builder));

            var rules = _controller.GetRulesToApply();
            A.CallTo(() => _rulesService.GetRules()).MustHaveHappened();

            Assert.AreEqual(3, rules.Count());
        }
コード例 #4
0
        public void ValidRulesParamsParsedCorrectly()
        {
            _controller = ConfigureControllerContext("http://localhost/api/flights?rules=2,1",
                new FlightsController(_rulesService, _builder));

            var rules = _controller.GetRulesToApply();
            A.CallTo(() => _rulesService.GetRules()).MustHaveHappened();

            Assert.AreEqual(2, rules.Count());
            Assert.IsTrue(rules.Any(r => r.Id == 1));
            Assert.IsTrue(rules.Any(r => r.Id == 2));
        }
コード例 #5
0
 private FlightsController ConfigureControllerContext(string url, FlightsController controller)
 {
     var config = new HttpConfiguration();
     var request = new HttpRequestMessage(HttpMethod.Post, url);
     var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
     var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "flights" } });
     controller.ControllerContext = new HttpControllerContext(config, routeData, request);
     controller.Request = request;
     controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
     return controller;
 }