コード例 #1
0
        public void NewMediaServiceAccountShouldPassWithValidParameters()
        {
            // Setup
            Mock<IMediaServicesClient> clientMock = new Mock<IMediaServicesClient>();

            const string storageAccountName = "teststorage";
            const string storageAccountKey = "key";
            const string accountName = "testaccount";
            const string region = "West US";
            const string blobStorageEndpointUri = "http://awesome.blob.core.windows.net/";

            MediaServicesAccountCreateParameters request = new MediaServicesAccountCreateParameters
            {
                AccountName = accountName,
                BlobStorageEndpointUri = new Uri(blobStorageEndpointUri),
                Region = region,
                StorageAccountKey = storageAccountKey,
                StorageAccountName = storageAccountName

            };

            clientMock.Setup(f => f.CreateNewAzureMediaServiceAsync(It.Is<MediaServicesAccountCreateParameters>(creationRequest => request.AccountName == accountName))).Returns(
                Task.Factory.StartNew(() => new MediaServicesAccountCreateResponse
                {
                    Account = new MediaServicesCreatedAccount {
                        AccountId = Guid.NewGuid().ToString(),
                        AccountName = request.AccountName,
                        SubscriptionId = Guid.NewGuid().ToString()
                   }
                }));


            clientMock.Setup(f => f.GetStorageServiceKeysAsync(storageAccountName)).Returns(
                Task.Factory.StartNew(() => new StorageAccountGetKeysResponse
            {
                PrimaryKey = storageAccountKey,
                SecondaryKey = storageAccountKey


            }));


            clientMock.Setup(f => f.GetStorageServicePropertiesAsync(storageAccountName)).Returns(Task.Factory.StartNew(() =>
            {
                StorageAccountGetResponse response = new StorageAccountGetResponse
                {
                    StorageAccount = new StorageAccount
                        {
                            Properties = new StorageAccountProperties()   
                        }
                };
                response.StorageAccount.Properties.Endpoints.Add(new Uri(blobStorageEndpointUri));
                return response;
            }));

            // Test
            NewAzureMediaServiceCommand command = new NewAzureMediaServiceCommand
            {
                CommandRuntime = new MockCommandRuntime(),
                Name = accountName,
                Location = region,
                StorageAccountName = storageAccountName,
                MediaServicesClient = clientMock.Object,
            };

            command.ExecuteCmdlet();
            Assert.Equal(1, ((MockCommandRuntime)command.CommandRuntime).OutputPipeline.Count);
            AccountCreationResult accountCreationResult = (AccountCreationResult)((MockCommandRuntime)command.CommandRuntime).OutputPipeline.FirstOrDefault();
            Assert.NotNull(accountCreationResult);
            Assert.Equal(accountName, accountCreationResult.Name);
        }
コード例 #2
0
 private Task<StorageAccountGetResponse> CreateGetResponse(string serviceName)
 {
     Task<StorageAccountGetResponse> resultTask;
     var data = accounts.FirstOrDefault(a => a.Name == serviceName);
     if (data != null)
     {
         var storageServiceGetResponse = new StorageAccountGetResponse
         {
             StorageAccount = new StorageAccount
                 {
                     Name = data.Name,
                     Properties = new StorageAccountProperties
                     {
                         Endpoints =
                         {
                             new Uri(data.BlobEndpoint),
                             new Uri(data.QueueEndpoint),
                             new Uri(data.TableEndpoint)
                         }
                     }
                 }                    
         };
         resultTask = Tasks.FromResult(storageServiceGetResponse);
     }
     else
     {
         resultTask = Tasks.FromException<StorageAccountGetResponse>(ClientMocks.Make404Exception());
     }
     return resultTask;
 }
コード例 #3
0
        internal StorageAccountGetResponse GetStorageAccountProperties()
        {
            StorageAccountGetResponse gr = new StorageAccountGetResponse();

            gr = _storageManagementClient.StorageAccounts.Get(
                _parameters.StorageAccountName);

            return gr;
        }