Exemple #1
0
 public SensorErrorTests()
 {
     var configuration1 = new HttpConfiguration();
     configuration1.MapSensorRoutes(ctx => true);
     var server = new HttpServer(configuration1);
     apiClient = new HttpClient(server);
 }
Exemple #2
0
 public SensorRoutingTests()
 {
     configuration = new HttpConfiguration();
     configuration.MapSensorRoutes(ctx => true);
     var server = new HttpServer(configuration);
     apiClient = new HttpClient(server);
 }
        public void A_message_handler_can_be_specified_to_perform_authentication_prior_to_the_sensor_authorization_check()
        {
            var authenticator = new Authenticator
            {
                Send = request =>
                {
                    var response = request.CreateResponse(HttpStatusCode.OK);
                    response.Headers.Add("authenticated", "true");
                    return response;
                }
            };
            var httpConfig = new HttpConfiguration();

            HttpMessageHandler handler = HttpClientFactory.CreatePipeline(
                new HttpControllerDispatcher(httpConfig),
                new[] { authenticator });

            httpConfig.MapSensorRoutes(
                ctx => ctx.Response.Headers.Contains("authenticated") &&
                       ctx.Response.Headers.GetValues("authenticated").Single() == "true",
                handler: handler);

            var apiClient = new HttpClient(new HttpServer(httpConfig));

            apiClient.GetAsync("http://blammo.biz/sensors").Result.StatusCode.Should().Be(HttpStatusCode.OK);
        }