コード例 #1
0
        public void ChannelCRUDTest()
        {
            var account    = App.Config.Content.ContentProviders[0].MediaServicesSets[0].MediaServicesAccounts[0];
            var controller = new ChannelsController();
            var context    = account.GetContext();
            int chnlCount  = context.Channels.Count();
            var name       = string.Format("New-Channel-{0}", DateTime.UtcNow.ToOADate().ToString().Replace(".", "-"));
            var settings   = new Models.ChannelSettings
            {
                Name = name
            };
            var operation = controller.Create(account.AccountName, settings);

            while (operation.State == OperationState.InProgress)
            {
                Thread.Sleep(10000);
                operation = context.Operations.GetOperation(operation.Id);
            }
            Assert.AreEqual(chnlCount + 1, context.Channels.Count());

            var channel = context.Channels.ToList().First(c => c.Name == name);

            var range = new Models.IPRange
            {
                SubnetPrefixLength = 32,
                Address            = "127.0.0.1"
            };

            //update the channel.
            var updateSettings = new Models.ChannelUpdateSettings
            {
                IngestAllowList  = new Models.IPRange[] { range },
                PreviewAllowList = new Models.IPRange[] { range },
                Description      = "SomeDescription"
            };

            operation = controller.Update(account.AccountName, channel.Id.NimbusIdToRawGuid(), updateSettings);
            while (operation.State == OperationState.InProgress)
            {
                Thread.Sleep(10000);
                operation = context.Operations.GetOperation(operation.Id);
            }

            // create new context to avoid cache issue.
            context = account.GetContext();
            channel = context.Channels.Where(c => c.Id == channel.Id).FirstOrDefault();
            Assert.IsNotNull(channel);

            // verify ingest.
            Assert.AreEqual(1, channel.Input.AccessControl.IPAllowList.Count);
            Assert.AreEqual("Range0", channel.Input.AccessControl.IPAllowList[0].Name);
            Assert.AreEqual(range.SubnetPrefixLength, channel.Input.AccessControl.IPAllowList[0].SubnetPrefixLength);
            Assert.AreEqual(range.Address, channel.Input.AccessControl.IPAllowList[0].Address);

            // verify preview.
            Assert.AreEqual(1, channel.Preview.AccessControl.IPAllowList.Count);
            Assert.AreEqual("Range0", channel.Preview.AccessControl.IPAllowList[0].Name);
            Assert.AreEqual(range.SubnetPrefixLength, channel.Preview.AccessControl.IPAllowList[0].SubnetPrefixLength);
            Assert.AreEqual(range.Address, channel.Preview.AccessControl.IPAllowList[0].Address);

            operation = controller.Delete(account.AccountName, channel.Id.NimbusIdToRawGuid());
            while (operation.State == OperationState.InProgress)
            {
                Thread.Sleep(10000);
                operation = context.Operations.GetOperation(operation.Id);
            }
            Assert.AreEqual(chnlCount, context.Channels.Count());
        }