public void AddDeviceTest() { using (ILoRaClient client = CreateLoRaClient()) { var customers = client.GetCustomers().Result; var deviceProfiles = client.GetDeviceProfiles(customers.subscription.href).Result; var modelId = deviceProfiles.briefs.First().ID; var device = new DeviceAddModel.Device { name = "AddDeviceTest_ut", model = new DeviceAddModel.Model { ID = modelId }, nwAddress = "0B60D265", EUI = "200000000F252D98", nwKey = "12345678901234567890123456789012" }; var result = client.AddDevice(customers.subscription.href, device).Result; var allCurrentDevices = client.GetDevices(customers.subscription.href).Result; //cleanup client.RemoveDevice(result.href); Assert.NotNull(result); Assert.True(allCurrentDevices.briefs.Any(d => d.EUI == "200000000F252D98")); } }
public void RemoveDeviceTest() { using (ILoRaClient client = CreateLoRaClient()) { var customers = client.GetCustomers().Result; var deviceProfiles = client.GetDeviceProfiles(customers.subscription.href).Result; var modelId = deviceProfiles.briefs.First().ID; var newDevice = new DeviceAddModel.Device { name = "RemoveDeviceTest_ut", model = new DeviceAddModel.Model { ID = modelId }, nwAddress = "0B60D266", EUI = "200000000F252D95", nwKey = "12345678901234567890123456789013" }; var result = client.AddDevice(customers.subscription.href, newDevice).Result; var devices = client.GetDevices(customers.subscription.href).Result; //act client.RemoveDevice(result.href); Assert.True(devices.briefs .Any(d => d.EUI == "200000000F252D95")); var endresult = client.GetDevices(customers.subscription.href).Result.briefs; Assert.False(endresult .Any(d => d.EUI == "200000000F252D95")); } }
public async Task <Device> AddDevice(string subscriptionHref, Models.DeviceAddModel.Device device) { var response = await _loRaHttpClient.PostJsonAsync($"{_restPath}{subscriptionHref}/devices", device); response.HandleResponseErrors(); string result = await response.Content.ReadAsStringAsync(); var addedDevice = JsonConvert.DeserializeObject <Device>(result); var locationHeader = response.Headers.GetValues("Location"); addedDevice.href = locationHeader.Single(); return(addedDevice); }
public void UpdateDeviceTest() { using (ILoRaClient client = CreateLoRaClient()) { var customers = client.GetCustomers().Result; var deviceProfiles = client.GetDeviceProfiles(customers.subscription.href).Result; var modelId = deviceProfiles.briefs.First().ID; var newDevice = new DeviceAddModel.Device { name = "UpdateDeviceTest_ut", model = new DeviceAddModel.Model { ID = modelId }, nwAddress = "0B60D267", EUI = "200000000F252D97", nwKey = "12345678901234567890123456789015" }; var result = client.AddDevice(customers.subscription.href, newDevice).Result; var devices = client.GetDevices(customers.subscription.href).Result; var device = devices.briefs.First(d => d.EUI == "200000000F252D97"); //Act var updateDevice = new DeviceUpdateModel.Device { name = "UpdatedDeviceTest_ut", nwKey = "12345678901234567890123456789015" }; newDevice.name = "UpdatedDeviceTest_ut"; var updateResult = client.UpdateDevice(device.href, updateDevice).Result; //Get Aftermath var afterupdatedevices = client.GetDevices(customers.subscription.href).Result; var afterupdatedevice = afterupdatedevices.briefs.First(d => d.EUI == "200000000F252D97"); //Cleanup client.RemoveDevice(device.href); //Assert Assert.Equal("UpdatedDeviceTest_ut", afterupdatedevice.name); } }