public void GetDeviceDetails() { string data = JsonConvert.SerializeObject(MockDataModel); FakeResponseHandler fakeDevicesHandler = new FakeResponseHandler(); fakeDevicesHandler.AddFakeResponse( new Uri($"{ApplicationURLS.Backend}/api/devices/{MockDataModel.Device.DeviceId}/details"), new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(data) }); RestService restService = new RestService(new HttpClient(fakeDevicesHandler), mockTokenAcquisition, mockConfiguration); DeviceDetailViewController deviceDetailViewController = new DeviceDetailViewController(restService); ViewResult viewResult = deviceDetailViewController.Device("device1") as ViewResult; Assert.Equal("device1", viewResult.ViewData["DeviceID"]); }
public void NotExistingDevice() { FakeResponseHandler fakeNotExistingDeviceHandler = new FakeResponseHandler(); fakeNotExistingDeviceHandler.AddFakeException( new Uri($"{ApplicationURLS.Backend}/api/devices/{MockDataModel.Device.DeviceId}/details"), new HttpRequestException($"Device {MockDataModel.Device.DeviceId} not found") ); RestService restService = new RestService(new HttpClient(fakeNotExistingDeviceHandler), mockTokenAcquisition, mockConfiguration); DeviceDetailViewController deviceDetailViewController = new DeviceDetailViewController(restService); try { deviceDetailViewController.Device(MockDataModel.Device.DeviceId); } catch (Exception e) { Assert.IsType <HttpRequestException>(e.InnerException); Assert.Equal("Response status code does not indicate success: 404 (Not Found).", e.InnerException.Message); } }