コード例 #1
0
        public void AttemptToGetJsonFromRealApiWithBadKey()
        {
            bool gotResult = false;
            ManualResetEvent waiter = new ManualResetEvent(false);

            IApiRequestHandler handler = new ApiRequestHandler(new ApiUriBuilder());
            handler.SendRequestAsync(
                ApiMethod.CountryLookup,
                "test",
                "test",
                null,
                null,
                null,
                (Response<JObject> result) =>
                {
                    Assert.IsNotNull(result, "Expected a result");
                    Assert.IsNotNull(result.Error, "Expected an error");
                    Assert.IsNull(result.Result, "Expected no result object");
                    Assert.IsNotNull(result.StatusCode, "Expected a status code - this test can fail when you run tests with no internet connection!");
                    Assert.AreEqual(HttpStatusCode.Forbidden, result.StatusCode.Value, "Expected a 401");
                    gotResult = true;
                    waiter.Set();
                });

            // Wait for the response and parsing...
            waiter.WaitOne(5000);
            Assert.IsTrue(gotResult, "Expected a result flag");
        }
コード例 #2
0
        public void AttemptToGetJsonFromBadHttpUrlToEnsureWebExceptionCaught()
        {
            bool gotResult = false;
            ManualResetEvent waiter = new ManualResetEvent(false);

            IApiRequestHandler handler = new ApiRequestHandler(new TestHttpUriBuilder(new Uri("http://baduritesting.co")));
            handler.SendRequestAsync(
                ApiMethod.CountryLookup,
                "test",
                "test",
                null,
                null,
                null,
                (Response<JObject> result) =>
                {
                    Assert.IsNotNull(result, "Expected a result");
                    Assert.IsNotNull(result.Error, "Expected an error");
                    Assert.IsNull(result.Result, "Expected no result object");
                    gotResult = true;
                    waiter.Set();
                });

            // Wait for the response and parsing...
            waiter.WaitOne(5000);
            Assert.IsTrue(gotResult, "Expected a result flag");
        }
コード例 #3
0
        public void AttemptToGetStatusCodeFromRealUri()
        {
            bool gotResult = false;
            ManualResetEvent waiter = new ManualResetEvent(false);

            IApiRequestHandler handler = new ApiRequestHandler(new TestHttpUriBuilder(new Uri("http://www.nokia.com")));
            handler.SendRequestAsync(
                ApiMethod.CountryLookup,
                "test",
                "test",
                null,
                null,
                null,
                (Response<JObject> result) =>
                {
                    Assert.IsNotNull(result, "Expected a result");
                    Assert.IsNotNull(result.Error, "Expected an error");
                    Assert.IsNull(result.Result, "Expected no result object");
                    Assert.IsNotNull(result.StatusCode, "Expected a status code - this test can fail when you run tests with no internet connection!");
                    gotResult = true;
                    waiter.Set();
                });

            // Wait for the response and parsing...
            waiter.WaitOne(5000);
            Assert.IsTrue(gotResult, "Expected a result flag");
        }
コード例 #4
0
        public void GetJsonFromLocalFileToTestSuccessfulRequestAndJsonParsing()
        {
            bool gotResult = false;
            ManualResetEvent waiter = new ManualResetEvent(false);

            IApiRequestHandler handler = new ApiRequestHandler(new LocalFileUriBuilder("country.json"));
            handler.SendRequestAsync(
                ApiMethod.CountryLookup,
                "test",
                "test",
                null,
                null,
                null,
                (Response<JObject> result) =>
                {
                    Assert.IsNotNull(result, "Expected a result");
                    Assert.IsNull(result.Error, "Expected no error");
                    Assert.IsNotNull(result.Result, "Expected a result object");
                    gotResult = true;
                    waiter.Set();
                });

            // Wait for the response and parsing...
            waiter.WaitOne(1000);
            Assert.IsTrue(gotResult, "Expected a result flag");
        }
コード例 #5
0
        public void RequestWithValidHeaderIsSuccessful()
        {
            bool gotResult = false;
            ManualResetEvent waiter = new ManualResetEvent(false);

            IApiRequestHandler handler = new ApiRequestHandler(new TestHttpUriBuilder(new Uri("http://www.nokia.com")));
            handler.SendRequestAsync(
                new CountryResolver("test", "test"),
                new MockMusicClientSettings("test", "test", null),
                null,
                null,
                (Response<JObject> result) =>
                {
                    Assert.IsNotNull(result, "Expected a result");
                    Assert.IsNotNull(result.Error, "Expected an error");
                    Assert.IsNull(result.Result, "Expected no result object");
                    Assert.IsNotNull(result.StatusCode, "Expected a status code - this test can fail when you run tests with no internet connection!");
                    gotResult = true;
                    waiter.Set();
                },
                new Dictionary<string, string> { { "Custom", @"test" } });

            // Wait for the response and parsing...
            waiter.WaitOne(5000);
            Assert.IsTrue(gotResult, "Expected a result flag");
        }
コード例 #6
0
        public void GetJsonFromLocalFileToTestSuccessfulRequestAndBadJsonHandling()
        {
            bool gotResult = false;
            ManualResetEvent waiter = new ManualResetEvent(false);

            IApiRequestHandler handler = new ApiRequestHandler(new LocalFileUriBuilder("bad-result.json"));
            handler.SendRequestAsync(
                new CountryResolver("test", "test"),
                new MockMusicClientSettings("test", "test", null),
                null,
                null,
                (Response<JObject> result) =>
                {
                    Assert.IsNotNull(result, "Expected a result");
                    Assert.IsNotNull(result.Error, "Expected an error");
                    Assert.IsNull(result.Result, "Expected no result object");
                    gotResult = true;
                    waiter.Set();
                });

            // Wait for the response and parsing...
            waiter.WaitOne(1000);
            Assert.IsTrue(gotResult, "Expected a result flag");
        }