示例#1
0
        public void MediaServiceListByResourceGroupTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler3 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                // Create clients
                var mediaMgmtClient = MediaManagementTestUtilities.GetMediaManagementClient(context, handler1);
                var resourcesClient = MediaManagementTestUtilities.GetResourceManagementClient(context, handler2);
                var storageClient   = MediaManagementTestUtilities.GetStorageManagementClient(context, handler3);

                var location = MediaManagementTestUtilities.TryGetLocation(resourcesClient, MediaManagementTestUtilities.DefaultLocation);

                // Create resource group
                var rgname = MediaManagementTestUtilities.CreateResourceGroup(resourcesClient, location);

                // List media services by resource group
                var mediaservices = mediaMgmtClient.Mediaservices.List(rgname);
                Assert.Empty(mediaservices);

                // Create storage account
                var storageAccount = MediaManagementTestUtilities.CreateStorageAccount(storageClient, rgname, location);

                // Create a media service
                var accountName  = TestUtilities.GenerateName("media");
                var mediaService = new MediaService
                {
                    Location = MediaManagementTestUtilities.DefaultLocation,
                    Tags     = new Dictionary <string, string>
                    {
                        { "key1", "value1" },
                        { "key2", "value2" }
                    },
                    StorageAccounts = new List <StorageAccount>
                    {
                        new StorageAccount
                        {
                            Id   = storageAccount.Id,
                            Type = StorageAccountType.Primary
                        }
                    }
                };
                mediaMgmtClient.Mediaservices.CreateOrUpdate(rgname, accountName, mediaService);

                mediaservices = mediaMgmtClient.Mediaservices.List(rgname);
                Assert.Single(mediaservices);

                mediaMgmtClient.Mediaservices.Delete(rgname, accountName);
                MediaManagementTestUtilities.DeleteStorageAccount(storageClient, rgname, storageAccount.Name);
                MediaManagementTestUtilities.DeleteResourceGroup(resourcesClient, rgname);
            }
        }
        public void CreateMediaServicesAccount()
        {
            Location = MediaManagementTestUtilities.TryGetLocation(ResourceClient, MediaManagementTestUtilities.DefaultLocation);

            ResourceGroup = MediaManagementTestUtilities.CreateResourceGroup(ResourceClient, Location);

            // Create storage account
            var storageAccount = MediaManagementTestUtilities.CreateStorageAccount(StorageClient, ResourceGroup, Location);

            StorageAccountName = storageAccount.Name;

            // Create a media service account
            string accountName  = TestUtilities.GenerateName("media");
            var    mediaService = new MediaService
            {
                Location = MediaManagementTestUtilities.DefaultLocation,
                Tags     = new Dictionary <string, string>
                {
                    { "key1", "value1" },
                    { "key2", "value2" }
                },
                StorageAccounts = new List <Microsoft.Azure.Management.Media.Models.StorageAccount>
                {
                    new Microsoft.Azure.Management.Media.Models.StorageAccount
                    {
                        Id   = storageAccount.Id,
                        Type = StorageAccountType.Primary
                    }
                }
            };

            MediaService mediaAccount = MediaClient.Mediaservices.CreateOrUpdate(ResourceGroup, accountName, mediaService);

            AccountName = mediaAccount.Name;
        }
        protected MockContext StartMockContextAndInitializeClients(string className,
                                                                   // Automatically populates the methodName parameter with the calling method, which
                                                                   // gets used to generate recorder file names.
                                                                   [System.Runtime.CompilerServices.CallerMemberName]
                                                                   string methodName = "")
        {
            MockContext context = MockContext.Start(className, methodName);

            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler3 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            // Create clients
            MediaClient    = MediaManagementTestUtilities.GetMediaManagementClient(context, handler1);
            ResourceClient = MediaManagementTestUtilities.GetResourceManagementClient(context, handler2);
            StorageClient  = MediaManagementTestUtilities.GetStorageManagementClient(context, handler3);

            return(context);
        }
        public void DeleteMediaServicesAccount()
        {
            if (!string.IsNullOrEmpty(AccountName))
            {
                MediaClient.Mediaservices.Delete(ResourceGroup, AccountName);
            }

            if (!string.IsNullOrEmpty(StorageAccountName))
            {
                MediaManagementTestUtilities.DeleteStorageAccount(StorageClient, ResourceGroup, StorageAccountName);
            }

            if (!string.IsNullOrEmpty(ResourceGroup))
            {
                MediaManagementTestUtilities.DeleteResourceGroup(ResourceClient, ResourceGroup);
            }
        }
示例#5
0
        public void MediaServiceCheckNameAvailabiltyTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler3 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                // Create clients
                var mediaMgmtClient = MediaManagementTestUtilities.GetMediaManagementClient(context, handler1);
                var resourcesClient = MediaManagementTestUtilities.GetResourceManagementClient(context, handler2);
                var storageClient   = MediaManagementTestUtilities.GetStorageManagementClient(context, handler3);

                var location = MediaManagementTestUtilities.TryGetLocation(resourcesClient, MediaManagementTestUtilities.DefaultLocation);
                var lowerCaseLocationWithoutSpaces = location.Replace(" ", string.Empty).ToLowerInvariant(); // TODO: Fix this once the bug is addressed

                // Create resource group
                var rgname = MediaManagementTestUtilities.CreateResourceGroup(resourcesClient, location);

                // List media services by resource group
                var mediaservices = mediaMgmtClient.Mediaservices.List(rgname);
                Assert.Empty(mediaservices);

                // Create storage account
                var storageAccount = MediaManagementTestUtilities.CreateStorageAccount(storageClient, rgname, location);

                string mediaServicesType = "Microsoft.Media/MediaServices";
                var    accountName       = TestUtilities.GenerateName("media");

                // check name availabilty
                var checkNameAvailabilityOutput = mediaMgmtClient.Locations.CheckNameAvailability(lowerCaseLocationWithoutSpaces, accountName, mediaServicesType);
                Assert.True(checkNameAvailabilityOutput.NameAvailable);

                var mediaService = new MediaService
                {
                    Location = location,
                    Tags     = new Dictionary <string, string>
                    {
                        { "key1", "value1" },
                        { "key2", "value2" }
                    },
                    StorageAccounts = new List <StorageAccount>
                    {
                        new StorageAccount
                        {
                            Id   = storageAccount.Id,
                            Type = StorageAccountType.Primary
                        }
                    }
                };
                mediaMgmtClient.Mediaservices.CreateOrUpdate(rgname, accountName, mediaService);

                mediaservices = mediaMgmtClient.Mediaservices.List(rgname);
                Assert.Single(mediaservices);

                // check name availabilty
                checkNameAvailabilityOutput = mediaMgmtClient.Locations.CheckNameAvailability(lowerCaseLocationWithoutSpaces, accountName, mediaServicesType);
                Assert.False(checkNameAvailabilityOutput.NameAvailable);

                mediaMgmtClient.Mediaservices.Delete(rgname, accountName);
                MediaManagementTestUtilities.DeleteStorageAccount(storageClient, rgname, storageAccount.Name);
                MediaManagementTestUtilities.DeleteResourceGroup(resourcesClient, rgname);
            }
        }
示例#6
0
        public void MediaServiceRegenerateKeyTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler3 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                // Create clients
                var mediaMgmtClient = MediaManagementTestUtilities.GetMediaManagementClient(context, handler1);
                var resourcesClient = MediaManagementTestUtilities.GetResourceManagementClient(context, handler2);
                var storageClient   = MediaManagementTestUtilities.GetStorageManagementClient(context, handler3);

                var location = MediaManagementTestUtilities.TryGetLocation(resourcesClient, MediaManagementTestUtilities.DefaultLocation);

                // Create resource group
                var rgname = MediaManagementTestUtilities.CreateResourceGroup(resourcesClient, location);

                // Create storage account
                var storageAccount = MediaManagementTestUtilities.CreateStorageAccount(storageClient, rgname, location);

                // Create a media service
                var accountName  = TestUtilities.GenerateName("media");
                var mediaService = new MediaService
                {
                    Location = MediaManagementTestUtilities.DefaultLocation,
                    Tags     = new Dictionary <string, string>
                    {
                        { "key1", "value1" },
                        { "key2", "value2" }
                    },
                    StorageAccounts = new List <StorageAccount>
                    {
                        new StorageAccount
                        {
                            Id        = storageAccount.Id,
                            IsPrimary = true
                        }
                    }
                };
                mediaMgmtClient.MediaService.Create(rgname, accountName, mediaService);

                var serviceKeys = mediaMgmtClient.MediaService.ListKeys(rgname, accountName);
                Assert.NotNull(serviceKeys.PrimaryKey);
                Assert.NotNull(serviceKeys.SecondaryKey);

                // regenerate the primary key
                mediaMgmtClient.MediaService.RegenerateKey(rgname, accountName, new RegenerateKeyInput(KeyType.Primary));
                var serviceKeysUpdated1 = mediaMgmtClient.MediaService.ListKeys(rgname, accountName);
                Assert.NotNull(serviceKeysUpdated1.PrimaryKey);
                Assert.NotEqual(serviceKeys.PrimaryKey, serviceKeysUpdated1.PrimaryKey);
                Assert.Equal(serviceKeys.SecondaryKey, serviceKeysUpdated1.SecondaryKey);

                // regenerate the secondary key
                mediaMgmtClient.MediaService.RegenerateKey(rgname, accountName, new RegenerateKeyInput(KeyType.Secondary));
                var serviceKeysUpdated2 = mediaMgmtClient.MediaService.ListKeys(rgname, accountName);
                Assert.NotNull(serviceKeysUpdated2.SecondaryKey);
                Assert.NotEqual(serviceKeysUpdated1.SecondaryKey, serviceKeysUpdated2.SecondaryKey);
                Assert.Equal(serviceKeysUpdated1.PrimaryKey, serviceKeysUpdated2.PrimaryKey);

                mediaMgmtClient.MediaService.Delete(rgname, accountName);
                MediaManagementTestUtilities.DeleteStorageAccount(storageClient, rgname, storageAccount.Name);
                MediaManagementTestUtilities.DeleteResourceGroup(resourcesClient, rgname);
            }
        }
示例#7
0
        public void MediaServiceCheckNameAvailabiltyTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler3 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                // Create clients
                var mediaMgmtClient = MediaManagementTestUtilities.GetMediaManagementClient(context, handler1);
                var resourcesClient = MediaManagementTestUtilities.GetResourceManagementClient(context, handler2);
                var storageClient   = MediaManagementTestUtilities.GetStorageManagementClient(context, handler3);

                var location = MediaManagementTestUtilities.TryGetLocation(resourcesClient, MediaManagementTestUtilities.DefaultLocation);

                // Create resource group
                var rgname = MediaManagementTestUtilities.CreateResourceGroup(resourcesClient, location);

                // List media services by resource group
                var mediaservices = mediaMgmtClient.MediaService.ListByResourceGroup(rgname);
                Assert.Equal(0, mediaservices.Count());

                // Create storage account
                var storageAccount = MediaManagementTestUtilities.CreateStorageAccount(storageClient, rgname, location);

                // Create a media service
                var accountName = TestUtilities.GenerateName("media");
                // check name availabilty
                var checkNameAvailabilityOutput = mediaMgmtClient.MediaService.CheckNameAvailabilty(new CheckNameAvailabilityInput(accountName, "mediaservices"));
                Assert.NotNull(checkNameAvailabilityOutput.NameAvailable);
                Assert.True(checkNameAvailabilityOutput.NameAvailable.Value);

                var mediaService = new MediaService
                {
                    Location = MediaManagementTestUtilities.DefaultLocation,
                    Tags     = new Dictionary <string, string>
                    {
                        { "key1", "value1" },
                        { "key2", "value2" }
                    },
                    StorageAccounts = new List <StorageAccount>
                    {
                        new StorageAccount
                        {
                            Id        = storageAccount.Id,
                            IsPrimary = true
                        }
                    }
                };
                mediaMgmtClient.MediaService.Create(rgname, accountName, mediaService);

                mediaservices = mediaMgmtClient.MediaService.ListByResourceGroup(rgname);
                Assert.Equal(1, mediaservices.Count());

                // check name availabilty
                checkNameAvailabilityOutput = mediaMgmtClient.MediaService.CheckNameAvailabilty(new CheckNameAvailabilityInput(accountName, "mediaservices"));
                Assert.NotNull(checkNameAvailabilityOutput.NameAvailable);
                Assert.False(checkNameAvailabilityOutput.NameAvailable.Value);

                mediaMgmtClient.MediaService.Delete(rgname, accountName);
                MediaManagementTestUtilities.DeleteStorageAccount(storageClient, rgname, storageAccount.Name);
                MediaManagementTestUtilities.DeleteResourceGroup(resourcesClient, rgname);
            }
        }
示例#8
0
        public void MediaServiceUpdateTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler3 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                // Create clients
                var mediaMgmtClient = MediaManagementTestUtilities.GetMediaManagementClient(context, handler1);
                var resourcesClient = MediaManagementTestUtilities.GetResourceManagementClient(context, handler2);
                var storageClient   = MediaManagementTestUtilities.GetStorageManagementClient(context, handler3);

                var location = MediaManagementTestUtilities.TryGetLocation(resourcesClient, MediaManagementTestUtilities.DefaultLocation);

                // Create resource group
                var rgname = MediaManagementTestUtilities.CreateResourceGroup(resourcesClient, location);

                // Create storage account
                var storageAccount = MediaManagementTestUtilities.CreateStorageAccount(storageClient, rgname, location);

                // Create a media service
                var accountName = TestUtilities.GenerateName("media");

                var mediaService = new MediaService
                {
                    Location = MediaManagementTestUtilities.DefaultLocation,
                    Tags     = new Dictionary <string, string>
                    {
                        { "key1", "value1" },
                        { "key2", "value2" }
                    },
                    StorageAccounts = new List <StorageAccount>
                    {
                        new StorageAccount
                        {
                            Id        = storageAccount.Id,
                            IsPrimary = true
                        }
                    }
                };
                mediaMgmtClient.MediaService.Create(rgname, accountName, mediaService);

                var mediaServiceGet = mediaMgmtClient.MediaService.Get(rgname, accountName);
                Assert.NotNull(mediaServiceGet);
                Assert.Equal(accountName, mediaServiceGet.Name);

                var tagsUpdated = new Dictionary <string, string>
                {
                    { "key3", "value3" },
                    { "key4", "value4" }
                };
                mediaMgmtClient.MediaService.Update(rgname, accountName, new MediaService
                {
                    Tags = tagsUpdated
                });

                mediaServiceGet = mediaMgmtClient.MediaService.Get(rgname, accountName);
                Assert.NotNull(mediaServiceGet);
                Assert.Equal(accountName, mediaServiceGet.Name);
                Assert.Equal(tagsUpdated, mediaServiceGet.Tags);

                mediaMgmtClient.MediaService.Delete(rgname, accountName);
                MediaManagementTestUtilities.DeleteStorageAccount(storageClient, rgname, storageAccount.Name);
                MediaManagementTestUtilities.DeleteResourceGroup(resourcesClient, rgname);
            }
        }