Skip to content

Commit

Permalink
Added a new LongRunningOperations test to verify that a CloudExceptio…
Browse files Browse the repository at this point in the history
…n is thrown even when a JSONException occurs Deserializing the HTTPResponse.Content
  • Loading branch information
John-Hart committed Apr 14, 2016
1 parent 8b015ac commit 3622e2b
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ public void TestAsyncOperationWithMissingProvisioningState()
Assert.Equal("100", resource.Id);
}

[Fact]
public void TestAsyncOperationWithNonSuccessStatusAndInvalidResponseContent()
{
var tokenCredentials = new TokenCredentials("123", "abc");
var handler = new PlaybackTestHandler(MockAsyncOperaionWithNonSuccessStatusAndInvalidResponseContent());
var fakeClient = new RedisManagementClient(tokenCredentials, handler);
fakeClient.LongRunningOperationInitialTimeout = fakeClient.LongRunningOperationRetryTimeout = 0;
var error = Assert.Throws<CloudException>(() =>
fakeClient.RedisOperations.Delete("rg", "redis", "1234"));
Assert.Equal("Long running operation failed with status 'BadRequest'.", error.Message);
Assert.Null(error.Body);
}

[Fact]
public void TestPutOperationWithoutProvisioningState()
{
Expand Down Expand Up @@ -737,6 +750,22 @@ private IEnumerable<HttpResponseMessage> MockAsyncOperaionWithMissingProvisionin
yield return response3;
}

private IEnumerable<HttpResponseMessage> MockAsyncOperaionWithNonSuccessStatusAndInvalidResponseContent()
{
var response1 = new HttpResponseMessage(HttpStatusCode.Accepted)
{
Content = new StringContent("")
};
response1.Headers.Add("Location", "http://custom/status");
yield return response1;

var response2 = new HttpResponseMessage(HttpStatusCode.BadRequest)
{
Content = new StringContent("<")
};
yield return response2;
}

private IEnumerable<HttpResponseMessage> MockPutOperaionWithoutProvisioningStateInResponse()
{
var response1 = new HttpResponseMessage(HttpStatusCode.Created)
Expand Down

0 comments on commit 3622e2b

Please sign in to comment.