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());
        }
        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();
        }
        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());
        }
        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));
        }
 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;
 }