public bool Update(string id, [FromBody] DataModels.DeviceModel updatedState) { if (!string.IsNullOrEmpty(id) && updatedState != null) { return(_repository.UpdateDevice(id, updatedState)); } return(false); }
public bool UpdateDevice(string id, DataModels.DeviceModel device) { bool updated = false; var deviceDb = _csvHandler.ReadFile(_csvFilePath); foreach (var tempDevice in deviceDb) { if (tempDevice.Id == id) { updated = _csvHandler.DeleteFromFile(tempDevice.Id, _csvFilePath); updated &= _csvHandler.WriteToFile(device, _csvFilePath); } } return(updated); }
public void TestExpectingDeviceToBeUpdatedWhenCalledWithStirngIdAndUpdatedDeviceState() { DataModels.DeviceModel device = new DataModels.DeviceModel { Name = "IntelliVue X3", Id = "VUEX3", Batterycapacity = "7", Measurements = new List <string> { "ECG", "SPO2", "Respiration" }, Overview = "The IntelliVue X3 combines powerful monitoring with flexible portability in one compact unit. Supplying comprehensive patient information at a glance it can make a real difference when multiple patients and priorities need attention.", Resolution = "1024 x 420", Weight = 1.9f, }; Assert.True(_controller.Update("VUEX3", device)); }
public async Task TestExpectingTrueWhenDeviceHasBeenUpdatedWhenCalledWithValidId() { var updatedState = new DataModels.DeviceModel() { Name = "IntelliVue X3", Id = "VUEX3", Batterycapacity = "11", Measurements = new List <string> { "ECG", "SPO2", "Respiration" }, Overview = "The IntelliVue X3 combines powerful monitoring with flexible portability in one compact unit. Supplying comprehensive patient information at a glance it can make a real difference when multiple patients and priorities need attention.", Resolution = "1024x420", Weight = 1.7f, }; //ReSharper disable all var response = await _mockServer.Client.PutAsync(_url + "/VUEX3", new StringContent(JsonConvert.SerializeObject(updatedState), Encoding.UTF8, "application/json")); //ReSharper restore all Assert.True(response.StatusCode == HttpStatusCode.OK); }
public async Task TestExpectingTrueWhenNewDeviceIsAddedSuccessfully() { var newDevice = new DataModels.DeviceModel() { Name = "IntelliVue MX300", Id = "VUEMX300", Batterycapacity = "11", Measurements = new List <string> { "ECG" }, Overview = "Something", Resolution = "1090x1020", Weight = 1.2f, }; //ReSharper disable all var response = await _mockServer.Client.PostAsync(_url, new StringContent(JsonConvert.SerializeObject(newDevice), Encoding.UTF8, "application/json")); //ReSharper restore all var jsonString = await response.Content.ReadAsStringAsync(); Assert.Equal("true", JsonConvert.DeserializeObject <string>(jsonString)); }
public async Task TestExpectingFalseWhenCalledForUpdattionWithInvalidId() { var updatedstate = new DataModels.DeviceModel() { Name = "IntelliVue X777", Id = "VUEX777", Batterycapacity = "7", Measurements = new List <string> { "ECG", "SPO2", "Respiration" }, Overview = "The IntelliVue X3 combines powerful monitoring with flexible portability in one compact unit. Supplying comprehensive patient information at a glance it can make a real difference when multiple patients and priorities need attention.", Resolution = "1024x420", Weight = 1.9f, }; //ReSharper disable all var response = await _mockServer.Client.PutAsync(_url + "/VUEX777", new StringContent(JsonConvert.SerializeObject(updatedstate), Encoding.UTF8, "application/json")); var jsonString = await response.Content.ReadAsStringAsync(); Assert.Equal("false", JsonConvert.DeserializeObject <string>(jsonString)); //ReSharper restore all }
public async Task TestExpectingTrueWhenCalledWithValidIdToDeleteMethod() { var device = new DataModels.DeviceModel() { Id = "VUEMX300", Name = "IntelliVue MX300", Measurements = new List <string> { "ECG" }, Resolution = "1090x1080", Overview = "some_random_overview", Weight = 1.6f, Batterycapacity = "11" }; //ReSharper disable all await _mockServer.Client.PostAsync(_url, new StringContent(JsonConvert.SerializeObject(device), Encoding.UTF8, "application/json"));//ReSharper restore all var response = await _mockServer.Client.DeleteAsync(_url + "/VUEMX300"); var jsonString = await response.Content.ReadAsStringAsync(); Assert.Equal("true", JsonConvert.DeserializeObject <string>(jsonString)); }
public static void addDevice(DataModels.DeviceModel f) { Console.WriteLine(f.measurements.GetType()); System.Net.HttpWebRequest _httpReq = System.Net.WebRequest.CreateHttp("http://localhost:5000/api/devices"); _httpReq.Method = "POST"; _httpReq.ContentType = "application/json"; System.Runtime.Serialization.Json.DataContractJsonSerializer filterDataJsonSerializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(DataModels.DeviceModel)); filterDataJsonSerializer.WriteObject(_httpReq.GetRequestStream(), f); System.Net.HttpWebResponse response = _httpReq.GetResponse() as System.Net.HttpWebResponse; if (response.StatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine("Communication Successful"); Console.WriteLine(response.ContentType); Console.WriteLine(response.ContentLength); System.Runtime.Serialization.Json.DataContractJsonSerializer _jsonSerializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(DataModels.DeviceModel[])); MessageBox.Show("Addition Successful !"); } }
public static DataModels.DeviceModel getDeviceById(string id) { string api = "http://localhost:5000/api/devices/" + id; System.Net.HttpWebRequest _httpReq = System.Net.WebRequest.CreateHttp(api); _httpReq.Method = "GET"; System.Net.HttpWebResponse response = _httpReq.GetResponse() as System.Net.HttpWebResponse; if (response.StatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine("Communication Successful"); Console.WriteLine(response.ContentType); Console.WriteLine(response.ContentLength); System.Runtime.Serialization.Json.DataContractJsonSerializer _jsonSerializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(DataModels.DeviceModel)); DataModels.DeviceModel m = _jsonSerializer.ReadObject(response.GetResponseStream()) as DataModels.DeviceModel; return(m); } return(null); }
public bool Post([FromBody] DataModels.DeviceModel device) { return(_repository.AddNewDevice(device)); }
public bool AddNewDevice(DataModels.DeviceModel device) { return(_csvHandler.WriteToFile(device, _csvFilePath)); }
public void TestExpectingNullWhenDeviceDoesNotExistInFile() { DataModels.DeviceModel tempDevice = _deviceRepository.GetDevice("VUEMX1100"); Assert.Null(tempDevice); }
public void TestExpectingADeviceWhenCalledWithStringId() { DataModels.DeviceModel tempDevice = _deviceRepository.GetDevice("VUEMX750"); Assert.Equal("IntelliVue MX750", tempDevice.Name); }