public void LroHappyPathTestsRest() { SwaggerSpecRunner.RunTests( SwaggerPath("lro.json"), ExpectedPath("Lro"), generator: "Azure.CSharp"); using ( var client = new AutoRestLongRunningOperationTestServiceClient(Fixture.Uri, new TokenCredentials(Guid.NewGuid().ToString()))) { client.LongRunningOperationRetryTimeout = 0; var customHeaders = new Dictionary <string, List <string> > { { "x-ms-client-request-id", new List <string> { "9C4D50EE-2D56-4CD3-8152-34347DC9F2B0" } } }; Assert.Equal("Succeeded", client.LRORetrys.Put201CreatingSucceeded200(new Product { Location = "West US" }).ProvisioningState); Assert.Equal("Succeeded", client.LRORetrys.PutAsyncRelativeRetrySucceeded(new Product { Location = "West US" }).ProvisioningState); client.LRORetrys.Post202Retry200(new Product { Location = "West US" }); client.LRORetrys.PostAsyncRelativeRetrySucceeded(new Product { Location = "West US" }); Assert.NotNull(client.LROsCustomHeader.Put201CreatingSucceeded200WithHttpMessagesAsync( new Product { Location = "West US" }, customHeaders).Result); } }
public void LroSadPathTests() { using ( var client = new AutoRestLongRunningOperationTestServiceClient(Fixture.Uri, new TokenCredentials(Guid.NewGuid().ToString()))) { client.LongRunningOperationRetryTimeout = 0; var exception = Assert.Throws <CloudException>( () => client.LROSADs.PutNonRetry400(new Product { Location = "West US" })); Assert.Contains("Expected", exception.Message, StringComparison.Ordinal); exception = Assert.Throws <CloudException>( () => client.LROSADs.PutNonRetry201Creating400(new Product { Location = "West US" })); Assert.Equal("Error from the server", exception.Body.Message); Assert.NotNull(exception.Request); Assert.NotNull(exception.Response); exception = Assert.Throws <CloudException>(() => client.LROSADs.PutNonRetry201Creating400InvalidJson(new Product { Location = "West US" })); Assert.Null(exception.Body); Assert.Equal("Long running operation failed with status 'BadRequest'.", exception.Message); exception = Assert.Throws <CloudException>( () => client.LROSADs.PutAsyncRelativeRetry400(new Product { Location = "West US" })); Assert.Equal("Long running operation failed with status 'BadRequest'.", exception.Message); exception = Assert.Throws <CloudException>(() => client.LROSADs.DeleteNonRetry400()); Assert.Contains("Expected", exception.Message, StringComparison.Ordinal); exception = Assert.Throws <CloudException>(() => client.LROSADs.Delete202NonRetry400()); Assert.Equal("Long running operation failed with status 'BadRequest'.", exception.Message); exception = Assert.Throws <CloudException>(() => client.LROSADs.DeleteAsyncRelativeRetry400()); Assert.Equal("Long running operation failed with status 'BadRequest'.", exception.Message); exception = Assert.Throws <CloudException>( () => client.LROSADs.PostNonRetry400(new Product { Location = "West US" })); Assert.Equal("Expected bad request message", exception.Message); exception = Assert.Throws <CloudException>( () => client.LROSADs.Post202NonRetry400(new Product { Location = "West US" })); Assert.Equal("Long running operation failed with status 'BadRequest'.", exception.Message); exception = Assert.Throws <CloudException>( () => client.LROSADs.PostAsyncRelativeRetry400(new Product { Location = "West US" })); Assert.Equal("Long running operation failed with status 'BadRequest'.", exception.Message); exception = Assert.Throws <CloudException>( () => client.LROSADs.PutError201NoProvisioningStatePayload(new Product { Location = "West US" })); Assert.Equal("The response from long running operation does not contain a body.", exception.Message); exception = Assert.Throws <CloudException>( () => client.LROSADs.PutAsyncRelativeRetryNoStatus(new Product { Location = "West US" })); Assert.Equal("The response from long running operation does not contain a body.", exception.Message); exception = Assert.Throws <CloudException>( () => client.LROSADs.PutAsyncRelativeRetryNoStatusPayload(new Product { Location = "West US" })); Assert.Equal("The response from long running operation does not contain a body.", exception.Message); Assert.Throws <SerializationException>(() => client.LROSADs.Put200InvalidJson(new Product { Location = "West US" })); Assert.Throws <CloudException>( () => client.LROSADs.PutAsyncRelativeRetryInvalidJsonPolling(new Product { Location = "West US" })); Assert.Throws <SerializationException>( () => client.LROSADs.PutAsyncRelativeRetryInvalidHeader(new Product { Location = "West US" })); var invalidHeader = Assert.Throws <SerializationException>(() => client.LROSADs.Delete202RetryInvalidHeader()); Assert.NotNull(invalidHeader.Message); var invalidAsyncHeader = Assert.Throws <SerializationException>(() => client.LROSADs.DeleteAsyncRelativeRetryInvalidHeader()); Assert.NotNull(invalidAsyncHeader.Message); invalidHeader = Assert.Throws <SerializationException>(() => client.LROSADs.Post202RetryInvalidHeader()); Assert.NotNull(invalidHeader.Message); invalidAsyncHeader = Assert.Throws <SerializationException>(() => client.LROSADs.PostAsyncRelativeRetryInvalidHeader()); Assert.NotNull(invalidAsyncHeader.Message); var invalidPollingBody = Assert.Throws <CloudException>( () => client.LROSADs.DeleteAsyncRelativeRetryInvalidJsonPolling()); Assert.NotNull(invalidPollingBody.Message); invalidPollingBody = Assert.Throws <CloudException>( () => client.LROSADs.PostAsyncRelativeRetryInvalidJsonPolling()); Assert.NotNull(invalidPollingBody.Message); client.LROSADs.Delete204Succeeded(); var noStatusInPollingBody = Assert.Throws <CloudException>(() => client.LROSADs.DeleteAsyncRelativeRetryNoStatus()); Assert.Equal("The response from long running operation does not contain a body.", noStatusInPollingBody.Message); var invalidOperationEx = Assert.Throws <CloudException>(() => client.LROSADs.Post202NoLocation()); Assert.Contains("Location header is missing from long running operation.", invalidOperationEx.Message, StringComparison.Ordinal); exception = Assert.Throws <CloudException>(() => client.LROSADs.PostAsyncRelativeRetryNoPayload()); Assert.Equal("The response from long running operation does not contain a body.", exception.Message); } }
public void LroHappyPathTests() { using ( var client = new AutoRestLongRunningOperationTestServiceClient(Fixture.Uri, new TokenCredentials(Guid.NewGuid().ToString()))) { client.LongRunningOperationRetryTimeout = 0; Assert.Equal("Succeeded", client.LROs.Put201CreatingSucceeded200(new Product { Location = "West US" }).ProvisioningState); var exception = Assert.Throws <CloudException>( () => client.LROs.Put201CreatingFailed200(new Product { Location = "West US" })); Assert.Contains("Long running operation failed", exception.Message, StringComparison.Ordinal); Assert.Equal("Succeeded", client.LROs.Put200UpdatingSucceeded204(new Product { Location = "West US" }).ProvisioningState); exception = Assert.Throws <CloudException>( () => client.LROs.Put200Acceptedcanceled200(new Product { Location = "West US" }).ProvisioningState); Assert.Contains("Long running operation failed", exception.Message, StringComparison.Ordinal); Assert.Equal("Succeeded", client.LROs.PutNoHeaderInRetry(new Product { Location = "West US" }).ProvisioningState); Assert.Equal("Succeeded", client.LROs.PutAsyncNoHeaderInRetry(new Product { Location = "West US" }).ProvisioningState); Assert.Equal("Succeeded", client.LROs.PutSubResource(new SubProduct().ProvisioningState).ProvisioningState); Assert.Equal("Succeeded", client.LROs.PutAsyncSubResource(new SubProduct().ProvisioningState).ProvisioningState); Assert.Equal("100", client.LROs.PutNonResource(new Sku()).Id); Assert.Equal("100", client.LROs.PutAsyncNonResource(new Sku()).Id); client.LROs.Post202Retry200(new Product { Location = "West US" }); Assert.Equal("Succeeded", client.LROs.Put200Succeeded(new Product { Location = "West US" }).ProvisioningState); Assert.Equal("100", client.LROs.Put200SucceededNoState(new Product { Location = "West US" }).Id); Assert.Equal("100", client.LROs.Put202Retry200(new Product { Location = "West US" }).Id); Assert.Equal("Succeeded", client.LROs.PutAsyncRetrySucceeded(new Product { Location = "West US" }).ProvisioningState); Assert.Equal("Succeeded", client.LROs.PutAsyncNoRetrySucceeded(new Product { Location = "West US" }).ProvisioningState); exception = Assert.Throws <CloudException>(() => client.LROs.PutAsyncRetryFailed(new Product { Location = "West US" })); Assert.Contains("Long running operation failed", exception.Message, StringComparison.Ordinal); exception = Assert.Throws <CloudException>( () => client.LROs.PutAsyncNoRetrycanceled(new Product { Location = "West US" })); Assert.Contains("Long running operation failed", exception.Message, StringComparison.Ordinal); client.LROs.Delete204Succeeded(); client.LROs.Delete202Retry200(); client.LROs.Delete202NoRetry204(); client.LROs.DeleteAsyncNoRetrySucceeded(); client.LROs.DeleteNoHeaderInRetry(); client.LROs.DeleteAsyncNoHeaderInRetry(); exception = Assert.Throws <CloudException>(() => client.LROs.DeleteAsyncRetrycanceled()); Assert.Contains("Long running operation failed", exception.Message, StringComparison.Ordinal); exception = Assert.Throws <CloudException>(() => client.LROs.DeleteAsyncRetryFailed()); Assert.Contains("Long running operation failed", exception.Message, StringComparison.Ordinal); client.LROs.DeleteAsyncRetrySucceeded(); client.LROs.DeleteProvisioning202Accepted200Succeeded(); exception = Assert.Throws <CloudException>(() => client.LROs.DeleteProvisioning202Deletingcanceled200()); Assert.Contains("Long running operation failed with status 'Canceled'", exception.Message, StringComparison.Ordinal); exception = Assert.Throws <CloudException>(() => client.LROs.DeleteProvisioning202DeletingFailed200()); Assert.Contains("Long running operation failed with status 'Failed'", exception.Message, StringComparison.Ordinal); client.LROs.Post202NoRetry204(new Product { Location = "West US" }); exception = Assert.Throws <CloudException>(() => client.LROs.PostAsyncRetryFailed()); Assert.Contains("Long running operation failed with status 'Failed'", exception.Message, StringComparison.Ordinal); Assert.NotNull(exception.Body); var error = exception.Body; Assert.NotNull(error.Code); Assert.NotNull(error.Message); exception = Assert.Throws <CloudException>(() => client.LROs.PostAsyncRetrycanceled()); Assert.Contains("Long running operation failed with status 'Canceled'", exception.Message, StringComparison.Ordinal); Product prod = client.LROs.PostAsyncRetrySucceeded(); Assert.Equal("100", prod.Id); prod = client.LROs.PostAsyncNoRetrySucceeded(); Assert.Equal("100", prod.Id); var sku = client.LROs.Post200WithPayload(); Assert.Equal("1", sku.Id); client.LRORetrys.DeleteProvisioning202Accepted200Succeeded(); client.LRORetrys.Delete202Retry200(); client.LRORetrys.DeleteAsyncRelativeRetrySucceeded(); var customHeaders = new Dictionary <string, List <string> > { { "x-ms-client-request-id", new List <string> { "9C4D50EE-2D56-4CD3-8152-34347DC9F2B0" } } }; Assert.NotNull(client.LROsCustomHeader.PutAsyncRetrySucceededWithHttpMessagesAsync( new Product { Location = "West US" }, customHeaders).Result); Assert.NotNull(client.LROsCustomHeader.PostAsyncRetrySucceededWithHttpMessagesAsync( new Product { Location = "West US" }, customHeaders).Result); Assert.NotNull(client.LROsCustomHeader.Post202Retry200WithHttpMessagesAsync( new Product { Location = "West US" }, customHeaders).Result); } }