コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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")));
        }