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.AreEqual(1, ((MockCommandRuntime)command.CommandRuntime).OutputPipeline.Count); AccountCreationResult accountCreationResult = (AccountCreationResult)((MockCommandRuntime)command.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.IsNotNull(accountCreationResult); Assert.AreEqual(accountName, accountCreationResult.Name); }
public void NewMediaServiceAccountShouldPassWithValidParameters() { // Setup var 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/"; AccountCreationRequest request = new AccountCreationRequest() { AccountName = accountName, BlobStorageEndpointUri = blobStorageEndpointUri, Region = region, StorageAccountKey = storageAccountKey, StorageAccountName = storageAccountName }; clientMock.Setup(f => f.CreateNewAzureMediaServiceAsync(It.Is <AccountCreationRequest>(creationRequest => request.AccountName == accountName))).Returns(Task.Factory.StartNew(() => { return(new AccountCreationResult() { AccountId = Guid.NewGuid().ToString(), Name = request.AccountName, Subscription = Guid.NewGuid().ToString() }); })); clientMock.Setup(f => f.GetStorageServiceKeys(storageAccountName)).Returns(Task.Factory.StartNew(() => { return(new StorageService() { StorageServiceKeys = new StorageServiceKeys() { Primary = storageAccountKey, Secondary = storageAccountKey } }); })); clientMock.Setup(f => f.GetStorageServiceProperties(storageAccountName)).Returns(Task.Factory.StartNew(() => { return(new StorageService() { StorageServiceProperties = new StorageServiceProperties() { Endpoints = new EndpointList() { blobStorageEndpointUri } } }); })); // Test var command = new NewAzureMediaServiceCommand() { CommandRuntime = new MockCommandRuntime(), Name = accountName, Location = region, StorageAccountName = storageAccountName, MediaServicesClient = clientMock.Object, }; command.ExecuteCmdlet(); Assert.AreEqual(1, ((MockCommandRuntime)command.CommandRuntime).OutputPipeline.Count); var accountCreationResult = (AccountCreationResult)((MockCommandRuntime)command.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.IsNotNull(accountCreationResult); Assert.AreEqual(accountName, accountCreationResult.Name); }