예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
		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);
			}
		}
예제 #4
0
		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);
			}
		}