Beispiel #1
0
        public void DeleteVaultRemovesVaultTest()
        {
            using (UndoContext undoContext = UndoContext.Current)
            {
                undoContext.Start();

                BackupVaultServicesManagementClient client = GetServiceClient <BackupVaultServicesManagementClient>();

                string resourceGroupName = ConfigurationManager.AppSettings["resourceGroupName"];
                string location          = ConfigurationManager.AppSettings["Location"];
                string resourceName      = "delTestRes";
                string defaultSku        = "standard";

                AzureBackupVaultCreateOrUpdateParameters parameters = new AzureBackupVaultCreateOrUpdateParameters()
                {
                    Location   = location,
                    Properties = new AzureBackupVaultProperties()
                    {
                        Sku = new SkuProperties()
                        {
                            Name = defaultSku,
                        },
                    },
                };

                AzureBackupVaultGetResponse createResponse = client.Vault.CreateOrUpdate(resourceGroupName, resourceName, parameters, GetCustomRequestHeaders());
                Assert.True(createResponse.StatusCode == HttpStatusCode.OK || createResponse.StatusCode == HttpStatusCode.Created,
                            "Unable to create test resource");

                AzureBackupVaultGetResponse deleteResponse = client.Vault.Delete(resourceGroupName, resourceName, GetCustomRequestHeaders());
                Assert.NotNull(deleteResponse);
                Assert.Equal(deleteResponse.StatusCode, HttpStatusCode.OK);

                bool resourceDeleted = false;
                try
                {
                    AzureBackupVaultGetResponse getResponse = client.Vault.Get(resourceGroupName, resourceName, GetCustomRequestHeaders());
                }
                catch (Exception ex)
                {
                    if (ex.GetType() == typeof(Hyak.Common.CloudException))
                    {
                        Hyak.Common.CloudException cloudEx = ex as Hyak.Common.CloudException;
                        if (cloudEx != null &&
                            cloudEx.Error != null &&
                            !string.IsNullOrEmpty(cloudEx.Error.Code) &&
                            cloudEx.Error.Code == "ResourceNotFound")
                        {
                            resourceDeleted = true;
                        }
                    }
                }

                Assert.True(resourceDeleted, "Resource still exists after deletion");
            }
        }
        void UnregisterContainerDeletesContainer()
        {
            using (UndoContext undoContext = UndoContext.Current)
            {
                undoContext.Start();

                BackupVaultServicesManagementClient client = GetServiceClient <BackupVaultServicesManagementClient>();
                string containerId  = ConfigurationManager.AppSettings["ContainerId"];
                string friendlyName = ConfigurationManager.AppSettings["ContainerFriendlyName"];

                OperationResponse response = client.Container.UnregisterMarsContainer(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, containerId, GetCustomRequestHeaders());
                // Response Validation
                Assert.NotNull(response);
                Assert.True(response.StatusCode == HttpStatusCode.NoContent, "Status code should be NoContent");

                bool containerDeleted = false;
                try
                {
                    ListMarsContainerOperationResponse getResponse = client.Container.ListMarsContainersByTypeAndFriendlyName(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, MarsContainerType.Machine, friendlyName, GetCustomRequestHeaders());
                    if (getResponse.ListMarsContainerResponse.Value.Count == 0)
                    {
                        containerDeleted = true;
                    }
                }
                catch (Exception ex)
                {
                    if (ex.GetType() == typeof(Hyak.Common.CloudException))
                    {
                        Hyak.Common.CloudException cloudEx = ex as Hyak.Common.CloudException;
                        if (cloudEx != null &&
                            cloudEx.Error != null &&
                            !string.IsNullOrEmpty(cloudEx.Error.Code) &&
                            cloudEx.Error.Code == "ResourceNotFound")
                        {
                            containerDeleted = true;
                        }
                    }
                }

                Assert.True(containerDeleted, "Container still exists after unregistration");
            }
        }
Beispiel #3
0
        public AzureRestExceptionRecord(Hyak.Common.CloudException exception, ErrorRecord record, bool inner = false) : base(exception, record, inner)
        {
            if (exception != null)
            {
                if (exception.Error != null)
                {
                    ServerMessage = string.Format($"{exception.Error.Code}: {exception.Error.Message} ({exception.Error.OriginalMessage})");
                }

                if (exception.Response != null)
                {
                    ServerResponse = new HttpResponseInfo(exception.Response);
                }

                if (exception.Request != null)
                {
                    RequestMessage = new HttpRequestInfo(exception.Request);
                }
            }
        }