public void ProcessGetMediaServiceByNameShouldNotReturnEntriesForNoneMatchingName() { Mock <IMediaServicesClient> clientMock = new Mock <IMediaServicesClient>(); string mediaServicesAccountName = Guid.NewGuid().ToString(); clientMock.Setup(f => f.GetMediaServiceAsync(mediaServicesAccountName)).Returns(Task.Factory.StartNew(() => { if (String.IsNullOrEmpty(mediaServicesAccountName)) { return(new MediaServicesAccountGetResponse()); } throw new ServiceManagementClientException(HttpStatusCode.NotFound, new ServiceManagementError { Code = HttpStatusCode.NotFound.ToString(), Message = "Account not found" }, string.Empty); })); // Test GetAzureMediaServiceCommand getAzureMediaServiceCommand = new GetAzureMediaServiceCommand { CommandRuntime = new MockCommandRuntime(), MediaServicesClient = clientMock.Object, Name = mediaServicesAccountName }; AzureSession.SetCurrentContext(new AzureSubscription { Id = new Guid(SubscriptionId) }, null, null); Assert.Throws <ServiceManagementClientException>(() => getAzureMediaServiceCommand.ExecuteCmdlet()); Assert.Equal(0, ((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline.Count); }
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); }
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); }
public void ProcessGetMediaServicesTest() { // Setup Mock <IMediaServicesClient> clientMock = new Mock <IMediaServicesClient>(); Guid id1 = Guid.NewGuid(); Guid id2 = Guid.NewGuid(); MediaServicesAccountListResponse response = new MediaServicesAccountListResponse(); response.Accounts.Add(new MediaServicesAccountListResponse.MediaServiceAccount { AccountId = id1.ToString(), Name = "WAMS Account 1" }); response.Accounts.Add(new MediaServicesAccountListResponse.MediaServiceAccount { AccountId = id2.ToString(), Name = "WAMS Account 2" }); clientMock.Setup(f => f.GetMediaServiceAccountsAsync()).Returns(Task.Factory.StartNew(() => response)); // Test GetAzureMediaServiceCommand getAzureMediaServiceCommand = new GetAzureMediaServiceCommand { CommandRuntime = new MockCommandRuntime(), MediaServicesClient = clientMock.Object, }; currentProfile = new AzureSMProfile(); var subscription = new AzureSubscription { Id = SubscriptionId }; subscription.SetDefault(); currentProfile.SubscriptionTable[new Guid(SubscriptionId)] = subscription; getAzureMediaServiceCommand.ExecuteCmdlet(); IEnumerable <MediaServiceAccount> accounts = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline).Cast <MediaServiceAccount>(); Assert.NotNull(accounts); Assert.Equal(2, accounts.Count()); Assert.True(accounts.Any(mediaservice => (mediaservice).AccountId == id1)); Assert.True(accounts.Any(mediaservice => (mediaservice).AccountId == id2)); Assert.True(accounts.Any(mediaservice => (mediaservice).Name.Equals("WAMS Account 1"))); Assert.True(accounts.Any(mediaservice => (mediaservice).Name.Equals("WAMS Account 2"))); }
public void ProcessGetMediaServicesTest() { // Setup Mock <IMediaServicesClient> clientMock = new Mock <IMediaServicesClient>(); Guid id1 = Guid.NewGuid(); Guid id2 = Guid.NewGuid(); MediaServicesAccountListResponse response = new MediaServicesAccountListResponse(); response.Accounts.Add(new MediaServicesAccountListResponse.MediaServiceAccount { AccountId = id1.ToString(), Name = "WAMS Account 1" }); response.Accounts.Add(new MediaServicesAccountListResponse.MediaServiceAccount { AccountId = id2.ToString(), Name = "WAMS Account 2" }); clientMock.Setup(f => f.GetMediaServiceAccountsAsync()).Returns(Task.Factory.StartNew(() => response)); // Test GetAzureMediaServiceCommand getAzureMediaServiceCommand = new GetAzureMediaServiceCommand { CommandRuntime = new MockCommandRuntime(), MediaServicesClient = clientMock.Object, }; currentProfile = new AzureProfile(); var subscription = new AzureSubscription { Id = new Guid(SubscriptionId) }; subscription.Properties[AzureSubscription.Property.Default] = "True"; currentProfile.Subscriptions[new Guid(SubscriptionId)] = subscription; getAzureMediaServiceCommand.ExecuteCmdlet(); Assert.Equal(1, ((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline.Count); IEnumerable <MediaServiceAccount> accounts = (IEnumerable <MediaServiceAccount>)((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.NotNull(accounts); Assert.True(accounts.Any(mediaservice => (mediaservice).AccountId == id1)); Assert.True(accounts.Any(mediaservice => (mediaservice).AccountId == id2)); Assert.True(accounts.Any(mediaservice => (mediaservice).Name.Equals("WAMS Account 1"))); Assert.True(accounts.Any(mediaservice => (mediaservice).Name.Equals("WAMS Account 2"))); }
public void ProcessGetMediaServicesTest() { // Setup var clientMock = new Mock <IMediaServicesClient>(); Guid id1 = Guid.NewGuid(); Guid id2 = Guid.NewGuid(); IEnumerable <MediaServiceAccount> accountsForMock = new List <MediaServiceAccount> { new MediaServiceAccount { AccountId = id1, Name = "WAMS Account 1" }, new MediaServiceAccount { AccountId = id2, Name = "WAMS Account 2" } }; clientMock.Setup(f => f.GetMediaServiceAccountsAsync()).Returns(Task.Factory.StartNew(() => { return(accountsForMock); })); // Test var getAzureMediaServiceCommand = new GetAzureMediaServiceCommand { CommandRuntime = new MockCommandRuntime(), MediaServicesClient = clientMock.Object, CurrentSubscription = new SubscriptionData { SubscriptionId = SubscriptionId } }; getAzureMediaServiceCommand.ExecuteCmdlet(); Assert.AreEqual(1, ((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline.Count); var accounts = (IEnumerable <MediaServiceAccount>)((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline.FirstOrDefault(); Assert.IsNotNull(accounts); Assert.IsTrue(accounts.Any(mediaservice => (mediaservice).AccountId == id1)); Assert.IsTrue(accounts.Any(mediaservice => (mediaservice).AccountId == id2)); Assert.IsTrue(accounts.Any(mediaservice => (mediaservice).Name.Equals("WAMS Account 1"))); Assert.IsTrue(accounts.Any(mediaservice => (mediaservice).Name.Equals("WAMS Account 2"))); }
public void ProcessGetMediaServiceByNameShouldNotReturnEntriesForNoneMatchingName() { var clientMock = new Mock <IMediaServicesClient>(); string mediaServicesAccountName = Guid.NewGuid().ToString(); clientMock.Setup(f => f.GetMediaServiceAsync(mediaServicesAccountName)).Returns(Task.Factory.StartNew(() => { if (String.IsNullOrEmpty(mediaServicesAccountName)) { return(new MediaServiceAccountDetails()); } throw new ServiceManagementClientException(HttpStatusCode.NotFound, new ServiceManagementError { Code = HttpStatusCode.NotFound.ToString(), Message = "Account not found" }, string.Empty); })); // Test var getAzureMediaServiceCommand = new GetAzureMediaServiceCommand { CommandRuntime = new MockCommandRuntime(), MediaServicesClient = clientMock.Object, CurrentSubscription = new SubscriptionData { SubscriptionId = SubscriptionId } }; getAzureMediaServiceCommand.Name = mediaServicesAccountName; getAzureMediaServiceCommand.ExecuteCmdlet(); Assert.AreEqual(0, ((MockCommandRuntime)getAzureMediaServiceCommand.CommandRuntime).OutputPipeline.Count); }