public async Task FlashKnownAppAsyncHttpRequestExceptionTest()
        {
            using (ParticleCloudMock cloud = new ParticleCloudMock())
            {
                var ex = new HttpRequestException("Unable to resolve");
                cloud.RequestCallBack = (a, b, c) =>
                {
                    throw ex;
                };

                var p      = new ParticleDeviceMock(cloud, JObject.Parse("{'id':'3', 'name': 'test'}"));
                var result = await p.FlashKnownAppAsync("tinker");

                Assert.IsNotNull(result);
                Assert.IsFalse(result.Success);
                Assert.AreEqual(ex.Message, result.Error);
                Assert.AreEqual(ex, result.Exception);
            }
        }
		public async Task FlashKnownAppAsyncHttpRequestExceptionTest()
		{
			using (ParticleCloudMock cloud = new ParticleCloudMock())
			{
				var ex = new HttpRequestException("Unable to resolve");
				cloud.RequestCallBack = (a, b, c) =>
				{
					throw ex;
				};

				var p = new ParticleDeviceMock(cloud, JObject.Parse("{'id':'3', 'name': 'test'}"));
				var result = await p.FlashKnownAppAsync("tinker");
				Assert.IsNotNull(result);
				Assert.IsFalse(result.Success);
				Assert.AreEqual(ex.Message, result.Error);
				Assert.AreEqual(ex, result.Exception);
			}
		}
		public async Task FlashKnownAppAsyncTest()
		{
			using (ParticleCloudMock cloud = new ParticleCloudMock())
			{
				cloud.RequestCallBack = (a, b, c) =>
				{
					Assert.AreEqual("PUT", a);
					Assert.AreEqual("devices/3", b);
					Assert.AreEqual(1, c.Length);
					var p1 = c[0];
					Assert.AreEqual("app", p1.Key);
					Assert.AreEqual("newTest", p1.Value);
					return new RequestResponse
					{
						StatusCode = System.Net.HttpStatusCode.OK,
						Response = JToken.Parse(@"{
			  'ok': false,
			  'code': 500,
			  'errors': [
				'Can\'t flash unknown app newTest'
			  ]
					}")
					};
				};

				var p = new ParticleDeviceMock(cloud, JObject.Parse("{'id':'3', 'name': 'test'}"));

				var exc = Assert.Throws<ArgumentNullException>(() => { p.FlashKnownAppAsync(null).GetAwaiter().GetResult(); });
				Assert.AreEqual("appName", exc.ParamName);

				var result = await p.FlashKnownAppAsync("newTest");
				Assert.IsNotNull(result);
				Assert.IsFalse(result.Success);
				Assert.AreEqual("Can't flash unknown app newTest", result.Error);

				cloud.RequestCallBack = (a, b, c) =>
				{
					Assert.AreEqual("PUT", a);
					Assert.AreEqual("devices/3", b);
					Assert.AreEqual(1, c.Length);
					var p1 = c[0];
					Assert.AreEqual("app", p1.Key);
					Assert.AreEqual("tinker", p1.Value);
					return new RequestResponse
					{
						StatusCode = System.Net.HttpStatusCode.OK,
						Response = JToken.Parse(@"{
  'id': '3',
  'status': 'Update started'
}")
					};
				};

				result = await p.FlashKnownAppAsync("tinker");
				Assert.IsNotNull(result);
				Assert.IsTrue(result.Success);
				Assert.AreEqual("Update started", result.Message);
			}
		}
        public async Task FlashKnownAppAsyncTest()
        {
            using (ParticleCloudMock cloud = new ParticleCloudMock())
            {
                cloud.RequestCallBack = (a, b, c) =>
                {
                    Assert.AreEqual("PUT", a);
                    Assert.AreEqual("devices/3", b);
                    Assert.AreEqual(1, c.Length);
                    var p1 = c[0];
                    Assert.AreEqual("app", p1.Key);
                    Assert.AreEqual("newTest", p1.Value);
                    return(new RequestResponse
                    {
                        StatusCode = System.Net.HttpStatusCode.OK,
                        Response = JToken.Parse(@"{
			  'ok': false,
			  'code': 500,
			  'errors': [
				'Can\'t flash unknown app newTest'
			  ]
					}"                    )
                    });
                };

                var p = new ParticleDeviceMock(cloud, JObject.Parse("{'id':'3', 'name': 'test'}"));

                var exc = Assert.Throws <ArgumentNullException>(() => { p.FlashKnownAppAsync(null).GetAwaiter().GetResult(); });
                Assert.AreEqual("appName", exc.ParamName);

                var result = await p.FlashKnownAppAsync("newTest");

                Assert.IsNotNull(result);
                Assert.IsFalse(result.Success);
                Assert.AreEqual("Can't flash unknown app newTest", result.Error);

                cloud.RequestCallBack = (a, b, c) =>
                {
                    Assert.AreEqual("PUT", a);
                    Assert.AreEqual("devices/3", b);
                    Assert.AreEqual(1, c.Length);
                    var p1 = c[0];
                    Assert.AreEqual("app", p1.Key);
                    Assert.AreEqual("tinker", p1.Value);
                    return(new RequestResponse
                    {
                        StatusCode = System.Net.HttpStatusCode.OK,
                        Response = JToken.Parse(@"{
  'id': '3',
  'status': 'Update started'
}")
                    });
                };

                result = await p.FlashKnownAppAsync("tinker");

                Assert.IsNotNull(result);
                Assert.IsTrue(result.Success);
                Assert.AreEqual("Update started", result.Message);
            }
        }