public async Task SignupWithUserAsyncTest() { using (var cloud = new ParticleCloudMock()) { cloud.RequestCallBack = (t, m, p) => { return(new RequestResponse { StatusCode = HttpStatusCode.OK, Response = JToken.Parse(@" { ok: false, errors:[""username must be an email address""] }") }); }; ArgumentNullException e = Assert.Throws <ArgumentNullException>(() => { cloud.SignupWithUserAsync(null, "test").GetAwaiter().GetResult(); }); Assert.AreEqual("username", e.ParamName); e = Assert.Throws <ArgumentNullException>(() => { cloud.SignupWithUserAsync("test", null).GetAwaiter().GetResult(); }); Assert.AreEqual("password", e.ParamName); var result = await cloud.SignupWithUserAsync("test", "test"); Assert.IsNotNull(result); Assert.IsFalse(result.Success); Assert.AreEqual("username must be an email address", result.Error); cloud.RequestCallBack = (t, m, p) => { return(new RequestResponse { StatusCode = HttpStatusCode.OK, Response = JToken.Parse(@" { ok: true }") }); }; result = await cloud.SignupWithUserAsync("*****@*****.**", "test"); Assert.IsNotNull(result); Assert.IsTrue(result.Success); } }
public async Task SignupWithUserAsyncHttpRequestExceptionTest() { using (var cloud = new ParticleCloudMock()) { var ex = new HttpRequestException("Error Connecting to Server"); cloud.RequestCallBack = (t, m, p) => { throw ex; }; var result = await cloud.SignupWithUserAsync("Test", "test"); Assert.IsNotNull(result); Assert.IsFalse(result.Success); Assert.AreEqual(ex.Message, result.Error); Assert.AreEqual(ex, result.Exception); } }
public async Task SignupWithUserAsyncTest() { using (var cloud = new ParticleCloudMock()) { cloud.RequestCallBack = (t, m, p) => { return new RequestResponse { StatusCode = HttpStatusCode.OK, Response = JToken.Parse(@" { ok: false, errors:[""username must be an email address""] }") }; }; ArgumentNullException e = Assert.Throws<ArgumentNullException>(() => { cloud.SignupWithUserAsync(null, "test").GetAwaiter().GetResult(); }); Assert.AreEqual("username", e.ParamName); e = Assert.Throws<ArgumentNullException>(() => { cloud.SignupWithUserAsync("test", null).GetAwaiter().GetResult(); }); Assert.AreEqual("password", e.ParamName); var result = await cloud.SignupWithUserAsync("test", "test"); Assert.IsNotNull(result); Assert.IsFalse(result.Success); Assert.AreEqual("username must be an email address", result.Error); cloud.RequestCallBack = (t, m, p) => { return new RequestResponse { StatusCode = HttpStatusCode.OK, Response = JToken.Parse(@" { ok: true }") }; }; result = await cloud.SignupWithUserAsync("*****@*****.**", "test"); Assert.IsNotNull(result); Assert.IsTrue(result.Success); } }