public void TestDataUpdate()
        {
            Device device = new Device();
            device.Name = "TestDataUpdate" + new Random().Next();
            device.Working = true;
            devRep.Save(device);

            Data data = new Data();
            data.Name = "TestDataUpdate";
            data.Timestamp = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0)).Seconds;
            data.Value = new Random().Next();
            data.Device = device;
            dataRep.Save(data);

            string newName = "newName";
            long newTs = 1234;
            double value = 12345;
            data.Name = newName;
            data.Timestamp = newTs;
            data.Value = value;
            dataRep.Update(data.Id, data);


            Data another = dataRep.GetById(data.Id);
            Assert.AreEqual(newName, another.Name);
            Assert.AreEqual( newTs, another.Timestamp);
            Assert.AreEqual(value, another.Value);
        }
 public static Device GetDevice()
 {
     Device res = new Device();
     res.Name = "GeneratedDevice" + RandomIntModifier();
     res.Working = RandomBoolModifier();
     return res;
 }
 public static Command GetFilledCommand(Device device = null)
 {
     Command comm = EntityGenerator.GetCommand();
     if (device == null)
         device = GetFilledDevice();
     comm.Device = device;
     commRep.Save(comm);
     return comm;
 }
 public static Data GetFilledData(Device device = null)
 {
     Data data = EntityGenerator.GetData();
     if (device == null)
         device = GetFilledDevice();
     data.Device = device;
     dataRep.Save(data);
     return data;
 }
 public void Prepare()
 {
     device = ScenarioGenerator.GetFilledDevice();
     Console.WriteLine("Device ID: " + device.Id);
     command = new List<Command>();
     for (int i = 0; i < 10; i++)
     {
         Command temp = ScenarioGenerator.GetFilledCommand(device);
         command.Add(temp);
         Console.WriteLine("Command ID: " + temp.Id);                
     }
     token = ScenarioGenerator.GetFilledToken();
    
 }
        public static DeviceDTO Convert(Device from)
        {
            DeviceDTO res = new DeviceDTO();
            res.Id = from.Id;
            res.Name = from.Name;
            res.Working = from.Working;

            res.Datas = new List<DataDTO>();
            foreach (Data d in from.Data)
                res.Datas.Add(DataDTO.Convert(d));

            res.Commands = new List<CommandDTO>();
            foreach (Command c in from.Command)
                res.Commands.Add(CommandDTO.Convert(c));

            return res;
        }
        public void TestDataSave()
        {
            Device device = new Device();
            device.Name = "TestDataSave" + new Random().Next();
            device.Working = true;
            devRep.Save(ref device);

            Data data = new Data();
            data.Name = "TestDataSave1";
            data.Timestamp = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0)).Seconds;
            data.Value = new Random().Next();
            data.Device = device;
            dataRep.Save(ref data);

            Data another = dataRep.GetById(data.Id);

            Assert.AreEqual(another.Device.Id, data.Device.Id);

            foreach (var cur in device.Data)
                Assert.AreEqual(another.Id, cur.Id);
        }
 public System.Net.HttpStatusCode editDevice(Device device)
 {
     //dummy device validation
     //dummy update
     throw new NotImplementedException();
 }