コード例 #1
0
        public async Task <ActionResult <DeviceDTO> > Register([FromBody] RegisterDeviceDTO value)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var device    = _mapper.Map <Device>(value);
                var newDevice = await _deviceBusiness.RegisterAsync(device).ConfigureAwait(false);

                var deviceDto = _mapper.Map <DeviceDTO>(newDevice);
                return(Ok(deviceDto));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message + ex.StackTrace);
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
コード例 #2
0
        private async Task InsertNewDevice()
        {
            // Arrange
            var client           = _factory.CreateClient();
            var getAllDevicesUrl = "/api/Devices";

            // Act
            var device = new RegisterDeviceDTO()
            {
                Id              = "123456789",
                DeviceName      = "IPhone",
                OperatingSystem = "IOS 12.2",
                Version         = "5S",
                ERNIControlNo   = "00000"
            };

            var json     = JsonConvert.SerializeObject(device);
            var content  = new StringContent(json, Encoding.UTF8, "application/json");
            var response = await client.PutAsync(getAllDevicesUrl, content).ConfigureAwait(false);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }