private GetRequest BuildGetRequest(EndPointInfo endPointInfo)
		{
			var uri = ConstructEndpoint(endPointInfo);
			var signedUrl = SignHttpGetUrl(uri, endPointInfo);
			var getRequest = new GetRequest(signedUrl, endPointInfo.Headers);
			return getRequest;
		}
		private GetRequest BuildGetRequest(RequestData requestData)
		{
			var uri = ConstructEndpoint(requestData);
			var signedUrl = SignHttpGetUrl(uri, requestData);
			var getRequest = new GetRequest(signedUrl, requestData.Headers);
			return getRequest;
		}
		public Response Get(GetRequest request)
		{
			var webRequest = MakeWebRequest(request.Url, "GET", request.Headers);
			using (var webResponse = GetWebResponse(webRequest))
			{
				return MakeResponse(webResponse);
			}
		}
		public void Can_resolve_uri()
		{
			var url = string.Format("{0}/status?oauth_consumer_key={1}", API_URL, _consumerKey);
			var request = new GetRequest(url, new Dictionary<string, string>());

			var response = new GzipHttpClient().Get(request);
			AssertResponse(response, HttpStatusCode.OK);
		}
		public void Bad_url_should_return_not_found()
		{
			var url = string.Format("{0}/foo/bar/fish/1234?oauth_consumer_key={1}", API_URL, _consumerKey);
			var request = new GetRequest(url, new Dictionary<string, string>());

			var response = new GzipHttpClient().Get(request);
			AssertResponse(response, HttpStatusCode.NotFound);
		}
		public void Can_resolve_uri_that_returns_gzip()
		{
			var url = string.Format("{0}/release/details?oauth_consumer_key={1}&releaseId=12345", API_URL, _consumerKey);
			var request = new GetRequest(url, new Dictionary<string, string>());

			var response = new GzipHttpClient().Get(request);
			AssertResponse(response, HttpStatusCode.OK);
			AssertCanParseBody(response);
		}
Ejemplo n.º 7
0
		public Response Get(GetRequest request)
		{
			var webRequest = MakeWebRequest(request.Url, "GET", request.Headers);

			WebResponse webResponse;
			try
			{
				webResponse = webRequest.GetResponse();
			}
			catch (WebException ex)
			{
				if (ex.Response == null)
				{
					throw;
				}
				webResponse = ex.Response;
			}

			return MakeResponse(webResponse);
		}
		public void Can_resolve_uri_async()
		{
			var url = string.Format("{0}/status?oauth_consumer_key={1}", API_URL, _consumerKey);
			var request = new GetRequest(url, new Dictionary<string, string>());

			var autoResetEvent = new AutoResetEvent(false);
			Response response = null;

			Action<Response> callback = callbackResponse =>
			                            {
			                            	response = callbackResponse;
			                            	autoResetEvent.Set();
			                            };

			new GzipHttpClient().GetAsync(request, callback);

			var signalled = autoResetEvent.WaitOne(_asyncTimeout);
			Assert.That(signalled, Is.True, "event was not signalled");

			AssertResponse(response, HttpStatusCode.OK);
		}
		public void Bad_url_should_return_not_found_async()
		{
			string url = string.Format("{0}/foo/bar/fish/1234?oauth_consumer_key={1}", ApiUrl, consumerKey);
			var request = new GetRequest(url, new Dictionary<string, string>());

			AutoResetEvent autoResetEvent = new AutoResetEvent(false);
			Response response = null;

			Action<Response> callback = callbackResponse =>
			{
				response = callbackResponse;
				autoResetEvent.Set();
			};

			new HttpClientWrapper().GetAsync(request, callback);

			var signalled = autoResetEvent.WaitOne(AsyncTimeout);
			Assert.That(signalled, Is.True, "event was not signalled");

			AssertResponse(response, HttpStatusCode.NotFound);
		}
		public void GetAsync(GetRequest request, Action<Response> callback)
		{
			callback(_fakeResponse);
		}
		public Response Get(GetRequest request)
		{
			throw new NotImplementedException();
		}
		public void GetAsync(GetRequest request, Action<Response> callback)
		{
			var webRequest = MakeWebRequest(request.Url, "GET", request.Headers);
			webRequest.BeginGetResponse(iar => callback(GetAsyncResponse(iar)), webRequest);
		}
		public Response Get(GetRequest request)
		{
			var webRequest = MakeWebRequest(request.Url, "GET", request.Headers);
			
			return TryGetResponse(webRequest.GetResponse);
		}
		public void Can_cope_with_timeouts()
		{
			const string apiUrl = "http://hanging-web-app.7digital.local";
			var request = new GetRequest(apiUrl, new Dictionary<string, string>());

			var response = new GzipHttpClient().Get(request);
			AssertResponse(response, HttpStatusCode.OK);
		}
		public void No_key_should_return_unauthorized()
		{
			var url = string.Format("{0}/status", API_URL);
			var request = new GetRequest(url, new Dictionary<string, string>());

			var response = new GzipHttpClient().Get(request);
			AssertResponse(response, HttpStatusCode.Unauthorized);
		}