コード例 #1
0
 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));
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }