示例#1
0
 public NetworkTestBase()
 {
     NetworkClient    = GetServiceClient <NetworkManagementClient>();
     ManagementClient = GetServiceClient <ManagementClient>();
     ComputeClient    = GetServiceClient <ComputeManagementClient>();
     StorageClient    = GetServiceClient <StorageManagementClient>();
     _defaultLocation = ManagementTestUtilities.GetDefaultLocation(ManagementClient, "Compute");
 }
        public void CanGetLocationsForMediaServices()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                var client = GetManagementClient();
                Assert.DoesNotThrow(() =>
                {
                    string location = ManagementTestUtilities.GetDefaultLocation(client, "HighMemory");
                    Assert.NotNull(location);
                });
            }
        }
        public string CreateTestCloudService()
        {
            bool   validServiceNameFound = false;
            string serviceName;

            do
            {
                serviceName = GenerateRandomName(TestArtifactType.CloudService);
                HostedServiceCheckNameAvailabilityResponse nameCheckResponse = ComputeManagementClient.HostedServices.CheckNameAvailability(serviceName);
                validServiceNameFound = nameCheckResponse.IsAvailable;
            }while (!validServiceNameFound);

            Compute.Models.HostedServiceCreateParameters parameter = new Compute.Models.HostedServiceCreateParameters();
            parameter.ServiceName = serviceName;
            parameter.Location    = ManagementTestUtilities.GetDefaultLocation(ManagementClient, "Compute");
            parameter.Label       = serviceName;
            parameter.Description = serviceName;
            AzureOperationResponse response = ComputeManagementClient.HostedServices.Create(parameter);

            RegisterToCleanup(serviceName, _servicesToCleanup);

            return(serviceName + CloudServiceNamingExtension);
        }
        public void CanCreateMediaServicesAccountSuccessfully()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                var mode = HttpMockServer.GetCurrentMode();

                var managementClient   = GetManagementClient();
                var storageClient      = GetStorageManagementClient();
                var mediaClient        = GetMediaServicesManagementClient();
                var storageAccountName = TestUtilities.GenerateName();
                var mediaAccountName   = TestUtilities.GenerateName();

                string location = ManagementTestUtilities.GetDefaultLocation(managementClient, "HighMemory");

                Assert.DoesNotThrow(() =>
                {
                    try
                    {
                        storageClient.StorageAccounts.Create(new StorageAccountCreateParameters
                        {
                            Name        = storageAccountName,
                            AccountType = "Standard_LRS",
                            Location    = location,
                        });
                        var storageResult = storageClient.StorageAccounts.Get(storageAccountName);
                        var blobEndpoint  = storageResult.StorageAccount.Properties.Endpoints.First();

                        var keyResult = storageClient.StorageAccounts.GetKeys(storageAccountName);
                        StorageAccountGetResponse storageStatus = null;
                        int tries = 0;
                        do
                        {
                            TestUtilities.Wait(TimeSpan.FromSeconds(5));
                            storageStatus = storageClient.StorageAccounts.Get(storageAccountName);
                            ++tries;
                        } while (storageStatus.StorageAccount.Properties.Status != StorageAccountStatus.Created &&
                                 tries < 10);

                        mediaClient.Accounts.Create(new MediaServicesAccountCreateParameters
                        {
                            AccountName            = mediaAccountName,
                            BlobStorageEndpointUri = blobEndpoint,
                            StorageAccountName     = storageAccountName,
                            StorageAccountKey      = keyResult.PrimaryKey,
                            Region = location
                        });

                        var mediaGetResult = mediaClient.Accounts.Get(mediaAccountName);
                        Assert.Equal(mediaGetResult.Account.AccountName, mediaAccountName);
                        Assert.Equal(mediaGetResult.Account.AccountRegion, location);
                        Assert.Equal(mediaGetResult.Account.StorageAccountName, storageAccountName);


                        mediaClient.Accounts.RegenerateKey(mediaAccountName, MediaServicesKeyType.Primary);

                        var mediaAccountList     = mediaClient.Accounts.List();
                        var matchingMediaAccount =
                            mediaAccountList.First(
                                m => string.Equals(m.Name, mediaAccountName, StringComparison.Ordinal));
                        Assert.NotNull(matchingMediaAccount);
                    }
                    finally
                    {
                        TestUtilities.Wait(3000);
                        TestUtilities.IgnoreExceptions(() => mediaClient.Accounts.Delete(mediaAccountName));
                        TestUtilities.IgnoreExceptions(() => storageClient.StorageAccounts.Delete(storageAccountName));
                    }
                });
            }
        }