Пример #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 void When_registered_sensor_is_a_method_then_name_is_derived_from_its_name()
        {
            var registry = new SensorRegistry();

            registry.Add(SensorNameTester);

            registry.Count(s => s.Name == "SensorNameTester").Should().Be(1);
        }
Пример #3
0
        public void When_registered_sensor_is_a_method_then_DeclaringType_is_the_containing_type()
        {
            var registry = new SensorRegistry();

            registry.Add(StaticTestSensors.ExceptionSensor);

            var sensor = registry.Single(s => s.Name == "ExceptionSensor");

            sensor.DeclaringType.Should().Be(typeof(StaticTestSensors));
        }
Пример #4
0
        public void When_a_sensor_returns_a_Task_then_its_IsAsync_Property_returns_true()
        {
            var sensorName = Any.Paragraph(5);
            var registry   = new SensorRegistry();

            registry.Add(AsyncTask, sensorName);

            var sensor = registry.Single(s => s.Name == sensorName);

            sensor.IsAsync.Should().BeTrue();
        }
Пример #5
0
        public void When_a_sensor_does_not_return_a_Task_then_its_IsAsync_Property_returns_false()
        {
            var sensorName = Any.Paragraph(5);

            var registry = new SensorRegistry();

            registry.Add(() => "hi!", sensorName);

            var sensor = registry.Single(s => s.Name == sensorName);

            sensor.IsAsync.Should().BeFalse();
        }
Пример #6
0
        public void When_registered_sensor_is_anonymous_then_DeclaringType_is_the_containing_type()
        {
            var newGuid = Guid.NewGuid();

            var registry = new SensorRegistry();

            registry.Add(() => newGuid);

            var sensor = registry.Single(s => s.Read().Result.Value.Equals(newGuid));

            sensor.DeclaringType.Should().Be(GetType());
        }
Пример #7
0
        public void When_registered_sensor_is_anonymous_then_default_name_is_derived_from_method_doing_registration()
        {
            var newGuid = Guid.NewGuid();

            var registry = new SensorRegistry();

            registry.Add(() => newGuid);

            var sensor = registry.Single(s => s.Read().Result.Value.Equals(newGuid));

            sensor.Name.Should().Contain(nameof(When_registered_sensor_is_anonymous_then_default_name_is_derived_from_method_doing_registration));
        }
Пример #8
0
        public async Task Sensors_can_be_registered_at_runtime()
        {
            var sensorName = nameof(Sensors_can_be_registered_at_runtime);
            var registry   = new SensorRegistry();

            registry.Add(() => "hello", sensorName);

            var sensor = registry.Single(s => s.Name == sensorName);

            sensor.DeclaringType.Should().Be(GetType());
            sensor.ReturnType.Should().Be(typeof(string));
            var reading = await sensor.Read();

            reading.Value.Should().Be("hello");
        }