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);
        }
        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");
        }
        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 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 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);
        }
        private static MediaServicesManagementClient CreateMediaManagementClientWithFakeHttpMessageHandler(out FakeHttpMessageHandler fakeHttpHandler)
        {
            fakeHttpHandler = new FakeHttpMessageHandler();
            MediaServicesManagementClient managementClient  = InitManagementClient();
            MediaServicesManagementClient clientWithHandler = managementClient.WithHandler(fakeHttpHandler);

            return(clientWithHandler);
        }
        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 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.º 9
0
        private async void buttonConnect_Click(object sender, EventArgs e)
        {
            try
            {
                mediaClient = await GetMediaClient();

                mediaClient.SubscriptionId = AzureSubscriptionID;

                // get Media service information
                mediaService = mediaClient.MediaService.Get(AMSResourceGroup, _credentials.ReturnAccountName());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error when connecting", MessageBoxButtons.OK, MessageBoxIcon.Error);
                buttonAttach.Enabled = groupBoxStorage.Enabled = false;
                return;
            }

            var storages = mediaService.StorageAccounts.ToList();

            listViewStorage.Items.Clear();

            storages.ForEach(s =>
            {
                if (!(bool)s.IsPrimary)
                {
                    var names          = s.Id.Split('/');
                    var lvitem         = new ListViewItem(new string[] { names.Last(), s.Id });
                    lvitem.ToolTipText = s.Id;
                    listViewStorage.Items.Add(lvitem);
                }
            }
                             );

            buttonAttach.Enabled = groupBoxStorage.Enabled = true;
        }