public void Execute_SuccessfulOperation_MarksResponseAsSuccessfull() { var expectedUri = "test://queue.abc/whatever/"; var expectedRawRequest = new TestableWebRequest(new Uri(expectedUri)); expectedRawRequest.EnqueueResponse(HttpStatusCode.OK, "Success", "Response content", false); TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRawRequest); var request = new RequestWithEmptyPayload(new SettingsFake(), expectedUri, "GET"); var response = request.Execute(); Assert.AreEqual(HttpStatusCode.OK, response.HttpStatus); }
public void Execute_ExpectingEmptyPayload_ConsumesResponseStream() { var expectedUri = "test://queue.abc/whatever/"; var expectedRawRequest = new TestableWebRequest(new Uri(expectedUri)); var expectedRawResponse = new HttpResponseSettings(HttpStatusCode.OK, "Success", "Response content", false); expectedRawRequest.EnqueueResponse(expectedRawResponse); TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRawRequest); var request = new RequestWithEmptyPayload(new SettingsFake(), expectedUri, "GET"); var response = request.Execute(); // expect the response stream to be closed now long x; Assert.Throws<ObjectDisposedException>(() => x = expectedRawResponse.ResponseStream.Position); }
public void Execute_CommonApiException_MapsToProperAzureException(string exceptionName, string errorCode, int httpStatus, string errorMessage) { //arrange string expectedExceptionName = exceptionName + "AzureException"; var expectedUri = "test://common-api-errors.abc/whatever/"; var expectedRawRequest = new TestableWebRequest(new Uri(expectedUri)); expectedRawRequest.EnqueueResponse((HttpStatusCode)httpStatus, errorCode, ErrorContentFor(errorCode, errorMessage), true); TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRawRequest); var request = new RequestWithErrorPayload(new SettingsFake(), expectedUri, "GET", StorageServiceType.QueueService); request.RetryPolicy = new RetryPolicy<ExceptionRetryStrategy>(0); try { //act var response = request.Execute(); } catch (AzureException ae) { //assert Assert.AreEqual(expectedExceptionName, ae.GetType().Name); } }