public void TestGetMediaServiceAsync()
        {
            FakeHttpMessageHandler        fakeHttpHandler;
            MediaServicesManagementClient clientWithHandler = CreateMediaManagementClientWithFakeHttpMessageHandler(out fakeHttpHandler);

            const string responseText = @"<AccountDetails xmlns='http://schemas.datacontract.org/2004/07/Microsoft.Cloud.Media.Management.ResourceProvider.Models' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
                                    <AccountKey>primarykey</AccountKey><AccountKeys>
                                    <Primary>primarykey</Primary>
                                    <Secondary>secondarykey</Secondary>
                                    </AccountKeys><AccountName>testps</AccountName>
                                    <AccountRegion>West US</AccountRegion>
                                    <StorageAccountName>psstorage</StorageAccountName>
                                </AccountDetails>";

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

            fakeHttpHandler.Send = request => response;

            MediaServicesClient target = new MediaServicesClient(null,
                                                                 clientWithHandler,
                                                                 StorageClient.WithHandler(new FakeHttpMessageHandler()));

            MediaServicesAccountGetResponse result = target.GetMediaServiceAsync(AccountName).Result;

            Assert.AreEqual("primarykey", result.StorageAccountKeys.Primary);
            Assert.AreEqual("secondarykey", result.StorageAccountKeys.Secondary);
            Assert.AreEqual("testps", result.AccountName);
            Assert.AreEqual("psstorage", result.StorageAccountName);
        }
        public void TestDeleteAzureMediaServiceAccountAsync404()
        {
            FakeHttpMessageHandler        fakeHttpHandler;
            MediaServicesManagementClient clientWithHandler = CreateMediaManagementClientWithFakeHttpMessageHandler(out fakeHttpHandler);

            const string responseText = "<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">{\"Code\":\"NotFound\",\"Message\":\"The specified account was not found.\"}</string>";

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

            fakeHttpHandler.Send = request => response;

            MediaServicesClient target = new MediaServicesClient(null,
                                                                 clientWithHandler,
                                                                 StorageClient.WithHandler(new FakeHttpMessageHandler()));

            try
            {
                AzureOperationResponse result = target.DeleteAzureMediaServiceAccountAsync(AccountName).Result;
            }
            catch (AggregateException ax)
            {
                CloudException x = (CloudException)ax.InnerExceptions.Single();
                Assert.Equal(HttpStatusCode.NotFound, x.Response.StatusCode);
                return;
            }

            Assert.True(false, "ServiceManagementClientException expected");
        }
Ejemplo n.º 3
0
        public void TestGetStorageServiceKeys()
        {
            var fakeHttpHandler = new FakeHttpMessageHandler();

            string responseText = "<StorageService xmlns=\"http://schemas.microsoft.com/windowsazure\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Url>https://management.core.windows.net/f7190519-c29e-47f2-9019-c5a94c8e75f9/services/storageservices/nimbusivshapo</Url><StorageServiceKeys><Primary>PrimaryKey</Primary><Secondary>SecondaryKey</Secondary></StorageServiceKeys></StorageService>";

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

            response.Content.Headers.ContentType         = new MediaTypeHeaderValue("application/xml");
            response.Content.Headers.ContentType.CharSet = "utf-8";

            fakeHttpHandler.Send = request => response;

            var fakeHttpClient = fakeHttpHandler.CreateIMediaServicesHttpClient();

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

            var result = target.GetStorageServiceKeys(_accountName).Result;

            Assert.AreEqual("PrimaryKey", result.StorageServiceKeys.Primary);
            Assert.AreEqual("SecondaryKey", result.StorageServiceKeys.Secondary);
        }
        public void TestDeleteAzureMediaServiceAccountAsync404()
        {
            FakeHttpMessageHandler fakeHttpHandler;
            MediaServicesManagementClient clientWithHandler = CreateMediaManagementClientWithFakeHttpMessageHandler(out fakeHttpHandler);

            const string responseText = "<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">{\"Code\":\"NotFound\",\"Message\":\"The specified account was not found.\"}</string>";

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

            fakeHttpHandler.Send = request => response;

            MediaServicesClient target = new MediaServicesClient(null,
                clientWithHandler,
                StorageClient.WithHandler(new FakeHttpMessageHandler()));

            try
            {
                OperationResponse result = target.DeleteAzureMediaServiceAccountAsync(AccountName).Result;
            }
            catch (AggregateException ax)
            {
                CloudException x = (CloudException)ax.InnerExceptions.Single();
                Assert.AreEqual(HttpStatusCode.NotFound, x.Response.StatusCode);
                return;
            }

            Assert.Fail("ServiceManagementClientException expected");
        }
Ejemplo n.º 5
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);
        }
        public void TestGetMediaServiceAsync()
        {
            FakeHttpMessageHandler        fakeHttpHandler;
            MediaServicesManagementClient clientWithHandler = CreateMediaManagementClientWithFakeHttpMessageHandler(out fakeHttpHandler);

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

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

            fakeHttpHandler.Send = request => response;

            MediaServicesClient target = new MediaServicesClient(null,
                                                                 clientWithHandler,
                                                                 StorageClient.WithHandler(new FakeHttpMessageHandler()));

            MediaServicesAccountGetResponse result = target.GetMediaServiceAsync(AccountName).Result;

            Assert.Equal("primarykey", result.Account.StorageAccountKeys.Primary);
            Assert.Equal("secondarykey", result.Account.StorageAccountKeys.Secondary);
            Assert.Equal("testps", result.Account.AccountName);
            Assert.Equal("psstorage", result.Account.StorageAccountName);
        }
        public void TestGetMediaServiceAccountsAsync()
        {
            FakeHttpMessageHandler        fakeHttpHandler;
            MediaServicesManagementClient clientWithHandler = CreateMediaManagementClientWithFakeHttpMessageHandler(out fakeHttpHandler);

            const string responseText = @"<ServiceResources xmlns='http://schemas.microsoft.com/windowsazure' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
                                    <ServiceResource>
                                        <Name>mymediademo</Name>
                                        <Type>MediaService</Type>
                                        <State>Active</State>
                                        <AccountId>E0658294-5C96-4B0F-AD55-F7446CE4F788</AccountId>
                                    </ServiceResource>
                                    <ServiceResource>
                                        <Name>nimbusorigintrial</Name>
                                        <Type>MediaService</Type>
                                        <State>Active</State>
                                        <AccountId>C92B17C8-5422-4CD1-8D3C-61E576E861DD</AccountId>
                                    </ServiceResource>
                                </ServiceResources>";

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

            fakeHttpHandler.Send = request => response;

            MediaServicesClient target = new MediaServicesClient(null,
                                                                 clientWithHandler,
                                                                 StorageClient.WithHandler(new FakeHttpMessageHandler()));

            MediaServicesAccountListResponse.MediaServiceAccount[] result = target.GetMediaServiceAccountsAsync().Result.Accounts.ToArray();
            Assert.Equal("E0658294-5C96-4B0F-AD55-F7446CE4F788", result[0].AccountId);
            Assert.Equal("C92B17C8-5422-4CD1-8D3C-61E576E861DD", result[1].AccountId);
        }
        public void TestCreateNewAzureMediaServiceAsync()
        {
            FakeHttpMessageHandler fakeHttpHandler;
            MediaServicesManagementClient clientWithHandler = CreateMediaManagementClientWithFakeHttpMessageHandler(out fakeHttpHandler);

            const string responseText =
            @"{""AccountId"":""e26ca098-e363-450d-877c-384ce5a97c72"",
            ""AccountName"":""tmp"",
            ""Subscription"":""d4e66bc8-6ccb-4e49-9ee6-dc6925d5bbdb"",
            ""StatusCode"":201}";

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

            fakeHttpHandler.Send = request => response;

            MediaServicesClient target = new MediaServicesClient(null,
                clientWithHandler,
                StorageClient);

            MediaServicesAccountCreateParameters creationRequest = new MediaServicesAccountCreateParameters
            {
                AccountName = AccountName,
                BlobStorageEndpointUri = new Uri("http://tmp"),
                Region = "West US",
                StorageAccountKey = Guid.NewGuid().ToString(),
                StorageAccountName = "test"
            };

            MediaServicesAccountCreateResponse result = target.CreateNewAzureMediaServiceAsync(creationRequest).Result;
            Assert.Equal("tmp", result.Account.AccountName);
        }
Ejemplo n.º 9
0
        public void TestCreateNewAzureMediaServiceAsync()
        {
            var fakeHttpHandler = new FakeHttpMessageHandler();

            string responseText = "{\"AccountId\":\"abe5afa0-704b-4d07-b5d8-5b0b039474e7\",\"AccountName\":\"tmp\",\"StatusCode\":201,\"Subscription\":\"f7190519-c29e-47f2-9019-c5a94c8e75f9\"}";

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

            fakeHttpHandler.Send = request => response;

            var fakeHttpClient = fakeHttpHandler.CreateIMediaServicesHttpClient();

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

            var creationRequest = new AccountCreationRequest {
                AccountName = _accountName
            };

            var result = target.CreateNewAzureMediaServiceAsync(creationRequest).Result;

            Assert.AreEqual("tmp", result.Name);
        }
Ejemplo n.º 10
0
        public void TestGetMediaServiceAccountsAsync()
        {
            var fakeHttpHandler = new FakeHttpMessageHandler();

            string responseText =
                "[{\"Name\":\"testps\",\"Type\":\"MediaService\",\"State\":\"Active\",\"AccountId\":\"E0658294-5C96-4B0F-AD55-F7446CE4F788\"},{\"Name\":\"test2\",\"Type\":\"MediaService\",\"State\":\"Active\",\"AccountId\":\"C92B17C8-5422-4CD1-8D3C-61E576E861DD\"}]";

            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);

            MediaServiceAccount[] result = target.GetMediaServiceAccountsAsync().Result.ToArray();
            Assert.AreEqual(Guid.Parse("E0658294-5C96-4B0F-AD55-F7446CE4F788"), result[0].AccountId);
            Assert.AreEqual(Guid.Parse("C92B17C8-5422-4CD1-8D3C-61E576E861DD"), result[1].AccountId);
        }
        public void TestCreateNewAzureMediaServiceAsync()
        {
            FakeHttpMessageHandler        fakeHttpHandler;
            MediaServicesManagementClient clientWithHandler = CreateMediaManagementClientWithFakeHttpMessageHandler(out fakeHttpHandler);

            const string responseText =
                @"{""AccountId"":""e26ca098-e363-450d-877c-384ce5a97c72"",
            ""AccountName"":""tmp"",
            ""Subscription"":""d4e66bc8-6ccb-4e49-9ee6-dc6925d5bbdb"",
            ""StatusCode"":201}";

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

            fakeHttpHandler.Send = request => response;

            MediaServicesClient target = new MediaServicesClient(null,
                                                                 clientWithHandler,
                                                                 StorageClient);

            MediaServicesAccountCreateParameters creationRequest = new MediaServicesAccountCreateParameters
            {
                AccountName            = AccountName,
                BlobStorageEndpointUri = new Uri("http://tmp"),
                Region             = "West US",
                StorageAccountKey  = Guid.NewGuid().ToString(),
                StorageAccountName = "test"
            };

            MediaServicesAccountCreateResponse result = target.CreateNewAzureMediaServiceAsync(creationRequest).Result;

            Assert.Equal("tmp", result.Account.AccountName);
        }
Ejemplo n.º 12
0
        public void TestRegenerateMediaServicesAccountAsync()
        {
            HttpClient fakeHttpClient = new FakeHttpMessageHandler().CreateIMediaServicesHttpClient();

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

            bool result = target.RegenerateMediaServicesAccountAsync(_accountName, "Primary").Result;

            Assert.IsTrue(result);
        }
        public void TestDeleteAzureMediaServiceAccountAsync()
        {
            Mock<MediaServicesManagementClient> clientMock = InitMediaManagementClientMock();
            Mock<IAccountOperations> iAccountOperations = new Mock<IAccountOperations>();
            iAccountOperations.Setup(m => m.DeleteAsync(It.IsAny<string>(), It.IsAny<CancellationToken>())).Returns(() => Task.Factory.StartNew(() => new OperationResponse
            {
                RequestId = "request",
                StatusCode = HttpStatusCode.OK
            }));
            clientMock.Setup(m => m.Accounts).Returns(() => iAccountOperations.Object);

            StorageManagementClient storageClient = StorageClient.WithHandler(new FakeHttpMessageHandler());
            MediaServicesClient target = new MediaServicesClient(null,
                clientMock.Object,
                storageClient);

            OperationResponse result = target.DeleteAzureMediaServiceAccountAsync(AccountName).Result;

            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
Ejemplo n.º 14
0
        public void TestCreateNewAzureMediaServiceAsyncInvalidAccount()
        {
            var fakeHttpHandler = new FakeHttpMessageHandler();

            string responseText = "<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">{\"Code\":\"BadRequest\",\"Message\":\"Account Creation Request contains an invalid account name.\"}</string>";

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

            fakeHttpHandler.Send = request => response;

            var fakeHttpClient = fakeHttpHandler.CreateIMediaServicesHttpClient();

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

            var creationRequest = new AccountCreationRequest {
                AccountName = _accountName
            };

            try
            {
                var result = target.CreateNewAzureMediaServiceAsync(creationRequest).Result;
            }
            catch (AggregateException ax)
            {
                ServiceManagementClientException x = (ServiceManagementClientException)ax.InnerExceptions.Single();

                Assert.AreEqual(HttpStatusCode.BadRequest, x.HttpStatus);
                return;
            }

            Assert.Fail("ServiceManagementClientException expected");
        }
        public void TestCreateNewAzureMediaServiceAsyncInvalidAccount()
        {
            FakeHttpMessageHandler        fakeHttpHandler;
            MediaServicesManagementClient clientWithHandler = CreateMediaManagementClientWithFakeHttpMessageHandler(out fakeHttpHandler);

            const string responseText = @"<Error xmlns='http://schemas.microsoft.com/windowsazure' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
                                        <Code>BadRequest</Code>
                                        <Message>Account Creation Request contains an invalid account name.</Message>
                                    </Error>";

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

            fakeHttpHandler.Send = request => response;

            MediaServicesClient target = new MediaServicesClient(null,
                                                                 clientWithHandler,
                                                                 StorageClient);

            MediaServicesAccountCreateParameters creationRequest = new MediaServicesAccountCreateParameters
            {
                AccountName            = AccountName,
                BlobStorageEndpointUri = new Uri("http://tmp"),
                Region             = "West US",
                StorageAccountKey  = Guid.NewGuid().ToString(),
                StorageAccountName = "test"
            };

            try
            {
                MediaServicesAccountCreateResponse result = target.CreateNewAzureMediaServiceAsync(creationRequest).Result;
            }
            catch (AggregateException ex)
            {
                CloudException cloudException = ex.Flatten().InnerException as CloudException;
                Assert.NotNull(cloudException);
                Assert.Equal(HttpStatusCode.BadRequest, cloudException.Response.StatusCode);
            }
        }
        public void TestDeleteAzureMediaServiceAccountAsync()
        {
            Mock <MediaServicesManagementClient> clientMock         = InitMediaManagementClientMock();
            Mock <IAccountOperations>            iAccountOperations = new Mock <IAccountOperations>();

            iAccountOperations.Setup(m => m.DeleteAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).Returns(() => Task.Factory.StartNew(() => new AzureOperationResponse
            {
                RequestId  = "request",
                StatusCode = HttpStatusCode.OK
            }));
            clientMock.Setup(m => m.Accounts).Returns(() => iAccountOperations.Object);

            StorageManagementClient storageClient = StorageClient.WithHandler(new FakeHttpMessageHandler());
            MediaServicesClient     target        = new MediaServicesClient(null,
                                                                            clientMock.Object,
                                                                            storageClient);

            AzureOperationResponse result = target.DeleteAzureMediaServiceAccountAsync(AccountName).Result;

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
        }
Ejemplo n.º 17
0
        public void TestGetStorageServiceKeysInvalidAccountName()
        {
            var fakeHttpHandler = new FakeHttpMessageHandler();

            string responseText = "<Error xmlns=\"http://schemas.microsoft.com/windowsazure\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Code>BadRequest</Code><Message>The name is not a valid.</Message></Error>";

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

            response.Content.Headers.ContentType         = new MediaTypeHeaderValue("application/xml");
            response.Content.Headers.ContentType.CharSet = "utf-8";

            fakeHttpHandler.Send = request => response;

            var fakeHttpClient = fakeHttpHandler.CreateIMediaServicesHttpClient();

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

            try
            {
                var result = target.GetStorageServiceKeys(_accountName).Result;
            }
            catch (AggregateException ax)
            {
                ServiceManagementClientException x = (ServiceManagementClientException)ax.InnerExceptions.Single();

                Assert.AreEqual(HttpStatusCode.BadRequest, x.HttpStatus);
                return;
            }

            Assert.Fail("ServiceManagementClientException expected");
        }
        public override void ExecuteCmdlet()
        {
            MediaServicesClient = MediaServicesClient ?? new MediaServicesClient(Profile, Profile.Context.Subscription, WriteDebug);

            StorageAccountGetKeysResponse storageKeysResponse = null;
            Uri    storageEndPoint   = null;
            string storageAccountKey = null;

            CatchAggregatedExceptionFlattenAndRethrow(() => { storageKeysResponse = MediaServicesClient.GetStorageServiceKeysAsync(StorageAccountName).Result; });
            storageAccountKey = storageKeysResponse.PrimaryKey;

            StorageAccountGetResponse storageGetResponse = null;

            CatchAggregatedExceptionFlattenAndRethrow(() => { storageGetResponse = MediaServicesClient.GetStorageServicePropertiesAsync(StorageAccountName).Result; });

            if (storageGetResponse.StorageAccount.Properties != null && storageGetResponse.StorageAccount.Properties.Endpoints.Count > 0)
            {
                storageEndPoint = storageGetResponse.StorageAccount.Properties.Endpoints[0];
            }
            else
            {
                throw new Exception(string.Format(Resources.EndPointNotFoundForBlobStorage, Name));
            }

            AccountCreationResult result = null;
            var request = new MediaServicesAccountCreateParameters()
            {
                AccountName            = Name,
                BlobStorageEndpointUri = storageEndPoint,
                Region             = Location,
                StorageAccountKey  = storageAccountKey,
                StorageAccountName = StorageAccountName
            };

            CatchAggregatedExceptionFlattenAndRethrow(() => { result = new AccountCreationResult(MediaServicesClient.CreateNewAzureMediaServiceAsync(request).Result); });
            WriteObject(result, false);
        }
Ejemplo n.º 19
0
        public override void ExecuteCmdlet()
        {
            MediaServicesClient = MediaServicesClient ?? new MediaServicesClient(CurrentSubscription, WriteDebug);


            StorageService storage           = null;
            Uri            storageEndPoint   = null;
            string         storageAccountKey = null;

            CatchAggregatedExceptionFlattenAndRethrow(() => { storage = MediaServicesClient.GetStorageServiceKeys(StorageAccountName).Result; });
            storageAccountKey = storage.StorageServiceKeys.Primary;


            CatchAggregatedExceptionFlattenAndRethrow(() => { storage = MediaServicesClient.GetStorageServiceProperties(StorageAccountName).Result; });

            if (storage.StorageServiceProperties != null && storage.StorageServiceProperties.Endpoints.Count > 0)
            {
                storageEndPoint = new Uri(storage.StorageServiceProperties.Endpoints[0]);
            }
            else
            {
                throw new Exception(string.Format(Utilities.Properties.Resources.EndPointNotFoundForBlobStorage, Name));
            }

            AccountCreationResult result = null;
            var request = new AccountCreationRequest
            {
                AccountName            = Name,
                BlobStorageEndpointUri = storageEndPoint.ToString(),
                Region             = Location,
                StorageAccountKey  = storageAccountKey,
                StorageAccountName = StorageAccountName
            };

            CatchAggregatedExceptionFlattenAndRethrow(() => { result = MediaServicesClient.CreateNewAzureMediaServiceAsync(request).Result; });
            WriteObject(result, false);
        }
        public void TestRegenerateMediaServicesAccountAsync()
        {
            Mock <MediaServicesManagementClient> clientMock         = InitMediaManagementClientMock();
            Mock <IAccountOperations>            iAccountOperations = new Mock <IAccountOperations>();

            iAccountOperations
            .Setup(m => m.RegenerateKeyAsync(It.IsAny <string>(), It.IsAny <MediaServicesKeyType>(), It.IsAny <CancellationToken>()))
            .Returns(() => Task.Factory.StartNew(
                         () => new AzureOperationResponse
            {
                RequestId  = "request",
                StatusCode = HttpStatusCode.OK
            }));

            clientMock.Setup(m => m.Accounts).Returns(() => iAccountOperations.Object);

            MediaServicesClient target = new MediaServicesClient(null,
                                                                 clientMock.Object,
                                                                 StorageClient);

            AzureOperationResponse result = target.RegenerateMediaServicesAccountAsync(AccountName, MediaServicesKeyType.Primary).Result;

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
        }
        public void TestCreateNewAzureMediaServiceAsync()
        {
            FakeHttpMessageHandler        fakeHttpHandler;
            MediaServicesManagementClient clientWithHandler = CreateMediaManagementClientWithFakeHttpMessageHandler(out fakeHttpHandler);

            const string responseText = @"<AccountCreationResult xmlns='http://schemas.datacontract.org/2004/07/Microsoft.Cloud.Media.Management.ResourceProvider.Models' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
                                    <AccountId>e26ca098-e363-450d-877c-384ce5a97c72</AccountId>
                                    <AccountName>tmp</AccountName>
                                    <StatusCode>Created</StatusCode>
                                    <Subscription>d4e66bc8-6ccb-4e49-9ee6-dc6925d5bbdb</Subscription>
                                </AccountCreationResult>";

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

            fakeHttpHandler.Send = request => response;

            MediaServicesClient target = new MediaServicesClient(null,
                                                                 clientWithHandler,
                                                                 StorageClient);

            MediaServicesAccountCreateParameters creationRequest = new MediaServicesAccountCreateParameters
            {
                AccountName            = AccountName,
                BlobStorageEndpointUri = new Uri("http://tmp"),
                Region             = "West US",
                StorageAccountKey  = Guid.NewGuid().ToString(),
                StorageAccountName = "test"
            };

            MediaServicesAccountCreateResponse result = target.CreateNewAzureMediaServiceAsync(creationRequest).Result;

            Assert.AreEqual("tmp", result.AccountName);
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> Post()
        {
            //try
            //{
            var files = Request.Form.Files;

            if (files != null)
            {
                foreach (var file in files)
                {
                    if (file.Length > 0)
                    {
                        using (var ms = new MemoryStream())
                        {
                            file.CopyTo(ms);
                            ms.ToArray();
                            //string s = Convert.ToBase64String(fileBytes);

                            if (MediaServicesClient.Client == null)
                            {
                                await Task.Run(() => MediaServicesClient.Connect());
                            }
                            await Task.Run(() => MediaServicesClient.Upload(ms, file.FileName));

                            return(Ok(file.FileName));
                        }
                    }
                }
            }
            return(Ok());

            //}catch(Exception ex)
            //{
            //return BadRequest(ex);
            //}
        }
Ejemplo n.º 23
0
        public void TestDeleteAzureMediaServiceAccountAsync404()
        {
            var fakeHttpHandler = new FakeHttpMessageHandler();

            string responseText = "<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">{\"Code\":\"NotFound\",\"Message\":\"The specified account was not found.\"}</string>";

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

            fakeHttpHandler.Send = request => response;

            HttpClient fakeHttpClient = fakeHttpHandler.CreateIMediaServicesHttpClient();

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

            try
            {
                bool result = target.DeleteAzureMediaServiceAccountAsync(_accountName).Result;
            }
            catch (AggregateException ax)
            {
                var x = (ServiceManagementClientException)ax.InnerExceptions.Single();
                Assert.AreEqual("NotFound", x.ErrorDetails.Code);
                return;
            }

            Assert.Fail("ServiceManagementClientException expected");
        }
        public void TestGetMediaServiceAsync()
        {


            FakeHttpMessageHandler fakeHttpHandler;
            MediaServicesManagementClient clientWithHandler = CreateMediaManagementClientWithFakeHttpMessageHandler(out fakeHttpHandler);

            const string responseText = @"<AccountDetails xmlns='http://schemas.datacontract.org/2004/07/Microsoft.Cloud.Media.Management.ResourceProvider.Models' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
                                    <AccountKey>primarykey</AccountKey><AccountKeys>
                                    <Primary>primarykey</Primary>
                                    <Secondary>secondarykey</Secondary>
                                    </AccountKeys><AccountName>testps</AccountName>
                                    <AccountRegion>West US</AccountRegion>
                                    <StorageAccountName>psstorage</StorageAccountName>
                                </AccountDetails>";

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

            fakeHttpHandler.Send = request => response;

            MediaServicesClient target = new MediaServicesClient(null,
                clientWithHandler,
                StorageClient.WithHandler(new FakeHttpMessageHandler()));

            MediaServicesAccountGetResponse result = target.GetMediaServiceAsync(AccountName).Result;
            Assert.AreEqual("primarykey", result.StorageAccountKeys.Primary);
            Assert.AreEqual("secondarykey", result.StorageAccountKeys.Secondary);
            Assert.AreEqual("testps", result.AccountName);
            Assert.AreEqual("psstorage", result.StorageAccountName);
        }
        public void TestCreateNewAzureMediaServiceAsync()
        {
            FakeHttpMessageHandler fakeHttpHandler;
            MediaServicesManagementClient clientWithHandler = CreateMediaManagementClientWithFakeHttpMessageHandler(out fakeHttpHandler);

            const string responseText = @"<AccountCreationResult xmlns='http://schemas.datacontract.org/2004/07/Microsoft.Cloud.Media.Management.ResourceProvider.Models' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
                                    <AccountId>e26ca098-e363-450d-877c-384ce5a97c72</AccountId>
                                    <AccountName>tmp</AccountName>
                                    <StatusCode>Created</StatusCode>
                                    <Subscription>d4e66bc8-6ccb-4e49-9ee6-dc6925d5bbdb</Subscription>
                                </AccountCreationResult>";

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

            fakeHttpHandler.Send = request => response;

            MediaServicesClient target = new MediaServicesClient(null,
                clientWithHandler,
                StorageClient);

            MediaServicesAccountCreateParameters creationRequest = new MediaServicesAccountCreateParameters
            {
                AccountName = AccountName,
                BlobStorageEndpointUri = new Uri("http://tmp"),
                Region = "West US",
                StorageAccountKey = Guid.NewGuid().ToString(),
                StorageAccountName = "test"
            };

            MediaServicesAccountCreateResponse result = target.CreateNewAzureMediaServiceAsync(creationRequest).Result;
            Assert.AreEqual("tmp", result.AccountName);
        }
        public void TestGetMediaServiceAsync()
        {


            FakeHttpMessageHandler fakeHttpHandler;
            MediaServicesManagementClient clientWithHandler = CreateMediaManagementClientWithFakeHttpMessageHandler(out fakeHttpHandler);

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

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

            fakeHttpHandler.Send = request => response;

            MediaServicesClient target = new MediaServicesClient(null,
                clientWithHandler,
                StorageClient.WithHandler(new FakeHttpMessageHandler()));

            MediaServicesAccountGetResponse result = target.GetMediaServiceAsync(AccountName).Result;
            Assert.AreEqual("primarykey", result.Account.StorageAccountKeys.Primary);
            Assert.AreEqual("secondarykey", result.Account.StorageAccountKeys.Secondary);
            Assert.AreEqual("testps", result.Account.AccountName);
            Assert.AreEqual("psstorage", result.Account.StorageAccountName);
        }
        public void TestRegenerateMediaServicesAccountAsync()
        {
            Mock<MediaServicesManagementClient> clientMock = InitMediaManagementClientMock();
            Mock<IAccountOperations> iAccountOperations = new Mock<IAccountOperations>();
            iAccountOperations
                .Setup(m => m.RegenerateKeyAsync(It.IsAny<string>(), It.IsAny<MediaServicesKeyType>(), It.IsAny<CancellationToken>()))
                .Returns(() => Task.Factory.StartNew(
                    () => new OperationResponse
                    {
                        RequestId = "request",
                        StatusCode = HttpStatusCode.OK
                    }));

            clientMock.Setup(m => m.Accounts).Returns(() => iAccountOperations.Object);

            MediaServicesClient target = new MediaServicesClient(null,
                clientMock.Object,
                StorageClient);

            OperationResponse result = target.RegenerateMediaServicesAccountAsync(AccountName, MediaServicesKeyType.Primary).Result;

            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
        public void TestGetMediaServiceAccountsAsync()
        {

            FakeHttpMessageHandler fakeHttpHandler;
            MediaServicesManagementClient clientWithHandler = CreateMediaManagementClientWithFakeHttpMessageHandler(out fakeHttpHandler);

            const string responseText = @"<ServiceResources xmlns='http://schemas.microsoft.com/windowsazure' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
                                    <ServiceResource>
                                        <Name>mymediademo</Name>
                                        <Type>MediaService</Type>
                                        <State>Active</State>
                                        <AccountId>E0658294-5C96-4B0F-AD55-F7446CE4F788</AccountId>
                                    </ServiceResource>
                                    <ServiceResource>
                                        <Name>nimbusorigintrial</Name>
                                        <Type>MediaService</Type>
                                        <State>Active</State>
                                        <AccountId>C92B17C8-5422-4CD1-8D3C-61E576E861DD</AccountId>
                                    </ServiceResource>
                                </ServiceResources>";

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

            fakeHttpHandler.Send = request => response;

            MediaServicesClient target = new MediaServicesClient(null,
                clientWithHandler,
                StorageClient.WithHandler(new FakeHttpMessageHandler()));

            MediaServicesAccountListResponse.MediaServiceAccount[] result = target.GetMediaServiceAccountsAsync().Result.Accounts.ToArray();
            Assert.AreEqual("E0658294-5C96-4B0F-AD55-F7446CE4F788", result[0].AccountId);
            Assert.AreEqual("C92B17C8-5422-4CD1-8D3C-61E576E861DD", result[1].AccountId);
        }
        public void TestCreateNewAzureMediaServiceAsyncInvalidAccount()
        {
            FakeHttpMessageHandler fakeHttpHandler;
            MediaServicesManagementClient clientWithHandler = CreateMediaManagementClientWithFakeHttpMessageHandler(out fakeHttpHandler);

            const string responseText = @"<Error xmlns='http://schemas.microsoft.com/windowsazure' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
                                        <Code>BadRequest</Code>
                                        <Message>Account Creation Request contains an invalid account name.</Message>
                                    </Error>";

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

            fakeHttpHandler.Send = request => response;

            MediaServicesClient target = new MediaServicesClient(null,
                clientWithHandler,
                StorageClient);

            MediaServicesAccountCreateParameters creationRequest = new MediaServicesAccountCreateParameters
            {
                AccountName = AccountName,
                BlobStorageEndpointUri = new Uri("http://tmp"),
                Region = "West US",
                StorageAccountKey = Guid.NewGuid().ToString(),
                StorageAccountName = "test"
            };

            try
            {
                MediaServicesAccountCreateResponse result = target.CreateNewAzureMediaServiceAsync(creationRequest).Result;
            }
            catch (AggregateException ex)
            {
                CloudException cloudException = ex.Flatten().InnerException as CloudException;
                Assert.IsNotNull(cloudException);
                Assert.AreEqual(HttpStatusCode.BadRequest, cloudException.Response.StatusCode);
            }

        }