Esempio n. 1
0
        public async Task <Device> UpdateDevice(string deviceHref, Models.DeviceUpdateModel.Device device)
        {
            var response = await _loRaHttpClient.PutJsonAsync($"{deviceHref}", device);

            response.HandleResponseErrors();
            string result = await response.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <Device>(result));
        }
Esempio n. 2
0
        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);
            }
        }