public SensorRouter(SensorRegistry sensors, AuthorizeSensors authorizeSensors, string pathBase = "/sensors") : base(pathBase) { this.authorizeSensors = authorizeSensors ?? throw new ArgumentNullException(nameof(authorizeSensors)); this.sensors = sensors ?? throw new ArgumentNullException(nameof(sensors)); }
public async Task Authorization_can_be_denied_for_all_sensors() { authorize = context => { context.Handler = async httpContext => httpContext.Response.StatusCode = 403; }; var response = await apiClient.GetAsync("http://blammo.com/sensors/SensorMethod"); response.StatusCode.Should().Be(HttpStatusCode.Forbidden); }
public static IServiceCollection AddPeakySensors( this IServiceCollection builder, AuthorizeSensors authorize = null, string baseUri = "sensors") { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } authorize = authorize ?? (_ => { }); builder.TryAddSingleton(authorize); builder.TryAddSingleton(c => new SensorRegistry(DiagnosticSensor.DiscoverSensors())); return(builder); }