public void ProcessGetMediaServiceByNameShouldReturnOneMatchingEntry()
        {
            Mock <IMediaServicesClient> clientMock = new Mock <IMediaServicesClient>();


            const string expectedName = "WAMS Account 1";
            MediaServicesAccountGetResponse detail = new MediaServicesAccountGetResponse
            {
                Account = new MediaServicesAccount()
                {
                    AccountName = expectedName
                }
            };

            clientMock.Setup(f => f.GetMediaServiceAsync(detail.Account.AccountName)).Returns(Task.Factory.StartNew(() => detail));

            // Test
            GetAzureMediaServiceCommand getAzureMediaServiceCommand = new GetAzureMediaServiceCommand
            {
                CommandRuntime      = new MockCommandRuntime(),
                MediaServicesClient = clientMock.Object,
                Name = expectedName
            };

            AzureSession.SetCurrentContext(new AzureSubscription {
                Id = new Guid(SubscriptionId)
            }, null, null);
            getAzureMediaServiceCommand.ExecuteCmdlet();
            Assert.Equal(1, ((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline.Count);
            MediaServiceAccountDetails accounts = (MediaServiceAccountDetails)((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline.FirstOrDefault();

            Assert.NotNull(accounts);
            Assert.Equal(expectedName, accounts.Name);
        }
Beispiel #2
0
        public void ProcessGetMediaServiceByNameShouldReturnOneMatchingEntry()
        {
            var clientMock = new Mock <IMediaServicesClient>();


            string expectedName = "WAMS Account 1";
            var    detail       = new MediaServiceAccountDetails
            {
                Name = expectedName
            };

            clientMock.Setup(f => f.GetMediaServiceAsync(detail.Name)).Returns(Task.Factory.StartNew(() => { return(detail); }));

            // Test
            var getAzureMediaServiceCommand = new GetAzureMediaServiceCommand
            {
                CommandRuntime      = new MockCommandRuntime(),
                MediaServicesClient = clientMock.Object,
                CurrentSubscription = new SubscriptionData
                {
                    SubscriptionId = SubscriptionId
                }
            };

            getAzureMediaServiceCommand.Name = expectedName;
            getAzureMediaServiceCommand.ExecuteCmdlet();
            Assert.AreEqual(1, ((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline.Count);
            var accounts = (MediaServiceAccountDetails)((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline.FirstOrDefault();

            Assert.IsNotNull(accounts);
            Assert.AreEqual(expectedName, accounts.Name);
        }
Beispiel #3
0
        public void TestGetMediaServiceAsync()
        {
            var fakeHttpHandler = new FakeHttpMessageHandler();

            string responseText = "{\"AccountKey\":\"primarykey\",\"AccountKeys\":{\"Primary\":\"primarykey\",\"Secondary\":\"secondarykey\"},\"AccountName\":\"testps\",\"AccountRegion\":\"West US\",\"StorageAccountName\":\"nimbusorigintrial\"}";


            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new FakeHttpContent(responseText)
            };

            fakeHttpHandler.Send = request => response;

            HttpClient fakeHttpClient = fakeHttpHandler.CreateIMediaServicesHttpClient();

            var target = new MediaServicesClient(new SubscriptionData
            {
                SubscriptionId = _subscriptionId
            },
                                                 null,
                                                 fakeHttpClient,
                                                 fakeHttpClient);

            MediaServiceAccountDetails result = target.GetMediaServiceAsync(_accountName).Result;

            Assert.AreEqual("primarykey", result.MediaServicesPrimaryAccountKey);
            Assert.AreEqual("secondarykey", result.MediaServicesSecondaryAccountKey);
            Assert.AreEqual("testps", result.Name);
        }
Beispiel #4
0
        /// <summary>
        ///     Executes the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            MediaServicesClient = MediaServicesClient ?? new MediaServicesClient(CurrentSubscription, WriteDebug);

            if (!string.IsNullOrEmpty(Name))
            {
                MediaServiceAccountDetails account = null;
                CatchAggregatedExceptionFlattenAndRethrow(() => { account = MediaServicesClient.GetMediaServiceAsync(Name).Result; });
                WriteObject(account, false);
            }
            else
            {
                var accounts = new List <MediaServiceAccount>();
                accounts.AddRange(MediaServicesClient.GetMediaServiceAccountsAsync().Result);
                // Output results
                WriteMediaAccounts(accounts);
            }
        }
        /// <summary>
        ///     Executes the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            MediaServicesClient = MediaServicesClient ?? new MediaServicesClient(CurrentSubscription, WriteDebug);

            if (!string.IsNullOrEmpty(Name))
            {
                MediaServiceAccountDetails account = null;
                CatchAggregatedExceptionFlattenAndRethrow(() => { account = new MediaServiceAccountDetails(MediaServicesClient.GetMediaServiceAsync(Name).Result); });
                WriteObject(account, false);
            }
            else
            {
                var accounts = new List<MediaServiceAccount>();
                accounts.AddRange(MediaServicesClient.GetMediaServiceAccountsAsync().Result.Accounts.Select(c=>new MediaServiceAccount(c)));
                // Output results
                WriteMediaAccounts(accounts);
            }
        }
Beispiel #6
0
        public override void ExecuteCmdlet()
        {
            ConfirmAction(Force.IsPresent,
                          string.Format(Resources.RegenerateKeyWarning),
                          Resources.RegenerateKeyWhatIfMessage,
                          string.Empty,
                          () =>
            {
                MediaServicesClient = MediaServicesClient ?? new MediaServicesClient(CurrentSubscription, WriteDebug);

                bool result;
                CatchAggregatedExceptionFlattenAndRethrow(() => { result = MediaServicesClient.RegenerateMediaServicesAccountAsync(Name, KeyType.ToString()).Result; });

                MediaServiceAccountDetails account = null;
                CatchAggregatedExceptionFlattenAndRethrow(() => { account = MediaServicesClient.GetMediaServiceAsync(Name).Result; });
                string newKey = KeyType == KeyType.Primary ? account.AccountKeys.Primary : account.AccountKeys.Secondary;

                WriteObject(newKey);
            });
        }
        public override void ExecuteCmdlet()
        {
            ConfirmAction(Force.IsPresent,
                          string.Format(Resources.RegenerateKeyWarning),
                          Resources.RegenerateKeyWhatIfMessage,
                          string.Empty,
                          () =>
                          {
                              MediaServicesClient = MediaServicesClient ?? new MediaServicesClient(CurrentSubscription, WriteDebug);

                              
                              OperationResponse result =null;
                              CatchAggregatedExceptionFlattenAndRethrow(() => { result = MediaServicesClient.RegenerateMediaServicesAccountAsync(Name, KeyType).Result; });
                            
                              MediaServiceAccountDetails account = null;
                              CatchAggregatedExceptionFlattenAndRethrow(() => { account = new MediaServiceAccountDetails(MediaServicesClient.GetMediaServiceAsync(Name).Result); });
                              string newKey = KeyType == MediaServicesKeyType.Primary ? account.AccountKeys.Primary : account.AccountKeys.Secondary;

                              WriteObject(newKey);
                          });
        }
Beispiel #8
0
        public void RegenerateMediaServicesAccountTest()
        {
            // Setup
            var clientMock = new Mock <IMediaServicesClient>();

            string newKey       = "newkey";
            string expectedName = "testacc";

            clientMock.Setup(f => f.RegenerateMediaServicesAccountAsync(expectedName, "Primary")).Returns(Task.Factory.StartNew(() => true));

            var detail = new MediaServiceAccountDetails
            {
                Name        = expectedName,
                AccountKeys = new AccountKeys
                {
                    Primary = newKey
                }
            };

            clientMock.Setup(f => f.GetMediaServiceAsync(expectedName)).Returns(Task.Factory.StartNew(() => { return(detail); }));

            // Test
            var command = new NewAzureMediaServiceKeyCommand
            {
                CommandRuntime      = new MockCommandRuntime(),
                Name                = expectedName,
                KeyType             = KeyType.Primary,
                MediaServicesClient = clientMock.Object,
            };

            command.ExecuteCmdlet();
            Assert.AreEqual(1, ((MockCommandRuntime)command.CommandRuntime).OutputPipeline.Count);
            var key = (string)((MockCommandRuntime)command.CommandRuntime).OutputPipeline.FirstOrDefault();

            Assert.AreEqual(newKey, key);
        }