public static T GetServiceClient <T>() where T : class { var factory = (TestEnvironmentFactory) new CSMTestEnvironmentFactory(); var testEnvironment = factory.GetTestEnvironment(); ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateErrorHandler; BackupVaultServicesManagementClient client; string resourceName = ConfigurationManager.AppSettings["ResourceName"]; string resourceGroupName = ConfigurationManager.AppSettings["ResourceGroupName"]; if (testEnvironment.UsesCustomUri()) { client = new BackupVaultServicesManagementClient( resourceName, resourceGroupName, testEnvironment.Credentials as SubscriptionCloudCredentials, testEnvironment.BaseUri); } else { client = new BackupVaultServicesManagementClient( resourceName, resourceGroupName, testEnvironment.Credentials as SubscriptionCloudCredentials); } return(GetServiceClient <T>(factory, client)); }
void EnableContainerReregistrationSetsReregisterFlag() { using (UndoContext undoContext = UndoContext.Current) { undoContext.Start(); BackupVaultServicesManagementClient client = GetServiceClient <BackupVaultServicesManagementClient>(); string containerId = ConfigurationManager.AppSettings["ContainerId"]; string friendlyName = ConfigurationManager.AppSettings["ContainerFriendlyName"]; EnableReregistrationRequest request = new EnableReregistrationRequest() { ContainerReregistrationState = new ContainerReregistrationState() { EnableReregistration = true, }, }; OperationResponse response = client.Container.EnableMarsContainerReregistration(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, containerId, request, GetCustomRequestHeaders()); // Response Validation Assert.NotNull(response); Assert.True(response.StatusCode == HttpStatusCode.NoContent, "Status code should be NoContent"); // Basic Validation ListMarsContainerOperationResponse getResponse = client.Container.ListMarsContainersByTypeAndFriendlyName(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, MarsContainerType.Machine, friendlyName, GetCustomRequestHeaders()); Assert.True(getResponse.ListMarsContainerResponse.Value.Any(marsContainer => { return(marsContainer.ContainerType == MarsContainerType.Machine.ToString() && marsContainer.Properties != null && string.Equals(marsContainer.Properties.FriendlyName, friendlyName, StringComparison.OrdinalIgnoreCase) && marsContainer.Properties.CanReRegister == true); }), "Reregistration doesn't appear to have been enabled for the input container"); } }
public void ListVaultsByResourceGroupReturnsVaultsinResourceGroup() { using (UndoContext undoContext = UndoContext.Current) { undoContext.Start(); BackupVaultServicesManagementClient client = GetServiceClient <BackupVaultServicesManagementClient>(); string resourceGroupName = ConfigurationManager.AppSettings["resourceGroupName"]; string armResourceId = ConfigurationManager.AppSettings["ARMResourceId"]; string location = ConfigurationManager.AppSettings["Location"]; string resourceName = ConfigurationManager.AppSettings["ResourceName"]; string resourceType = ConfigurationManager.AppSettings["ResourceType"]; string locationShort = ConfigurationManager.AppSettings["LocationShort"]; int top = 100; AzureBackupVaultListResponse response = client.Vault.ListByResourceGroup(resourceGroupName, top, GetCustomRequestHeaders()); // Response Validation Assert.NotNull(response); Assert.True(response.StatusCode == HttpStatusCode.OK, "Status code should be OK"); Assert.NotNull(response.Vaults); // Basic Validation Assert.True(response.Vaults.Any(vault => { return(vault.Id == armResourceId && (vault.Location == location || vault.Location == locationShort) && vault.Name == resourceName && vault.Type == resourceType); }), "Obtained vault list doesn't container the input resource"); } }
public void GetResourceStorageConfigReturnsStorageTypeTest() { using (UndoContext undoContext = UndoContext.Current) { undoContext.Start(); BackupVaultServicesManagementClient client = GetServiceClient <BackupVaultServicesManagementClient>(); string resourceGroupName = ConfigurationManager.AppSettings["resourceGroupName"]; string resourceName = ConfigurationManager.AppSettings["ResourceName"]; GetResourceStorageConfigResponse response = client.Vault.GetResourceStorageConfig(resourceGroupName, resourceName, GetCustomRequestHeaders()); // Response Validation Assert.NotNull(response); Assert.True(response.StatusCode == HttpStatusCode.OK, "Status code should be OK"); Assert.NotNull(response.StorageDetails); // Basic Validation var validStorageTypes = Enum.GetNames(typeof(AzureBackupVaultStorageType)); Assert.True(validStorageTypes.Any(validStorageType => validStorageType == response.StorageDetails.StorageType), "Obtained storage type of vault is invalid"); var validStorageTypeStates = Enum.GetNames(typeof(AzureBackupVaultStorageTypeState)); Assert.True(validStorageTypeStates.Any(validStorageTypeState => validStorageTypeState == response.StorageDetails.StorageTypeState), "Obtained storage type state of vault is invalid"); } }
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"); } }
public void UploadCertReturnsValidResponseTest() { using (UndoContext undoContext = UndoContext.Current) { undoContext.Start(); BackupVaultServicesManagementClient client = GetServiceClient <BackupVaultServicesManagementClient>(); string subscriptionId = ConfigurationManager.AppSettings["SubscriptionId"]; string resourceName = ConfigurationManager.AppSettings["ResourceName"]; string resourceId = ConfigurationManager.AppSettings["ResourceId"]; string certFriendlyName = VaultTestHelper.GenerateCertFriendlyName(subscriptionId, resourceName); X509Certificate2 cert = VaultTestHelper.CreateSelfSignedCert(VaultTestHelper.DefaultIssuer, certFriendlyName, VaultTestHelper.DefaultPassword, DateTime.UtcNow.AddMinutes(-10), DateTime.UtcNow.AddHours(VaultTestHelper.GetCertificateExpiryInHours())); string rawCertDataString = Convert.ToBase64String(cert.RawData); VaultCredUploadCertRequest vaultCredUploadCertRequest = new VaultCredUploadCertRequest() { RawCertificateData = new RawCertificateData() { Certificate = rawCertDataString, }, }; VaultCredUploadCertResponse response = client.Vault.UploadCertificate("IdMgmtInternalCert", vaultCredUploadCertRequest, GetCustomRequestHeaders()); // Response Validation Assert.NotNull(response); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.ResourceCertificateAndACSDetails); // Basic Validation Assert.False(string.IsNullOrEmpty(response.ResourceCertificateAndACSDetails.GlobalAcsHostName), "Returned Global ACS Host Name shouldn't be null or empty"); Assert.False(string.IsNullOrEmpty(response.ResourceCertificateAndACSDetails.GlobalAcsNamespace), "Returned Global ACS Namespace shouldn't be null or empty"); Assert.False(string.IsNullOrEmpty(response.ResourceCertificateAndACSDetails.GlobalAcsRPRealm), "Returned Global ACS RP Realm shouldn't be null or empty"); // Extra Validation Assert.True(string.Equals(VaultTestHelper.DefaultIssuer, response.ResourceCertificateAndACSDetails.Issuer), "Downloaded and uploaded cert Issuers don't match"); Assert.True(string.Equals(resourceId, response.ResourceCertificateAndACSDetails.ResourceId.ToString()), "Downloaded and uploaded resource IDs don't match"); } }
public static T GetServiceClient <T>() where T : class { var factory = (TestEnvironmentFactory) new CSMTestEnvironmentFactory(); var testEnvironment = factory.GetTestEnvironment(); ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateErrorHandler; var credentials = new SubscriptionCredentialsAdapter( testEnvironment.AuthorizationContext.TokenCredentials[TokenAudience.Management], testEnvironment.SubscriptionId); if (typeof(T) == typeof(BackupVaultServicesManagementClient)) { BackupVaultServicesManagementClient client; if (testEnvironment.UsesCustomUri()) { client = new BackupVaultServicesManagementClient( credentials, testEnvironment.BaseUri); } else { client = new BackupVaultServicesManagementClient( credentials); } return(GetServiceClient <T>(factory, client)); } else { BackupServicesManagementClient client; if (testEnvironment.UsesCustomUri()) { client = new BackupServicesManagementClient( credentials, testEnvironment.BaseUri); } else { client = new BackupServicesManagementClient( credentials); } return(GetVaultServiceClient <T>(factory, client)); } }
public void CreateOrUpdateVaultReturnsValidCodeTest() { using (UndoContext undoContext = UndoContext.Current) { undoContext.Start(); BackupVaultServicesManagementClient client = GetServiceClient <BackupVaultServicesManagementClient>(); string location = ConfigurationManager.AppSettings["Location"]; string resourceGroupName = ConfigurationManager.AppSettings["resourceGroupName"]; string resourceName = ConfigurationManager.AppSettings["ResourceName"]; string armResourceId = ConfigurationManager.AppSettings["ARMResourceId"]; string resourceType = ConfigurationManager.AppSettings["ResourceType"]; string defaultSku = "standard"; AzureBackupVaultCreateOrUpdateParameters parameters = new AzureBackupVaultCreateOrUpdateParameters() { Location = location, Properties = new AzureBackupVaultProperties() { Sku = new SkuProperties() { Name = defaultSku, }, }, }; AzureBackupVaultGetResponse response = client.Vault.CreateOrUpdate(resourceGroupName, resourceName, parameters, GetCustomRequestHeaders()); // Response Validation Assert.NotNull(response); Assert.True(response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created, "Status Code should either be OK or Created"); Assert.NotNull(response.Vault); // Basic Validation //Assert.True(string.Equals(response.Vault.Id, armResourceId, StringComparison.OrdinalIgnoreCase), // "Obtained vault ID doesn't match the input ARM resource ID"); //Assert.True(string.Equals(response.Vault.Location, location), // "Obtained vault location doesn't match the input resource location"); //Assert.True(string.Equals(response.Vault.Name, resourceName), // "Obtained vault name doesn't match the input resource name"); //Assert.True(string.Equals(response.Vault.Type, resourceType), // "Obtained vault type doesn't match the input resource type"); //Assert.NotNull(response.Vault.Properties); //Assert.NotNull(response.Vault.Properties.Sku); //Assert.True(string.Equals(response.Vault.Properties.Sku.Name, defaultSku, StringComparison.OrdinalIgnoreCase), // "Obtained vault SKU doesn't match the input resource SKU"); } }
public static T GetServiceClient <T>() where T : class { var factory = (TestEnvironmentFactory) new CSMTestEnvironmentFactory(); var testEnvironment = factory.GetTestEnvironment(); ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateErrorHandler; if (typeof(T) == typeof(BackupVaultServicesManagementClient)) { BackupVaultServicesManagementClient client; if (testEnvironment.UsesCustomUri()) { client = new BackupVaultServicesManagementClient( testEnvironment.Credentials as SubscriptionCloudCredentials, testEnvironment.BaseUri); } else { client = new BackupVaultServicesManagementClient( testEnvironment.Credentials as SubscriptionCloudCredentials); } return(GetServiceClient <T>(factory, client)); } else { BackupServicesManagementClient client; if (testEnvironment.UsesCustomUri()) { client = new BackupServicesManagementClient( testEnvironment.Credentials as SubscriptionCloudCredentials, testEnvironment.BaseUri); } else { client = new BackupServicesManagementClient( testEnvironment.Credentials as SubscriptionCloudCredentials); } return(GetVaultServiceClient <T>(factory, client)); } }
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"); } }
public static T GetServiceClient <T>(TestEnvironmentFactory factory, BackupVaultServicesManagementClient client) where T : class { TestEnvironment testEnvironment = factory.GetTestEnvironment(); HttpMockServer instance; try { instance = HttpMockServer.CreateInstance(); } catch (ApplicationException) { HttpMockServer.Initialize("TestEnvironment", "InitialCreation"); instance = HttpMockServer.CreateInstance(); } T obj2 = typeof(T).GetMethod("WithHandler", new Type[1] { typeof(DelegatingHandler) }).Invoke((object)client, new object[1] { (object)instance }) as T; if (HttpMockServer.Mode == HttpRecorderMode.Record) { HttpMockServer.Variables[TestEnvironment.SubscriptionIdKey] = testEnvironment.SubscriptionId; } if (HttpMockServer.Mode == HttpRecorderMode.Playback) { PropertyInfo property1 = typeof(T).GetProperty("LongRunningOperationInitialTimeout", typeof(int)); PropertyInfo property2 = typeof(T).GetProperty("LongRunningOperationRetryTimeout", typeof(int)); if (property1 != (PropertyInfo)null && property2 != (PropertyInfo)null) { property1.SetValue((object)obj2, (object)-1); property2.SetValue((object)obj2, (object)-1); } } return(obj2); }
void ListMarsContainersByTypeReturnsNonZeroContainers() { using (UndoContext undoContext = UndoContext.Current) { undoContext.Start(); BackupVaultServicesManagementClient client = GetServiceClient <BackupVaultServicesManagementClient>(); string subscriptionId = ConfigurationManager.AppSettings["SubscriptionId"]; string resourceName = ConfigurationManager.AppSettings["ResourceName"]; string resourceId = ConfigurationManager.AppSettings["ResourceId"]; string containerId = ConfigurationManager.AppSettings["ContainerId"]; string containerStampId = ConfigurationManager.AppSettings["ContainerStampId"]; string containerStampUri = ConfigurationManager.AppSettings["ContainerStampUri"]; string friendlyName = ConfigurationManager.AppSettings["ContainerFriendlyName"]; string uniqueName = ConfigurationManager.AppSettings["ContainerUniqueName"]; ListMarsContainerOperationResponse response = client.Container.ListMarsContainersByType(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, MarsContainerType.Machine, GetCustomRequestHeaders()); // Response Validation Assert.NotNull(response); Assert.True(response.StatusCode == HttpStatusCode.OK, "Status code should be OK"); Assert.NotNull(response.ListMarsContainerResponse); // Basic Validation Assert.True(response.ListMarsContainerResponse.Value.Any(marsContainer => { return(marsContainer.ContainerType == MarsContainerType.Machine.ToString() && marsContainer.Properties != null && marsContainer.Properties.ContainerId.ToString() == containerId && marsContainer.Properties.ContainerStampId.ToString() == containerStampId && marsContainer.Properties.ContainerStampUri == containerStampUri && marsContainer.Properties.CustomerType == CustomerType.OBS.ToString() && string.Equals(marsContainer.Properties.FriendlyName, friendlyName, StringComparison.OrdinalIgnoreCase) && string.Equals(marsContainer.UniqueName, uniqueName, StringComparison.OrdinalIgnoreCase)); }), "Obtained container list doesn't contain the input container"); } }
public void UpdateStorageTypeReturnsValidCodeTest() { using (UndoContext undoContext = UndoContext.Current) { undoContext.Start(); BackupVaultServicesManagementClient client = GetServiceClient <BackupVaultServicesManagementClient>(); UpdateVaultStorageTypeRequest updateVaultStorageTypeRequest = new UpdateVaultStorageTypeRequest() { StorageTypeProperties = new StorageTypeProperties() { StorageModelType = AzureBackupVaultStorageType.LocallyRedundant.ToString(), }, }; OperationResponse response = client.Vault.UpdateStorageType(updateVaultStorageTypeRequest, GetCustomRequestHeaders()); // Response Validation Assert.NotNull(response); Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); } }
protected void SetupManagementClients() { BackupVaultServicesMgmtClient = GetBackupVaultServicesManagementClient(); //helper.SetupManagementClients(BackupServicesMgmtClient); helper.SetupSomeOfManagementClients(BackupVaultServicesMgmtClient); }