public async Task ClaimDeviceAsyncTest() { using (var cloud = new ParticleCloudMock()) { cloud.RequestCallBack = (t, m, p) => { return(new RequestResponse { StatusCode = HttpStatusCode.NotFound, Response = JToken.Parse(@" { ok: false, errors: ['device does not exist'] }") }); }; var ex = Assert.Throws <ArgumentNullException>(() => { cloud.ClaimDeviceAsync(null).GetAwaiter().GetResult(); }); Assert.AreEqual("deviceId", ex.ParamName); var result = await cloud.ClaimDeviceAsync("123"); Assert.IsNotNull(result); Assert.IsFalse(result.Success); Assert.AreEqual("device does not exist", result.Error); cloud.RequestCallBack = (t, m, p) => { return(new RequestResponse { StatusCode = HttpStatusCode.NotFound, Response = JToken.Parse(@" { 'user_id': '111111111111111111111111', 'id': '222222222222222222222222', 'connected': true, 'ok': true }") }); }; result = await cloud.ClaimDeviceAsync("222222222222222222222222"); Assert.IsNotNull(result); Assert.IsTrue(result.Success); } }
public async Task ClaimDeviceAsyncHttpRequestExceptionTest() { using (var cloud = new ParticleCloudMock()) { var ex = new HttpRequestException("Text HttpClient Request Exception"); cloud.RequestCallBack = (t, m, p) => { throw ex; //return new RequestResponse(); }; var result = await cloud.ClaimDeviceAsync("123"); Assert.IsNotNull(result); Assert.IsFalse(result.Success); Assert.AreEqual(ex.Message, result.Error); Assert.AreEqual(ex, result.Exception); } }
public async Task ClaimDeviceAsyncHttpRequestExceptionTest() { using (var cloud = new ParticleCloudMock()) { var ex = new HttpRequestException("Text HttpClient Request Exception"); cloud.RequestCallBack = (t, m, p) => { throw ex; //return new RequestResponse(); }; var result = await cloud.ClaimDeviceAsync("123"); Assert.IsNotNull(result); Assert.IsFalse(result.Success); Assert.AreEqual(ex.Message, result.Error); Assert.AreEqual(ex, result.Exception); } }
public async Task ClaimDeviceAsyncTest() { using (var cloud = new ParticleCloudMock()) { cloud.RequestCallBack = (t, m, p) => { return new RequestResponse { StatusCode = HttpStatusCode.NotFound, Response = JToken.Parse(@" { ok: false, errors: ['device does not exist'] }") }; }; var ex = Assert.Throws<ArgumentNullException>(() => { cloud.ClaimDeviceAsync(null).GetAwaiter().GetResult(); }); Assert.AreEqual("deviceId", ex.ParamName); var result = await cloud.ClaimDeviceAsync("123"); Assert.IsNotNull(result); Assert.IsFalse(result.Success); Assert.AreEqual("device does not exist", result.Error); cloud.RequestCallBack = (t, m, p) => { return new RequestResponse { StatusCode = HttpStatusCode.NotFound, Response = JToken.Parse(@" { 'user_id': '111111111111111111111111', 'id': '222222222222222222222222', 'connected': true, 'ok': true }") }; }; result = await cloud.ClaimDeviceAsync("222222222222222222222222"); Assert.IsNotNull(result); Assert.IsTrue(result.Success); } }