public void RegenerateMediaServicesAccountTest() { // Setup Mock <IMediaServicesClient> clientMock = new Mock <IMediaServicesClient>(); const string newKey = "newkey"; const string expectedName = "testacc"; clientMock.Setup(f => f.RegenerateMediaServicesAccountAsync(expectedName, MediaServicesKeyType.Primary)).Returns( Task.Factory.StartNew(() => new OperationResponse { StatusCode = HttpStatusCode.OK })); MediaServicesAccountGetResponse detail = new MediaServicesAccountGetResponse { Account = new MediaServicesAccount { AccountName = expectedName, StorageAccountKeys = new MediaServicesAccount.AccountKeys { Primary = newKey } } }; clientMock.Setup(f => f.GetMediaServiceAsync(expectedName)).Returns(Task.Factory.StartNew(() => detail)); // Test NewAzureMediaServiceKeyCommand command = new NewAzureMediaServiceKeyCommand { CommandRuntime = new MockCommandRuntime(), Name = expectedName, KeyType = MediaServicesKeyType.Primary, MediaServicesClient = clientMock.Object, }; command.ExecuteCmdlet(); Assert.Equal(1, ((MockCommandRuntime)command.CommandRuntime).OutputPipeline.Count); string key = (string)((MockCommandRuntime)command.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.Equal(newKey, key); }
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); }