public void SharedGalleryImage_GetAndList_Tests() { using (MockContext context = MockContext.Start(this.GetType())) { EnsureClientsInitialized(context); SharedGalleryImage sharedGalleryImageOut = m_CrpClient.SharedGalleryImages.Get(galleryAccessLocation, GalleryUniqueName, GalleryImageName); Trace.TraceInformation("Got the shared gallery image {0} which is shared to current subscription.", GalleryImageName); Assert.NotNull(sharedGalleryImageOut); ValidateSharedGalleryImage(sharedGalleryImageOut); IPage <SharedGalleryImage> sharedGalleryImagesList = m_CrpClient.SharedGalleryImages.List(galleryAccessLocation, GalleryUniqueName, "tenant"); Trace.TraceInformation("Got the shared gallery images which are shared to tenant of current subscription."); int count = sharedGalleryImagesList.Count(); Assert.Equal(1, count); foreach (SharedGalleryImage galleryImage in sharedGalleryImagesList) { if (galleryImage.Name == GalleryImageName) { ValidateSharedGalleryImage(galleryImage); break; } } sharedGalleryImagesList = m_CrpClient.SharedGalleryImages.List(galleryAccessLocation, GalleryUniqueName); count = sharedGalleryImagesList.Count(); Assert.Equal(1, count); Trace.TraceInformation("Got the shared gallery {0} which is shared to current subscription.", GalleryUniqueName); ValidateSharedGalleryImage(sharedGalleryImagesList.First()); sharedGalleryImagesList = m_CrpClient.SharedGalleryImages.List(galleryAccessLocation, GalleryUniqueName, sharedTo: SharedToValues.Tenant); count = sharedGalleryImagesList.Count(); Assert.Equal(1, count); Trace.TraceInformation("Got the shared gallery {0} which is shared to current tenant.", GalleryUniqueName); ValidateSharedGalleryImage(sharedGalleryImagesList.First()); } }
private async Task <string> GetTriggerNameAsync() { IPage <WorkflowTrigger> triggers = await _logicManagementClient.WorkflowTriggers.ListAsync(_resourceGroup, _logicAppName); if (triggers.Any()) { return(triggers.First().Name); } throw new LogicAppTriggerNotFoundException(_logicManagementClient.SubscriptionId, _resourceGroup, _logicAppName, $"Cannot find any trigger for logic app '{_logicAppName}' in resource group '{_resourceGroup}'"); }
public void SupportTicketGetTest() { using (var context = MockContext.Start(this.GetType())) { IPage <Models.SupportTicketDetails> supportTicketList = null; using (var client = context.GetServiceClient <MicrosoftSupportClient>()) { supportTicketList = client.SupportTickets.List(); var supportTicket = client.SupportTickets.Get(supportTicketList.First().Name); Assert.True(!string.IsNullOrWhiteSpace(supportTicket.Id)); Assert.Equal("microsoft.support/supporttickets", supportTicket.Type, ignoreCase: true); Assert.True(!string.IsNullOrWhiteSpace(supportTicket.Name)); } } }
protected void RunTest(ISqlManagementClient client, string resourceGroupName, string serverName, string databaseName) { IPage <SensitivityLabel> sensitivityLabels = ListCurrentSensitivityLabels( client, resourceGroupName, serverName, databaseName); Assert.NotNull(sensitivityLabels); Assert.Empty(sensitivityLabels); sensitivityLabels = ListRecommendedSensitivityLabels(client, resourceGroupName, serverName, databaseName); Assert.NotNull(sensitivityLabels); Assert.NotEmpty(sensitivityLabels); int recommendedLabelsCount = sensitivityLabels.Count(); SensitivityLabel recommendedLabel = sensitivityLabels.First(); string columnName = recommendedLabel.Id.Split("/")[16]; SensitivityLabel newLabel = new SensitivityLabel( labelName: recommendedLabel.LabelName, labelId: recommendedLabel.LabelId, informationType: recommendedLabel.InformationType, informationTypeId: recommendedLabel.InformationTypeId); SensitivityLabel createdLabel = CreateOrUpdateSensitivityLabel(client, resourceGroupName, serverName, databaseName, s_SchemaName, s_TableName, columnName, newLabel); AssertEqual(recommendedLabel, createdLabel); createdLabel = GetSensitivityLabel(client, resourceGroupName, serverName, databaseName, s_SchemaName, s_TableName, columnName); AssertEqual(recommendedLabel, createdLabel); sensitivityLabels = ListRecommendedSensitivityLabels(client, resourceGroupName, serverName, databaseName); Assert.NotNull(sensitivityLabels); Assert.Equal(recommendedLabelsCount - 1, sensitivityLabels.Count()); DeleteSensitivityLabel(client, resourceGroupName, serverName, databaseName, s_SchemaName, s_TableName, columnName); sensitivityLabels = ListRecommendedSensitivityLabels( client, resourceGroupName, serverName, databaseName); Assert.NotNull(sensitivityLabels); Assert.Equal(recommendedLabelsCount, sensitivityLabels.Count()); }
public string EnableProtection(string containerName, string protectedItemName, string policyName) { ProtectionPolicyResource policy = GetPolicyWithRetries(policyName); BackupClient.ProtectionContainers.Refresh(VaultName, ResourceGroup, FabricName); ODataQuery <BMSPOQueryObject> query = new ODataQuery <BMSPOQueryObject>(po => po.BackupManagementType == BackupManagementType.AzureIaasVM); IPage <WorkloadProtectableItemResource> protectableItems = BackupClient.BackupProtectableItems.List(VaultName, ResourceGroup, odataQuery: query); var desiredProtectedItem = (AzureIaaSComputeVMProtectableItem)protectableItems.First( protectableItem => containerName.ToLower().Contains(protectableItem.Name.ToLower()) ).Properties; Assert.NotNull(desiredProtectedItem); var item = new ProtectedItemResource() { Properties = new AzureIaaSComputeVMProtectedItem() { PolicyId = policy.Id, SourceResourceId = desiredProtectedItem.VirtualMachineId, } }; var response = BackupClient.ProtectedItems.CreateOrUpdateWithHttpMessagesAsync( VaultName, ResourceGroup, FabricName, containerName, protectedItemName, item).Result; ValidateOperationResponse(response); var jobResponse = GetOperationResponse <ProtectedItemResource, OperationStatusJobExtendedInfo>( containerName, protectedItemName, response, operationId => BackupClient.ProtectedItemOperationResults.GetWithHttpMessagesAsync( VaultName, ResourceGroup, FabricName, containerName, protectedItemName, operationId).Result, operationId => BackupClient.ProtectedItemOperationStatuses.GetWithHttpMessagesAsync( VaultName, ResourceGroup, FabricName, containerName, protectedItemName, operationId).Result); Assert.NotNull(jobResponse.JobId); return(jobResponse.JobId); }
public void PageSubnets() { using (var httpTest = new HttpTest()) { Identifier subnetId = Guid.NewGuid(); httpTest.RespondWithJson(new SubnetCollection { Subnets = { new Subnet { Id = subnetId } }, SubnetsLinks = { new Link("next", "http://api.com/next") } }); IPage <Subnet> subnets = _cloudNetworkService.ListSubnets(subnetId, 10); httpTest.ShouldHaveCalled(string.Format($"*/subnets?marker={subnetId}&limit=10")); Assert.NotNull(subnets); Assert.Equal(1, subnets.Count()); Assert.Equal(subnetId, subnets.First().Id); Assert.True(subnets.HasNextPage); } }
public void PagePorts() { using (var httpTest = new HttpTest()) { Identifier portId = Guid.NewGuid(); httpTest.RespondWithJson(new PortCollection { Ports = { new Port { Id = portId } }, PortsLinks = { new Link("next", "http://api.com/next") } }); IPage <Port> ports = _cloudNetworkService.ListPorts(portId, 10); httpTest.ShouldHaveCalled(string.Format($"*/ports?marker={portId}&limit=10")); Assert.NotNull(ports); Assert.Equal(1, ports.Count()); Assert.Equal(portId, ports.First().Id); Assert.True(ports.HasNextPage); } }
public void PageNetworks() { using (var httpTest = new HttpTest()) { Identifier networkId = Guid.NewGuid(); httpTest.RespondWithJson(new NetworkCollection { Networks = { new Network { Id = networkId } }, NetworksLinks = { new Link("next", "http://api.com/next") } }); IPage <Network> networks = _cloudNetworkService.ListNetworks(networkId, 10); httpTest.ShouldHaveCalled(string.Format($"*/networks?marker={networkId}&limit=10")); Assert.NotNull(networks); Assert.Equal(1, networks.Count()); Assert.Equal(networkId, networks.First().Id); Assert.True(networks.HasNextPage); } }
public void FirewallFunctionalTest() { using (var context = MockContext.Start(this.GetType())) { var _redisCacheManagementHelper = new RedisCacheManagementHelper(this, context); _redisCacheManagementHelper.TryRegisterSubscriptionForResource(); var resourceGroupName = TestUtilities.GenerateName("RedisFirewall"); var redisCacheName = TestUtilities.GenerateName("RedisFirewall"); var _client = RedisCacheManagementTestUtilities.GetRedisManagementClient(this, context); _redisCacheManagementHelper.TryCreateResourceGroup(resourceGroupName, RedisCacheManagementHelper.Location); _client.Redis.Create(resourceGroupName, redisCacheName, parameters: new RedisCreateParameters { Location = RedisCacheManagementHelper.Location, Sku = new Sku() { Name = SkuName.Premium, Family = SkuFamily.P, Capacity = 1 } }); // First try to get cache and verify that it is premium cache RedisResource response = _client.Redis.Get(resourceGroupName, redisCacheName); Assert.Contains(redisCacheName, response.Id); Assert.Equal(redisCacheName, response.Name); Assert.Equal(ProvisioningState.Succeeded, response.ProvisioningState, ignoreCase: true); Assert.Equal(SkuName.Premium, response.Sku.Name); Assert.Equal(SkuFamily.P, response.Sku.Family); // Set firewall rule for 10.0.0.0 to 10.0.0.32 RedisFirewallRule ruleOne = _client.FirewallRules.CreateOrUpdate(resourceGroupName, redisCacheName, "RuleOne", new RedisFirewallRuleCreateParameters { StartIP = "10.0.0.0", EndIP = "10.0.0.32" }); Assert.Equal("10.0.0.0", ruleOne.StartIP); Assert.Equal("10.0.0.32", ruleOne.EndIP); // Set firewall rule for 10.0.0.64 to 10.0.0.128 RedisFirewallRule ruleTwo = _client.FirewallRules.CreateOrUpdate(resourceGroupName, redisCacheName, "RuleTwo", new RedisFirewallRuleCreateParameters { StartIP = "10.0.0.64", EndIP = "10.0.0.128" }); Assert.Equal("10.0.0.64", ruleTwo.StartIP); Assert.Equal("10.0.0.128", ruleTwo.EndIP); // Get test ruleOne = _client.FirewallRules.Get(resourceGroupName, redisCacheName, "RuleOne"); Assert.Equal("10.0.0.0", ruleOne.StartIP); Assert.Equal("10.0.0.32", ruleOne.EndIP); ruleTwo = _client.FirewallRules.Get(resourceGroupName, redisCacheName, "RuleTwo"); Assert.Equal("10.0.0.64", ruleTwo.StartIP); Assert.Equal("10.0.0.128", ruleTwo.EndIP); // List test IPage <RedisFirewallRule> rules = _client.FirewallRules.List(resourceGroupName, redisCacheName); Assert.Equal(2, rules.Count()); // Delete _client.FirewallRules.Delete(resourceGroupName, redisCacheName, "RuleTwo"); if (Utility.IsLiveTest()) { Thread.Sleep(6000); } rules = _client.FirewallRules.List(resourceGroupName, redisCacheName); Assert.Single(rules); Assert.Equal("10.0.0.0", rules.First().StartIP); Assert.Equal("10.0.0.32", rules.First().EndIP); } }
public async Task CreateListUpdateDelete() { Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback"); using (MockContext context = MockContext.Start(this.GetType())) { var testBase = new ApiManagementTestBase(context); testBase.TryCreateApiManagementService(); // list all the APIs IPage <ApiContract> apiResponse = testBase.client.Api.ListByService( testBase.rgName, testBase.serviceName, null); Assert.NotNull(apiResponse); Assert.Single(apiResponse); Assert.Null(apiResponse.NextPageLink); //api to use ApiContract apiToUse = apiResponse.First(); // list diagnostics: there should be none for the Api currently var apiDiagnostics = testBase.client.ApiDiagnostic.ListByService( testBase.rgName, testBase.serviceName, apiToUse.Name); Assert.NotNull(apiDiagnostics); Assert.Empty(apiDiagnostics); // create new diagnostic, supported Ids are applicationinsights, azuremonitor string apiDiagnosticId = "applicationinsights"; string loggerId = TestUtilities.GenerateName("appInsights"); try { // create a logger Guid applicationInsightsGuid = TestUtilities.GenerateGuid("appInsights"); var credentials = new Dictionary <string, string>(); credentials.Add("instrumentationKey", applicationInsightsGuid.ToString()); var loggerCreateParameters = new LoggerContract(LoggerType.ApplicationInsights, credentials); var loggerContract = await testBase.client.Logger.CreateOrUpdateAsync( testBase.rgName, testBase.serviceName, loggerId, loggerCreateParameters); Assert.NotNull(loggerContract); Assert.Equal(loggerId, loggerContract.Name); Assert.Equal(LoggerType.ApplicationInsights, loggerContract.LoggerType); Assert.NotNull(loggerContract.Credentials); Assert.Equal(1, loggerContract.Credentials.Keys.Count); // create a diagnostic entity with just loggerId var diagnosticContractParams = new DiagnosticContract() { LoggerId = loggerContract.Id }; var apiDiagnosticContract = await testBase.client.ApiDiagnostic.CreateOrUpdateAsync( testBase.rgName, testBase.serviceName, apiToUse.Name, apiDiagnosticId, diagnosticContractParams); Assert.NotNull(apiDiagnosticContract); Assert.Equal(apiDiagnosticId, apiDiagnosticContract.Name); // check the diagnostic entity etag var apiDiagnosticTag = await testBase.client.ApiDiagnostic.GetEntityTagAsync( testBase.rgName, testBase.serviceName, apiToUse.Name, apiDiagnosticId); Assert.NotNull(apiDiagnosticTag); Assert.NotNull(apiDiagnosticTag.ETag); // now update the sampling and other settings of the diagnostic diagnosticContractParams.AlwaysLog = "allErrors"; diagnosticContractParams.Sampling = new SamplingSettings("fixed", 50); var listOfHeaders = new List <string> { "Content-type" }; var bodyDiagnostic = new BodyDiagnosticSettings(512); diagnosticContractParams.Frontend = new PipelineDiagnosticSettings { Request = new HttpMessageDiagnostic() { Body = bodyDiagnostic, Headers = listOfHeaders }, Response = new HttpMessageDiagnostic() { Body = bodyDiagnostic, Headers = listOfHeaders } }; diagnosticContractParams.Backend = new PipelineDiagnosticSettings { Request = new HttpMessageDiagnostic() { Body = bodyDiagnostic, Headers = listOfHeaders }, Response = new HttpMessageDiagnostic() { Body = bodyDiagnostic, Headers = listOfHeaders } }; var updatedApiDiagnostic = await testBase.client.ApiDiagnostic.CreateOrUpdateWithHttpMessagesAsync( testBase.rgName, testBase.serviceName, apiToUse.Name, apiDiagnosticId, diagnosticContractParams, apiDiagnosticTag.ETag); Assert.NotNull(updatedApiDiagnostic); Assert.Equal("allErrors", updatedApiDiagnostic.Body.AlwaysLog); Assert.NotNull(updatedApiDiagnostic.Body.Sampling); Assert.NotNull(updatedApiDiagnostic.Body.Frontend); Assert.NotNull(updatedApiDiagnostic.Body.Backend); // delete the diagnostic entity await testBase.client.ApiDiagnostic.DeleteAsync( testBase.rgName, testBase.serviceName, apiToUse.Name, apiDiagnosticId, updatedApiDiagnostic.Headers.ETag); Assert.Throws <ErrorResponseException>(() => testBase.client.ApiDiagnostic.GetEntityTag( testBase.rgName, testBase.serviceName, apiToUse.Name, apiDiagnosticId)); // check the logger entity etag var loggerTag = await testBase.client.Logger.GetEntityTagAsync( testBase.rgName, testBase.serviceName, loggerId); Assert.NotNull(loggerTag); Assert.NotNull(loggerTag.ETag); // delete the logger entity await testBase.client.Logger.DeleteAsync( testBase.rgName, testBase.serviceName, loggerId, loggerTag.ETag); Assert.Throws <ErrorResponseException>(() => testBase.client.Logger.GetEntityTag(testBase.rgName, testBase.serviceName, loggerId)); } finally { testBase.client.ApiDiagnostic.Delete( testBase.rgName, testBase.serviceName, apiToUse.Name, apiDiagnosticId, "*"); testBase.client.Logger.Delete(testBase.rgName, testBase.serviceName, loggerId, "*"); } } }
public void TestLongTermRetentionV2ResourceGroupBasedCrud() { // MANUAL TEST INSTRUCTIONS // PlayBack Mode: // Remove skip flag // Record Mode: // Create a server and database and fill in the appropriate information below // Set the weekly retention on the database so that the first backup gets picked up // Wait about 18 hours until it gets properly copied and you see the backup when run get backups // string locationName = "brazilsouth"; string resourceGroupName = "brrg"; string serverName = "ltrtest3"; string databaseName = "mydb"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Database database = sqlClient.Databases.Get(resourceGroupName, serverName, databaseName); // Get the backups under the location, server, and database. Assert there is at least one backup for each call. // IPage <LongTermRetentionBackup> backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupLocation(resourceGroupName, locationName); Assert.True(backups.Count() >= 1); backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupServer(resourceGroupName, locationName, serverName); Assert.True(backups.Count() >= 1); backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupDatabase(resourceGroupName, locationName, serverName, databaseName); Assert.True(backups.Count() >= 1); // Get a specific backup using the previous call // LongTermRetentionBackup backup = sqlClient.LongTermRetentionBackups.GetByResourceGroup(resourceGroupName, locationName, serverName, databaseName, backups.First().Name); Assert.NotNull(backup); // Restore the backup // Database restoredDatabase = sqlClient.Databases.CreateOrUpdate( resourceGroupName, serverName, databaseName: SqlManagementTestUtilities.GenerateName(), parameters: new Database { Location = locationName, CreateMode = CreateMode.RestoreLongTermRetentionBackup, LongTermRetentionBackupResourceId = backup.Id }); // Delete the backup. // sqlClient.LongTermRetentionBackups.DeleteByResourceGroupWithHttpMessagesAsync(resourceGroupName, locationName, serverName, databaseName, backup.Name); } }
private void ValidateAgreementList(IPage <IntegrationAccountAgreement> result) { Assert.Equal(1, result.Count()); this.ValidateAgreement(result.First()); Assert.Equal(Constants.NextPageLink, result.NextPageLink); }
private void ValidateRunActionListResponse1(IPage <WorkflowRunAction> page) { Assert.Equal(1, page.Count()); Assert.Equal("http://management.azure.com/actionNextLink", page.NextPageLink); this.ValidateRunAction1(page.First()); }
private void ValidateRunListResponse1(IPage <WorkflowRun> page) { Assert.Single(page); Assert.Equal("http://management.azure.com/runNextLink", page.NextPageLink); this.ValidateRun1(page.First()); }
public void TestLongTermRetentionV2Crud() { // MANUAL INSTRUCTIONS // Create a server and database and fill in the appropriate information below // Set the weekly retention on the database so that the first backup gets picked up // Wait about 18 hours until it gets properly copied and you see the backup when run get backups // string locationName = ""; string resourceGroupName = ""; string serverName = ""; string databaseName = ""; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Database database = sqlClient.Databases.Get(resourceGroupName, serverName, databaseName); // Set the retention policy to two weeks for the weekly retention policy // Microsoft.Azure.Management.Sql.Models.BackupLongTermRetentionPolicy parameters = new Microsoft.Azure.Management.Sql.Models.BackupLongTermRetentionPolicy(weeklyRetention: "P2W"); var policyResult = sqlClient.BackupLongTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serverName, databaseName, parameters).Result; sqlClient.GetPutOrPatchOperationResultAsync(policyResult, new Dictionary <string, List <string> >(), CancellationToken.None).Wait(); // Get the policy and verify the weekly policy is two weeks // Microsoft.Azure.Management.Sql.Models.BackupLongTermRetentionPolicy policy = sqlClient.BackupLongTermRetentionPolicies.Get(resourceGroupName, serverName, databaseName); Assert.Equal(parameters.WeeklyRetention, policy.WeeklyRetention); // Get the backups under the location, server, and database. Assert there is at least one backup for each call. // IPage <LongTermRetentionBackup> backups = sqlClient.LongTermRetentionBackups.ListByLocation(locationName); Assert.True(backups.Count() >= 1); backups = sqlClient.LongTermRetentionBackups.ListByServer(locationName, serverName); Assert.True(backups.Count() >= 1); backups = sqlClient.LongTermRetentionBackups.ListByDatabase(locationName, serverName, databaseName); Assert.True(backups.Count() >= 1); // Get a specific backup using the previous call // LongTermRetentionBackup backup = sqlClient.LongTermRetentionBackups.Get(locationName, serverName, databaseName, backups.First().Name); Assert.NotNull(backup); // Restore the backup // Database restoredDatabase = sqlClient.Databases.CreateOrUpdate( resourceGroupName, serverName, databaseName: SqlManagementTestUtilities.GenerateName(), parameters: new Database { Location = locationName, CreateMode = CreateMode.RestoreLongTermRetentionBackup, LongTermRetentionBackupResourceId = backup.Id }); // Delete the backup. // var deleteResult = sqlClient.LongTermRetentionBackups.BeginDeleteWithHttpMessagesAsync(locationName, serverName, databaseName, backup.Name).Result; sqlClient.GetPutOrPatchOperationResultAsync(deleteResult, new Dictionary <string, List <string> >(), CancellationToken.None).Wait(); // Verify the backup is gone. // try { sqlClient.LongTermRetentionBackups.Get(locationName, serverName, databaseName, backup.Name); } catch (CloudException e) { Assert.Contains(string.Format("'{0}' was not found.", backup.Name), e.Message); } // Set the retention policy back to one week for the weekly retention policy // parameters = new Microsoft.Azure.Management.Sql.Models.BackupLongTermRetentionPolicy(weeklyRetention: "P1W"); policyResult = sqlClient.BackupLongTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serverName, databaseName, parameters).Result; sqlClient.GetPutOrPatchOperationResultAsync(policyResult, new Dictionary <string, List <string> >(), CancellationToken.None).Wait(); // Get the policy and verify the weekly policy is two weeks // policy = sqlClient.BackupLongTermRetentionPolicies.Get(resourceGroupName, serverName, databaseName); Assert.Equal(parameters.WeeklyRetention, policy.WeeklyRetention); } }
private void ValidateRequestHistoryListResponse(IPage <RequestHistory> page) { Assert.Single(page); this.ValidateRequestHistory(page.First()); }
private void ValidateSessionList(IPage <IntegrationAccountSession> result) { Assert.Single(result); this.ValidateSession(result.First()); Assert.Equal(Constants.NextPageLink, result.NextPageLink); }
private void ValidateSchemaList(IPage <IntegrationAccountSchema> result) { Assert.Equal(1, result.Count()); this.ValidateSchema(result.First()); Assert.Equal(Constants.NextPageLink, result.NextPageLink); }
public void TestManagedIntanceLongTermRetentionCrud() { // MANUAL TEST INSTRUCTIONS // PlayBack Mode: // Make sure information below matches what is gets recorded in Session Records // Record Mode: // Create a server and database and fill in the appropriate information below // Set the weekly retention on the database so that the first backup gets picked up // Wait about 18 hours until it gets properly copied and you see the backup when run get backups // OR // Use existing instance/database that already has LTR backups // string locationName = "southeastasia"; string resourceGroupName = "sdk-test-rg"; string managedInstanceName = "sdk-test-mi"; string databaseName = "test"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); //ManagedDatabase database = sqlClient.ManagedDatabases.Get(resourceGroupName, managedInstanceName, databaseName); // Get the backups under the location, server, and database. Assert there is at least one backup for each call. // IPage <ManagedInstanceLongTermRetentionBackup> backups = sqlClient.LongTermRetentionManagedInstanceBackups.ListByLocation(locationName); Assert.True(backups.Count() >= 1); backups = sqlClient.LongTermRetentionManagedInstanceBackups.ListByInstance(locationName, managedInstanceName); Assert.True(backups.Count() >= 1); backups = sqlClient.LongTermRetentionManagedInstanceBackups.ListByDatabase(locationName, managedInstanceName, databaseName); Assert.True(backups.Count() >= 1); // Get a specific backup using the previous call // ManagedInstanceLongTermRetentionBackup backup = sqlClient.LongTermRetentionManagedInstanceBackups.Get(locationName, managedInstanceName, databaseName, backups.First().Name); Assert.NotNull(backup); // Restore the backup // ManagedDatabase restoredDatabase = sqlClient.ManagedDatabases.CreateOrUpdate( resourceGroupName, managedInstanceName, databaseName: SqlManagementTestUtilities.GenerateName(), parameters: new ManagedDatabase { Location = locationName, CreateMode = CreateMode.RestoreLongTermRetentionBackup, LongTermRetentionBackupResourceId = backup.Id }); } }
public void CreateLocalRestorePointWithSecurityProfile() { string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); using (MockContext context = MockContext.Start(this.GetType().FullName)) { string location = "southcentralus"; Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", location); EnsureClientsInitialized(context); var rgName = ComputeManagementTestUtilities.GenerateName(TestPrefix); ImageReference imageRef = new ImageReference(publisher: "MICROSOFTWINDOWSDESKTOP", offer: "WINDOWS-10", version: "latest", sku: "20H2-ENT-G2"); VirtualMachine inputVM; string storageAccountForDisks = TestUtilities.GenerateName(TestPrefix); string availabilitySetName = TestUtilities.GenerateName(TestPrefix); try { // PUT VM with SecurityType = TrustedLaunch VirtualMachine createdVM = CreateVM(rgName, availabilitySetName, storageAccountForDisks, imageRef, out inputVM, hasManagedDisks: true, vmSize: VirtualMachineSizeTypes.StandardD2sV3, securityType: "TrustedLaunch"); string rpcName = ComputeManagementTestUtilities.GenerateName("rpcClientTest"); string rpName = ComputeManagementTestUtilities.GenerateName("rpClientTest"); // Create Restore Point Collection string vmId = createdVM.Id; string vmSize = createdVM.HardwareProfile.VmSize; Dictionary <string, string> tags = new Dictionary <string, string>() { { "testTag", "testTagValue" } }; RestorePointCollection createdRpc = CreateRpc(vmId, rpcName, rgName, location, tags); // Create Restore Point RestorePoint createdRP = CreateRestorePoint(rgName, rpcName, rpName, diskToExclude: null, sourceRestorePointId: null); // GET Disk Restore Point IPage <DiskRestorePoint> listDiskRestorePoint = m_CrpClient.DiskRestorePoint.ListByRestorePoint(rgName, rpcName, rpName); var getDrp = m_CrpClient.DiskRestorePoint.Get(rgName, rpcName, rpName, listDiskRestorePoint.First().Name); Assert.Equal("TrustedLaunch", getDrp.SecurityProfile.SecurityType); } catch (Exception e) { throw e; } finally { m_ResourcesClient.ResourceGroups.Delete(rgName); Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation); } } }
private void ValidateCertificateList(IPage <IntegrationAccountCertificate> result) { Assert.Equal(1, result.Count()); this.ValidateCertificate(result.First()); Assert.Equal(Constants.NextPageLink, result.NextPageLink); }
public void TestDatabaseSensitivityLabels() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); ISqlManagementClient client = context.GetClient <SqlManagementClient>(); Server server = context.CreateServer(resourceGroup); client.FirewallRules.CreateOrUpdate(resourceGroup.Name, server.Name, "sqltestrule", new FirewallRule() { StartIpAddress = "0.0.0.0", EndIpAddress = "255.255.255.255" }); Database database = client.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, SqlManagementTestUtilities.GenerateName(s_DatabaseNamePrefix), new Database() { Location = server.Location, }); Assert.NotNull(database); if (HttpMockServer.GetCurrentMode() != HttpRecorderMode.Playback) { SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder() { DataSource = string.Format(server.FullyQualifiedDomainName, server.Name), UserID = SqlManagementTestUtilities.DefaultLogin, Password = SqlManagementTestUtilities.DefaultPassword, InitialCatalog = database.Name }; using (SqlConnection connection = new SqlConnection(builder.ConnectionString)) { connection.Open(); SqlCommand command = new SqlCommand(string.Format(@" CREATE TABLE {0} ( PersonID int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) );", s_TableName), connection); command.ExecuteNonQuery(); } SleepIfNeeded(); IPage <SensitivityLabel> sensitivityLabels = client.SensitivityLabels.ListByDatabase(resourceGroup.Name, server.Name, database.Name); Assert.NotNull(sensitivityLabels); Assert.NotEmpty(sensitivityLabels); Assert.DoesNotContain(sensitivityLabels, label => label.Name.Equals(s_Current)); int labelsCount = sensitivityLabels.Count(); SensitivityLabel sensitivityLabel = sensitivityLabels.First(); string columnName = sensitivityLabel.Id.Split("/")[16]; SensitivityLabel responseLabel = client.SensitivityLabels.CreateOrUpdate( resourceGroup.Name, server.Name, database.Name, s_SchemaName, s_TableName, columnName, new SensitivityLabel(labelName: sensitivityLabel.LabelName, informationType: sensitivityLabel.InformationType)); AssertEqual(sensitivityLabel, responseLabel); responseLabel = client.SensitivityLabels.Get(resourceGroup.Name, server.Name, database.Name, s_SchemaName, s_TableName, columnName, SensitivityLabelSource.Current); AssertEqual(sensitivityLabel, responseLabel); sensitivityLabels = client.SensitivityLabels.ListByDatabase(resourceGroup.Name, server.Name, database.Name); Assert.NotNull(sensitivityLabels); Assert.Equal(labelsCount, sensitivityLabels.Count()); Assert.Equal(labelsCount - 1, sensitivityLabels.Where(l => l.Name == "recommended").Count()); Assert.Contains(sensitivityLabels, label => label.Name.Equals(s_Current)); client.SensitivityLabels.Delete(resourceGroup.Name, server.Name, database.Name, s_SchemaName, s_TableName, columnName); sensitivityLabels = client.SensitivityLabels.ListByDatabase(resourceGroup.Name, server.Name, database.Name); Assert.NotNull(sensitivityLabels); Assert.Equal(labelsCount, sensitivityLabels.Count()); Assert.DoesNotContain(sensitivityLabels, label => label.Name.Equals(s_Current)); client.Databases.Delete(resourceGroup.Name, server.Name, database.Name); client.Servers.Delete(resourceGroup.Name, server.Name); } } }
[Fact(Skip = "Manual test due to long setup time required (over 18 hours).")] public void TestUpdateLongTermRetentionBackup() { // MANUAL TEST INSTRUCTIONS // PlayBack Mode: // Remove skip flag // Record Mode: // Create a server and database and fill in the appropriate information below // Set the weekly retention on the database so that the first backup gets picked up // Wait about 18 hours until it gets properly copied and you see the backup when run get backups // string locationName = "Southeast Asia"; string resourceGroupName = "testrg"; string serverName = "ayang-stage-seas"; string databaseName = "ltr3"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Database database = sqlClient.Databases.Get(resourceGroupName, serverName, databaseName); // Get backups under database // IPage <LongTermRetentionBackup> backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupDatabase(resourceGroupName, locationName, serverName, databaseName); Assert.True(backups.Count() >= 1); // Get a single backup using the previous call // LongTermRetentionBackup backup = sqlClient.LongTermRetentionBackups.GetByResourceGroup(resourceGroupName, locationName, serverName, databaseName, backups.First().Name); Assert.NotNull(backup); // Update the Backup Storage Redundancy of the backup // UpdateLongTermRetentionBackupParameters updateParameters = new UpdateLongTermRetentionBackupParameters(requestedBackupStorageRedundancy: "Geo"); LongTermRetentionBackupOperationResult restoredDatabase = sqlClient.LongTermRetentionBackups.Update(locationName, serverName, databaseName, backup.Name, updateParameters); } }
public void TestScriptActionsOnRunningCluster() { string clusterName = "hdisdk-scriptactions"; string testName = "TestScriptActionsOnRunningCluster"; string suiteName = GetType().FullName; ClusterCreateParameters createParams = ClusterCreateParametersHelpers.GetCustomCreateParametersIaas(testName); HDInsightManagementTestUtilities.CreateClusterInNewResourceGroupAndRunTest(suiteName, testName, clusterName, createParams, (client, rgName) => { string scriptName = "script1"; //Upload script to storage account. UploadScriptToStorageAccount(createParams); //Execute script actions, and persist on success. IList <RuntimeScriptAction> scriptActionParams = GetExecuteScriptActionParams(scriptName, InstallGiraph); client.Clusters.ExecuteScriptActions(rgName, clusterName, scriptActionParams, true); //List script actions and validate script is persisted. IPage <RuntimeScriptActionDetail> scriptActionsList = client.ScriptActions.ListByCluster(rgName, clusterName); Assert.Single(scriptActionsList); RuntimeScriptActionDetail scriptAction = scriptActionsList.First(); Assert.Equal(scriptActionParams[0].Name, scriptAction.Name); Assert.Equal(scriptActionParams[0].Uri, scriptAction.Uri); Assert.Equal(scriptActionParams[0].Roles, scriptAction.Roles); //Delete script action. client.ScriptActions.Delete(rgName, clusterName, scriptName); //List script actions and validate script is deleted. scriptActionsList = client.ScriptActions.ListByCluster(rgName, clusterName); Assert.Empty(scriptActionsList); //List script action history and validate script appears there. IPage <RuntimeScriptActionDetail> listHistoryResponse = client.ScriptExecutionHistory.ListByCluster(rgName, clusterName); Assert.Single(listHistoryResponse); scriptAction = listHistoryResponse.First(); Assert.Equal(1, scriptAction.ExecutionSummary.Count); Assert.Equal(scriptActionParams[0].Name, scriptAction.Name); Assert.Equal(scriptActionParams[0].Uri, scriptAction.Uri); Assert.Equal(scriptActionParams[0].Roles, scriptAction.Roles); Assert.Equal("Succeeded", scriptAction.Status); //Get the script action by ID and validate it's the same action. scriptAction = client.ScriptActions.GetExecutionDetail(rgName, clusterName, listHistoryResponse.First().ScriptExecutionId.Value.ToString()); Assert.Equal(scriptActionParams[0].Name, scriptAction.Name); //Execute script actions, but don't persist on success. scriptActionParams = GetExecuteScriptActionParams("script5baf", InstallGiraph); client.Clusters.ExecuteScriptActions(rgName, clusterName, scriptActionParams, false); //List script action history and validate the new script also appears. listHistoryResponse = client.ScriptExecutionHistory.ListByCluster(rgName, clusterName); Assert.Equal(2, listHistoryResponse.Count()); scriptAction = listHistoryResponse.FirstOrDefault(a => a.Name.Equals(scriptActionParams[0].Name, StringComparison.OrdinalIgnoreCase)); Assert.NotNull(scriptAction); Assert.Equal(1, scriptAction.ExecutionSummary.Count); Assert.Equal(scriptActionParams[0].Name, scriptAction.Name); Assert.Equal(scriptActionParams[0].Uri, scriptAction.Uri); Assert.Equal(scriptActionParams[0].Roles, scriptAction.Roles); Assert.Equal("Succeeded", scriptAction.Status); //Promote non-persisted script. client.ScriptExecutionHistory.Promote(rgName, clusterName, listHistoryResponse.First().ScriptExecutionId.Value.ToString()); //Execute failing script action. string failingScriptUri = GetFailingScriptUri(createParams); IList <RuntimeScriptAction> failingScriptActionParams = GetExecuteScriptActionParams(string.Format("script0cc4", Guid.NewGuid()).Substring(0, 10), failingScriptUri); CloudException ex = Assert.Throws <CloudException>(() => client.Clusters.ExecuteScriptActions(rgName, clusterName, failingScriptActionParams, true)); //List script action list and validate the promoted script is the only one there. scriptActionsList = client.ScriptActions.ListByCluster(rgName, clusterName); Assert.Single(scriptActionsList); Assert.Equal(1, scriptAction.ExecutionSummary.Count); Assert.Equal(scriptActionParams[0].Name, scriptAction.Name); Assert.Equal(scriptActionParams[0].Uri, scriptAction.Uri); Assert.Equal(scriptActionParams[0].Roles, scriptAction.Roles); Assert.Equal("Succeeded", scriptAction.Status); //List script action history and validate all three scripts are there. listHistoryResponse = client.ScriptExecutionHistory.ListByCluster(rgName, clusterName); Assert.Equal(3, listHistoryResponse.Count()); Assert.Equal(2, listHistoryResponse.Count(a => a.Status == "Succeeded")); Assert.Equal(1, listHistoryResponse.Count(a => a.Status == "Failed")); }); }
public void TestCopyLongTermRetentionBackup() { // MANUAL TEST INSTRUCTIONS // PlayBack Mode: // Make sure information below matches what is gets recorded in Session Records // Record Mode: // Create a server and database and fill in the appropriate information below // Set the weekly retention on the database so that the first backup gets picked up // Wait about 18 hours until it gets properly copied and you see the backup when run get backups // OR // Use existing instance/database that already has LTR backups // string locationName = "southeastasia"; string subscriptionId = "01c4ec88-e179-44f7-9eb0-e9719a5087ab"; string resourceGroupName = "testrg"; string sourceServerName = "ayang-stage-seas"; string sourceDatabaseName = "ltr3"; string targetServerName = "ayang-stage-seas-1"; string targetDatabaseName = "ltr1"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Database database = sqlClient.Databases.Get(resourceGroupName, sourceServerName, sourceDatabaseName); // Get backups under database // IPage <LongTermRetentionBackup> backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupDatabase(resourceGroupName, locationName, sourceServerName, sourceDatabaseName); Assert.True(backups.Count() >= 1); // Get a single backup using the previous call // LongTermRetentionBackup backup = sqlClient.LongTermRetentionBackups.GetByResourceGroup(resourceGroupName, locationName, sourceServerName, sourceDatabaseName, backups.First().Name); Assert.NotNull(backup); // Copy the backup to target database // string targetServerResourceId = String.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/servers/{2}", subscriptionId, resourceGroupName, targetServerName); CopyLongTermRetentionBackupParameters copyParameters = new CopyLongTermRetentionBackupParameters( targetSubscriptionId: subscriptionId, targetResourceGroup: resourceGroupName, targetServerResourceId: targetServerResourceId, targetDatabaseName: targetDatabaseName); LongTermRetentionBackupOperationResult restoredDatabase = sqlClient.LongTermRetentionBackups.Copy(locationName, sourceServerName, sourceDatabaseName, backup.Name, copyParameters); } }
private void ValidateWorkflowList1(IPage <Workflow> result) { Assert.Single(result); this.ValidateWorkflow1(result.First()); Assert.Equal("http://workflowlist1nextlink", result.NextPageLink); }
private void ValidateTriggerListResponse1(IPage <WorkflowTrigger> page) { Assert.Single(page); Assert.Equal("http://management.azure.com/triggerNextLink", page.NextPageLink); this.ValidateTrigger1(page.First()); }
private void ValidateTriggerHistoryListResponse1(IPage <WorkflowTriggerHistory> page) { Assert.Equal(1, page.Count()); Assert.Equal("http://management.azure.com/keyNextLink", page.NextPageLink); this.ValidateTriggerHistory1(page.First()); }