コード例 #1
0
        public async Task GetSensor_NotFound()
        {
            var    hueSensorProvider = Substitute.For <IHueSensorProvider>();
            Sensor sensor            = null;

            hueSensorProvider.GetSensorByIdAsync(1).Returns(Task.FromResult(sensor));
            var controller = new MeasurementController(hueSensorProvider);

            var result = await controller.GetSensor(1);

            Assert.IsType <NotFoundResult>(result.Result);
        }
コード例 #2
0
        public async Task GetSensor_Found()
        {
            var    hueSensorProvider = Substitute.For <IHueSensorProvider>();
            Sensor sensor            = new DummySensor
            {
                Id   = 1,
                Name = "Sensor1",
                Type = SensorType.Dummy,
                BatteryPercentage = 51
            };

            hueSensorProvider.GetSensorByIdAsync(1).Returns(Task.FromResult(sensor));
            var controller = new MeasurementController(hueSensorProvider);

            var result = await controller.GetSensor(1);

            var okResult     = Assert.IsType <OkObjectResult>(result.Result);
            var sensorResult = Assert.IsType <DummySensor>(okResult.Value);

            Assert.Equal(sensor, sensorResult);
        }