コード例 #1
0
ファイル: AcceptanceTests.cs プロジェクト: dihan0604/autorest
        public void LroHappyPathTests()
        {
            SwaggerSpecRunner.RunTests(
                SwaggerPath("lro.json"), ExpectedPath("Lro"), generator: "Azure.CSharp");
            using (
                var client = new AutoRestLongRunningOperationTestService(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);
                Assert.Equal("Succeeded", client.LROs.PutAsyncSubResource(new SubProduct()).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();
                client.LROs.DeleteProvisioning202Deletingcanceled200();
                client.LROs.DeleteProvisioning202DeletingFailed200();
                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);
                // Retryable errors
                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.DeleteProvisioning202Accepted200Succeeded();
                client.LRORetrys.Delete202Retry200();
                client.LRORetrys.DeleteAsyncRelativeRetrySucceeded();
                client.LRORetrys.Post202Retry200(new Product {
                    Location = "West US"
                });
                client.LRORetrys.PostAsyncRelativeRetrySucceeded(new Product {
                    Location = "West US"
                });

                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);

                // Failing in CoreCLR - TODO: debug and fix
                // Assert.NotNull(client.LROsCustomHeader.Put201CreatingSucceeded200WithHttpMessagesAsync(
                //                    new Product { Location = "West US" }, customHeaders).Result);

                Assert.NotNull(client.LROsCustomHeader.Post202Retry200WithHttpMessagesAsync(
                                   new Product {
                    Location = "West US"
                }, customHeaders).Result);
            }
        }
コード例 #2
0
ファイル: AcceptanceTests.cs プロジェクト: johanste/autorest
        public void LroSadPathTests()
        {
            using (
                var client = new AutoRestLongRunningOperationTestService(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.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 <CloudException>(() => client.LROSADs.Put200InvalidJson(new Product {
                    Location = "West US"
                }));

                Assert.Throws <CloudException>(
                    () => client.LROSADs.PutAsyncRelativeRetryInvalidJsonPolling(new Product {
                    Location = "West US"
                }));
                // TODO: 4103936 Fix exception type
#if !PORTABLE
                Assert.Throws <RestException>(
                    () => client.LROSADs.PutAsyncRelativeRetryInvalidHeader(new Product {
                    Location = "West US"
                }));
                // TODO: 4103936 Fix exception type
                // UriFormatException invalidHeader = null;
                var invalidHeader = Assert.Throws <UriFormatException>(() => client.LROSADs.Delete202RetryInvalidHeader());
                Assert.NotNull(invalidHeader.Message);

                // TODO: 4103936 Fix exception type
                var invalidAsyncHeader =
                    Assert.Throws <UriFormatException>(() => client.LROSADs.DeleteAsyncRelativeRetryInvalidHeader());
                Assert.NotNull(invalidAsyncHeader.Message);

                // TODO: 4103936 Fix exception type
                invalidHeader = Assert.Throws <UriFormatException>(() => client.LROSADs.Post202RetryInvalidHeader());
                Assert.NotNull(invalidHeader.Message);
                // TODO: 4103936 Fix exception type
                invalidAsyncHeader =
                    Assert.Throws <UriFormatException>(() => client.LROSADs.PostAsyncRelativeRetryInvalidHeader());
                Assert.NotNull(invalidAsyncHeader.Message);
#endif
                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);
            }
        }