public void CreateDeleteDeviceIsHealthy() { Skip.IfNot(this.credentialsAvailable, "Skipping this test for Travis pull request as credentials are not available"); var deviceId = "CreateDevice"; this.DeleteDeviceIfExists(deviceId); // create device var device = new DeviceRegistryApiModel() { Id = deviceId }; var request = new HttpRequest(); request.SetUriFromString(AssemblyInitialize.Current.WsHostname + $"/v1/devices"); request.SetContent(device); var response = this.httpClient.PostAsync(request).Result; var azureDevice = JsonConvert.DeserializeObject <DeviceRegistryApiModel>(response.Content); Assert.Equal(deviceId, azureDevice.Id); // clean it up this.DeleteDeviceIfExists(deviceId); }
private DeviceRegistryApiModel CreateDeviceIfNotExists(string deviceId) { var device = this.GetDevice(deviceId); if (device != null) { return(device); } device = new DeviceRegistryApiModel() { Id = deviceId }; var request = new HttpRequest(); request.SetUriFromString(AssemblyInitialize.Current.WsHostname + $"/v1/devices/{deviceId}"); request.SetContent(device); var response = this.httpClient.PutAsync(request).Result; Assert.Equal(HttpStatusCode.OK, response.StatusCode); return(JsonConvert.DeserializeObject <DeviceRegistryApiModel>(response.Content)); }
private DeviceRegistryApiModel CreateDeviceIfNotExists(string deviceId, Dictionary <string, string> tags = null) { var device = this.GetDevice(deviceId); if (device != null) { return(device); } device = new DeviceRegistryApiModel() { Id = deviceId, }; if (tags != null) { device.Tags = new Dictionary <string, JToken>(); foreach (var tag in tags) { device.Tags.Add(tag.Key, tag.Value); } } var request = new HttpRequest(); request.SetUriFromString(AssemblyInitialize.Current.WsHostname + $"/v1/devices/{deviceId}"); request.SetContent(device); var response = this.httpClient.PutAsync(request).Result; Assert.Equal(HttpStatusCode.OK, response.StatusCode); return(JsonConvert.DeserializeObject <DeviceRegistryApiModel>(response.Content)); }
private Row GenerateRowForChildPartDetail(DeviceRegistryApiModel model, List <ColumnMappingModel> columnMapping) { Row tRow = new Row(); JObject modelObject = (JObject)JToken.FromObject(model); foreach (var map in columnMapping) { tRow.Append(OpenXMLHelper.CreateCell((string)modelObject.SelectToken(map.Mapping))); } return(tRow); }
public async void PutThrowsResourceNotFound() { const string deviceId = "testDevice"; var model = new DeviceRegistryApiModel { Id = deviceId, }; this.devicesMock .Setup(x => x.UpdateAsync( It.IsAny <DeviceServiceModel>(), It.IsAny <DevicePropertyDelegate>())) .ThrowsAsync(new ResourceNotFoundException()); await Assert.ThrowsAsync <ResourceNotFoundException>(async() => await this.controller.PutAsync(deviceId, model)); }
public async Task <DeviceRegistryApiModel> PutAsync(string id, [FromBody] DeviceRegistryApiModel device) { DevicePropertyDelegate updateListDelegate = new DevicePropertyDelegate(this.deviceProperties.UpdateListAsync); return(new DeviceRegistryApiModel(await this.devices.CreateOrUpdateAsync(device.ToServiceModel(), updateListDelegate))); }
public async Task <DeviceRegistryApiModel> PostAsync([FromBody] DeviceRegistryApiModel device) { return(new DeviceRegistryApiModel(await this.devices.CreateAsync(device.ToServiceModel()))); }
public void CreateDeviceIsHealthy() { Skip.IfNot(this.credentialsAvailable, "Skipping this test for Travis pull request as credentials are not available"); // create using auto device id { var device = new DeviceRegistryApiModel(); var request = new HttpRequest(); request.SetUriFromString(AssemblyInitialize.Current.WsHostname + $"/v1/devices"); request.SetContent(device); var response = this.httpClient.PostAsync(request).Result; var azureDevice = JsonConvert.DeserializeObject <DeviceRegistryApiModel>(response.Content); var deviceId = azureDevice.Id; Assert.True(!string.IsNullOrEmpty(azureDevice.Id)); Assert.True(!string.IsNullOrEmpty(azureDevice.Authentication.PrimaryKey)); Assert.True(!string.IsNullOrEmpty(azureDevice.Authentication.SecondaryKey)); Assert.Equal(AuthenticationType.Sas, azureDevice.Authentication.AuthenticationType); // clean it up this.DeleteDeviceIfExists(deviceId); } // create with SaS keys { var device = new DeviceRegistryApiModel() { Authentication = new AuthenticationMechanismApiModel() { PrimaryKey = "gcSE7TEHB/S5Y8QKsoRVdX9iDRd8eFCr8MjoNlmrukI=", SecondaryKey = "HLmp5CtxoA463nlUamXCBLc9x4WGJDXK+f3PlD+wsHg=" } }; var request = new HttpRequest(); request.SetUriFromString(AssemblyInitialize.Current.WsHostname + $"/v1/devices"); request.SetContent(device); var response = this.httpClient.PostAsync(request).Result; var azureDevice = JsonConvert.DeserializeObject <DeviceRegistryApiModel>(response.Content); var deviceId = azureDevice.Id; Assert.True(!string.IsNullOrEmpty(azureDevice.Id)); Assert.True(string.IsNullOrEmpty(azureDevice.Authentication.PrimaryThumbprint)); Assert.True(string.IsNullOrEmpty(azureDevice.Authentication.SecondaryThumbprint)); Assert.Equal(AuthenticationType.Sas, azureDevice.Authentication.AuthenticationType); Assert.Equal(device.Authentication.PrimaryKey, azureDevice.Authentication.PrimaryKey); Assert.Equal(device.Authentication.SecondaryKey, azureDevice.Authentication.SecondaryKey); // clean it up this.DeleteDeviceIfExists(deviceId); } // create with Certificate thumbprints { var device = new DeviceRegistryApiModel() { Authentication = new AuthenticationMechanismApiModel() { AuthenticationType = AuthenticationType.SelfSigned, PrimaryThumbprint = "a909502dd82ae41433e6f83886b00d4277a32a7b", SecondaryThumbprint = "b909502dd82ae41433e6f83886b00d4277a32a7b" } }; var request = new HttpRequest(); request.SetUriFromString(AssemblyInitialize.Current.WsHostname + $"/v1/devices"); request.SetContent(device); var response = this.httpClient.PostAsync(request).Result; var azureDevice = JsonConvert.DeserializeObject <DeviceRegistryApiModel>(response.Content); var deviceId = azureDevice.Id; Assert.True(!string.IsNullOrEmpty(azureDevice.Id)); Assert.True(string.IsNullOrEmpty(azureDevice.Authentication.PrimaryKey)); Assert.True(string.IsNullOrEmpty(azureDevice.Authentication.SecondaryKey)); Assert.Equal(AuthenticationType.SelfSigned, azureDevice.Authentication.AuthenticationType); Assert.Equal(device.Authentication.PrimaryThumbprint, azureDevice.Authentication.PrimaryThumbprint); Assert.Equal(device.Authentication.SecondaryThumbprint, azureDevice.Authentication.SecondaryThumbprint); // clean it up this.DeleteDeviceIfExists(deviceId); } }