public async Task GetDevicesAsyncTest() { using (var cloud = new ParticleCloudMock()) { cloud.RequestCallBack = (t, m, p) => { return(new RequestResponse { StatusCode = HttpStatusCode.OK, Response = JToken.Parse(@"[ { ""id"": ""1"", ""name"": ""Work"", ""last_app"": null, ""last_ip_address"": ""192.168.0.1"", ""last_heard"": ""2015-05-25T01:15:36.034Z"", ""product_id"": 0, ""connected"": false }, { ""id"": ""2"", ""name"": ""Home"", ""last_app"": null, ""last_ip_address"": ""192.168.0.1"", ""last_heard"": ""2015-05-25T01:15:59.188Z"", ""product_id"": 0, ""connected"": false }, { ""id"": ""3"", ""name"": ""Proto"", ""last_app"": null, ""last_ip_address"": ""192.168.0.1"", ""last_heard"": ""2015-07-24T00:37:07.820Z"", ""product_id"": 6, ""connected"": true } ]") }); }; var result = await cloud.GetDevicesAsync(); Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.IsNotNull(result.Data); var devices = result.Data; Assert.AreEqual(3, devices.Count); var device = devices[0]; Assert.AreEqual("1", device.Id); Assert.AreEqual("Work", device.Name); device = devices[1]; Assert.AreEqual("2", device.Id); Assert.AreEqual("Home", device.Name); device = devices[2]; Assert.AreEqual("3", device.Id); Assert.AreEqual("Proto", device.Name); } }
public async Task GetDevicesAsyncHttpRequestExceptionTest() { using (var cloud = new ParticleCloudMock()) { var ex = new HttpRequestException("Error connecting to the server"); cloud.RequestCallBack = (t, m, p) => { throw ex; }; var result = await cloud.GetDevicesAsync(); Assert.IsNotNull(result); Assert.IsFalse(result.Success); Assert.AreEqual(ex.Message, result.Error); Assert.AreEqual(ex, result.Exception); } }
public async Task GetDevicesAsyncHttpRequestExceptionTest() { using(var cloud = new ParticleCloudMock()) { var ex = new HttpRequestException("Error connecting to the server"); cloud.RequestCallBack = (t, m, p) => { throw ex; }; var result = await cloud.GetDevicesAsync(); Assert.IsNotNull(result); Assert.IsFalse(result.Success); Assert.AreEqual(ex.Message, result.Error); Assert.AreEqual(ex, result.Exception); } }
public async Task GetDevicesAsyncTest() { using (var cloud = new ParticleCloudMock()) { cloud.RequestCallBack = (t, m, p) => { return new RequestResponse { StatusCode = HttpStatusCode.OK, Response = JToken.Parse(@"[ { ""id"": ""1"", ""name"": ""Work"", ""last_app"": null, ""last_ip_address"": ""192.168.0.1"", ""last_heard"": ""2015-05-25T01:15:36.034Z"", ""product_id"": 0, ""connected"": false }, { ""id"": ""2"", ""name"": ""Home"", ""last_app"": null, ""last_ip_address"": ""192.168.0.1"", ""last_heard"": ""2015-05-25T01:15:59.188Z"", ""product_id"": 0, ""connected"": false }, { ""id"": ""3"", ""name"": ""Proto"", ""last_app"": null, ""last_ip_address"": ""192.168.0.1"", ""last_heard"": ""2015-07-24T00:37:07.820Z"", ""product_id"": 6, ""connected"": true } ]") }; }; var result = await cloud.GetDevicesAsync(); Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.IsNotNull(result.Data); var devices = result.Data; Assert.AreEqual(3, devices.Count); var device = devices[0]; Assert.AreEqual("1", device.Id); Assert.AreEqual("Work", device.Name); device = devices[1]; Assert.AreEqual("2", device.Id); Assert.AreEqual("Home", device.Name); device = devices[2]; Assert.AreEqual("3", device.Id); Assert.AreEqual("Proto", device.Name); } }