Exemplo n.º 1
0
        public ActionResult <SensorItemDto> CreateSensor(SensorItemDto sensorItemDto)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var sensor = this._dbContext.CreateSensor(userId, sensorItemDto);

            return(CreatedAtAction(nameof(GetSensor), new { id = sensor.Id }, ToSensorItemDto(sensor)));
        }
Exemplo n.º 2
0
        public Sensor CreateSensor(string userId, SensorItemDto sensorItemDto)
        {
            var owner  = this.Users.Find(userId);
            var sensor = new Sensor()
            {
                OwnerId    = owner.Id,
                Name       = sensorItemDto.Name,
                SensorType = sensorItemDto.SensorType,
                TimeZone   = sensorItemDto.TimeZone
            };

            this.Add(sensor);
            this.SaveChanges();
            return(sensor);
        }
Exemplo n.º 3
0
        public SensorItemDto CreateSensor()
        {
            // Act
            var sensorItemDto = new SensorItemDto()
            {
                Name = "Sensor 01", SensorType = SensorTypes.EnergyLog, TimeZone = System.TimeZoneInfo.Local.Id
            };
            var actionResult        = _controller.CreateSensor(sensorItemDto);
            var sensorItemDtoResult = Assert.IsType <SensorItemDto>(((CreatedAtActionResult)actionResult.Result).Value);

            // Assert
            Assert.NotEmpty(sensorItemDtoResult.Id);
            Assert.Equal(sensorItemDto.Name, sensorItemDtoResult.Name);
            return(sensorItemDtoResult);
        }