Esempio n. 1
0
        private static void VerifyManifestDeletion(string id)
        {
            CloudMediaContext context      = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IIngestManifest   expectedNull = context.IngestManifests.Where(c => c.Id == id).FirstOrDefault();

            Assert.IsNull(expectedNull, "Manifest has not been deleted as expected");
        }
Esempio n. 2
0
        public void ShouldDeleteAssetAndKeepAzureContainer()
        {
            IAsset asset = CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.None);

            Assert.AreEqual(AssetState.Initialized, asset.State);
            foreach (ILocator locator in asset.Locators)
            {
                locator.Delete();
            }

            var result = asset.DeleteAsync(true).Result;

            Assert.IsNull(_mediaContext.Assets.Where(a => a.Id == asset.Id).SingleOrDefault());

            CloudMediaContext newContext = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();

            Assert.IsNull(newContext.Assets.Where(a => a.Id == asset.Id).SingleOrDefault());

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(WindowsAzureMediaServicesTestConfiguration.ClientStorageConnectionString);
            string containername = asset.Id.Replace("nb:cid:UUID:", "asset-");
            var    client        = storageAccount.CreateCloudBlobClient();
            var    container     = client.GetContainerReference(containername);

            Assert.IsTrue(container.Exists(), "Asset container {0} can't be found", container);
        }
Esempio n. 3
0
        public static void ClassInit(TestContext context)
        {
            //CreateCounters();

            _mediaContext = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IContentKeyAuthorizationPolicyOption policyOption = null;

            for (int i = 0; i < 10; i++)
            {
                byte[]      expectedKey = null;
                IContentKey contentKey  = GetKeyDeliveryUrlTests.CreateTestKey(_mediaContext, ContentKeyType.EnvelopeEncryption, out expectedKey);

                policyOption = ContentKeyAuthorizationPolicyOptionTests.CreateOption(_mediaContext, String.Empty, ContentKeyDeliveryType.BaselineHttp, null, null, ContentKeyRestrictionType.Open);

                List <IContentKeyAuthorizationPolicyOption> options = new List <IContentKeyAuthorizationPolicyOption>
                {
                    policyOption
                };

                GetKeyDeliveryUrlTests.CreateTestPolicy(_mediaContext, String.Empty, options, ref contentKey);

                Uri keyDeliveryServiceUri = contentKey.GetKeyDeliveryUrl(ContentKeyDeliveryType.BaselineHttp);

                Assert.IsNotNull(keyDeliveryServiceUri);
                string rawkey = EncryptionUtils.GetKeyIdAsGuid(contentKey.Id).ToString();
                _testData.Add(new Tuple <Uri, string, string>(keyDeliveryServiceUri, TokenServiceClient.GetAuthTokenForKey(rawkey), GetKeyDeliveryUrlTests.GetString(expectedKey)));
            }
        }
        public void ShouldDeleteAssetWithCommonEncryptionContentKey()
        {
            var dataContext2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();

            // Note that this file is not really PlayReady encrypted.  For the purposes of this test that is okay.
            IAsset asset   = AssetTests.CreateAsset(_mediaContext, Path.GetFullPath(WindowsAzureMediaServicesTestConfiguration.SmallWmv), AssetCreationOptions.CommonEncryptionProtected);
            string assetId = asset.Id;
            string fileId  = asset.AssetFiles.ToList()[0].Id;

            Guid keyId = Guid.NewGuid();

            byte[]      contentKeyBytes = GetRandomBuffer(16);
            IContentKey key             = _mediaContext.ContentKeys.Create(keyId, contentKeyBytes);

            asset.ContentKeys.Add(key);

            string keyIdentifier = key.Id;

            asset.Delete();

            IAsset resultAsset = dataContext2.Assets.Where(a => a.Id == assetId).FirstOrDefault();

            Assert.IsNull(resultAsset, "Asset was deleted we should not be able to query it by identifier.");

            IAssetFile resultFile = dataContext2.Files.Where(f => f.Id == fileId).FirstOrDefault();

            Assert.IsNull(resultFile, "Asset was deleted we should not be able to query its associated File by identifier.");

            // The content key should not exists
            IContentKey resultContentKey = dataContext2.ContentKeys.Where(c => c.Id == keyIdentifier).FirstOrDefault();

            Assert.IsNull(resultContentKey, "Common Encryption Content Key should be deleted by deleting the asset");
        }
Esempio n. 5
0
        public void EncryptManifestTestDisableOverwriteExistingFile()
        {
            CloudMediaContext context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            var sourcePath            = DeploymentFolder1;

            Assert.IsTrue(Directory.Exists(sourcePath));
            List <string>   files                 = Directory.EnumerateFiles(sourcePath, "*.txt").ToList();
            const string    manifestName          = "Manifest 1";
            IIngestManifest ingestManifestCreated = context.IngestManifests.Create(manifestName);

            //Adding manifest asset info with multiple file
            IAsset emptyAsset = context.Assets.Create(Guid.NewGuid().ToString(), AssetCreationOptions.StorageEncrypted);

            IIngestManifestAsset ingestManifestAsset = ingestManifestCreated.IngestManifestAssets.Create(emptyAsset, files.ToArray());

            var path = @".\Resources\TestFiles\" + Guid.NewGuid();

            try
            {
                Directory.CreateDirectory(path);
                string dupFileName = Path.Combine(path, Path.GetFileName(files[0]));
                File.WriteAllText(dupFileName, "");
                ingestManifestCreated.EncryptFiles(path, false);
            }
            catch (AggregateException ax)
            {
                var expectedExcpetion = ax.GetBaseException() as IOException;
                throw expectedExcpetion;
            }
            finally
            {
                AssetFilesTests.CleanDirectory(path);
            }
        }
        private static void FindLocatorByNameAndVerifyIt(string locatorNameToSearch, string expectedLocatorId)
        {
            var context2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            var updated  = context2.Locators.Where(c => c.Name == locatorNameToSearch).FirstOrDefault();

            Assert.AreEqual(updated.Id, expectedLocatorId);
        }
        private static void EncryptFilesDecryptAndCompare(List <string> files)
        {
            CloudMediaContext context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            //Creating empty manifest
            const string    manifestName          = "Manifest 1";
            IIngestManifest ingestManifestCreated = context.IngestManifests.Create(manifestName);

            //Adding manifest asset info with multiple file
            IAsset emptyAsset = context.Assets.Create(Guid.NewGuid().ToString(), AssetCreationOptions.StorageEncrypted);

            IIngestManifestAsset ingestManifestAsset = ingestManifestCreated.IngestManifestAssets.CreateAsync(emptyAsset, files.ToArray(), CancellationToken.None).Result;

            var path = @".\Resources\TestFiles\" + Guid.NewGuid();

            Directory.CreateDirectory(path);
            ingestManifestCreated.EncryptFiles(path);

            Dictionary <string, string> filePaths = new Dictionary <string, string>();

            foreach (var filePath in files)
            {
                FileInfo fileInfo = new FileInfo(filePath);
                filePaths.Add(fileInfo.Name, filePath);
            }


            foreach (var assetFile in ingestManifestAsset.IngestManifestFiles)
            {
                var encryptedPath = Path.Combine(path, assetFile.Name);
                Assert.IsTrue(File.Exists(encryptedPath));
                var decryptedPath = DecryptedFile(assetFile, encryptedPath, context);
                Assert.IsTrue(AssetTests.CompareFiles(decryptedPath, filePaths[assetFile.Name]), "Original file and Decrypted are not same");
            }
        }
Esempio n. 8
0
        public void ShouldThrowExceptionWhenAttemptingToCreateManifestAssetFromContextCollection()
        {
            CloudMediaContext context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IAsset            asset1  = context.Assets.Create("Asset1", AssetCreationOptions.CommonEncryptionProtected);

            context.IngestManifestAssets.Create(asset1, new[] { "C:\\temp.txt" });
        }
        public void ExpirationTimeOfCreatedLocatorShouldMatchLocatorStartTimePlusPolicyDuration()
        {
            // Arrange


            var accessPolicy = _mediaContext.AccessPolicies.Create("TestPolicy", TimeSpan.FromMinutes(10), AccessPermissions.List | AccessPermissions.Read);
            var asset        = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.None);

            DateTime locatorStartTime = DateTime.Now.AddHours(1);

            // Act
            var locatorTask = _mediaContext.Locators.CreateLocatorAsync(LocatorType.Sas, asset, accessPolicy, locatorStartTime.ToUniversalTime(), null);

            locatorTask.Wait();
            var locator = locatorTask.Result;

            var context2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            var actual   = context2.Locators.Where(x => x.Id == locator.Id).FirstOrDefault();

            // Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(locator.Id, actual.Id);
            Assert.IsNotNull(actual.Path);
            Assert.AreEqual(asset.Id, actual.Asset.Id);
            Assert.AreEqual(asset.Name, actual.Asset.Name);
            Assert.AreEqual(accessPolicy.Id, actual.AccessPolicy.Id);
            var expectedExpiration = locatorStartTime.Add(accessPolicy.Duration).ToUniversalTime();

            Assert.AreEqual(expectedExpiration, locator.ExpirationDateTime);
        }
        public void ShouldCreateLocatorWhenCreateSasLocatorAsyncCalled()
        {
            // Arrange


            var accessPolicy = _mediaContext.AccessPolicies.Create("TestPolicy", TimeSpan.FromMinutes(10), AccessPermissions.List | AccessPermissions.Read);
            var asset        = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.None);

            // Act
            var task = _mediaContext.Locators.CreateSasLocatorAsync(asset, accessPolicy);

            task.Wait();

            var locator = task.Result;

            var context2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            var actual   = context2.Locators.Where(x => x.Id == locator.Id).FirstOrDefault();

            // Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(locator.Id, actual.Id);
            Assert.IsNotNull(actual.Path);
            Assert.IsTrue(actual.ExpirationDateTime < DateTime.UtcNow.AddMinutes(11));
            Assert.AreEqual(asset.Id, actual.Asset.Id);
            Assert.AreEqual(asset.Name, actual.Asset.Name);
            Assert.AreEqual(accessPolicy.Id, actual.AccessPolicy.Id);
        }
        public void ShouldUpdateExpiryTimeWhenUpdateLocatorAsyncCalledWithStartAndExpiryTime()
        {
            // Arrange

            var accessPolicyDuration = TimeSpan.FromHours(2);
            var expectedExpiryTime   = DateTime.UtcNow.Date.AddDays(2);
            var expectedStartTime    = DateTime.UtcNow.Date.AddDays(1);

            var accessPolicy = _mediaContext.AccessPolicies.Create("TestPolicy", accessPolicyDuration, AccessPermissions.Read);
            var asset        = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.None);
            var locator      = _mediaContext.Locators.CreateLocator(LocatorType.OnDemandOrigin, asset, accessPolicy);

            // Act
            var task = locator.UpdateAsync(expectedStartTime, expectedExpiryTime);

            task.Wait();

            var context2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            var actual   = context2.Locators.Where(x => x.Id == locator.Id).FirstOrDefault();

            // Assert
            Assert.AreEqual(expectedStartTime, locator.StartTime);
            Assert.AreEqual(expectedExpiryTime, locator.ExpirationDateTime);
            Assert.AreEqual(expectedExpiryTime, actual.ExpirationDateTime);
        }
Esempio n. 12
0
        public void ListAssetsAndFilesForNewlyCreatedManifests()
        {
            IIngestManifest ingestManifest = CreateEmptyManifestAndVerifyIt();

            IAsset asset = _mediaContext.Assets.Create("name", AssetCreationOptions.None);

            Assert.IsNotNull(asset);
            IIngestManifestAsset ingestManifestAsset = ingestManifest.IngestManifestAssets.Create(asset, new[] { TestFile1 });

            VerifyManifestAsset(ingestManifestAsset);
            IIngestManifestAsset firstAsset = ingestManifest.IngestManifestAssets.FirstOrDefault();

            VerifyManifestAsset(firstAsset);
            Assert.AreEqual(ingestManifestAsset.Id, firstAsset.Id);

            _mediaContext = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IIngestManifest sameIngestManifest = _mediaContext.IngestManifests.Where(c => c.Id == ingestManifest.Id).FirstOrDefault();

            Assert.IsNotNull(sameIngestManifest);
            Assert.AreEqual(1, sameIngestManifest.IngestManifestAssets.Count(), "Manifest asset count is not matching expecting value 1");
            firstAsset = sameIngestManifest.IngestManifestAssets.FirstOrDefault();
            VerifyManifestAsset(firstAsset);
            Assert.AreEqual(1, firstAsset.IngestManifestFiles.Count(), "Manifest file count is not matching expecting value 1");
            IIngestManifestFile firstFile = firstAsset.IngestManifestFiles.FirstOrDefault();

            Assert.AreEqual("text/plain", firstFile.MimeType, "IngestManifestFile's MimeType is wrong");
            VerifyManifestFile(firstFile);
        }
        public void ShouldCancelDownloadToFileAsyncTaskAfter50Milliseconds()
        {
            string fileUploaded    = _smallWmv;
            string outputDirectory = "Download" + Guid.NewGuid();
            string fileDownloaded  = Path.Combine(outputDirectory, Path.GetFileName(fileUploaded));

            IAsset     asset     = AssetTests.CreateAsset(_mediaContext, Path.GetFullPath(fileUploaded), AssetCreationOptions.StorageEncrypted);
            IAssetFile assetFile = asset.AssetFiles.First();

            Assert.AreEqual(assetFile.Asset.Id, asset.Id);
            Assert.AreEqual(1, asset.Locators.Count);

            CleanDirectory(outputDirectory);

            var                source             = new CancellationTokenSource();
            IAccessPolicy      accessPolicy       = _mediaContext.AccessPolicies.Create("SdkDownload", TimeSpan.FromHours(12), AccessPermissions.Read);
            ILocator           locator            = _mediaContext.Locators.CreateSasLocator(asset, accessPolicy);
            BlobTransferClient blobTransferClient = _mediaContext.MediaServicesClassFactory.GetBlobTransferClient();


            Exception canceledException  = null;
            Task      downloadToFileTask = null;

            try
            {
                downloadToFileTask = assetFile.DownloadAsync(fileDownloaded, blobTransferClient, locator, source.Token);

                // Send a cancellation signal after 2 seconds.
                Thread.Sleep(50);
                source.Cancel();

                // Block the thread waiting for the job to finish.
                downloadToFileTask.Wait();
            }
            catch (AggregateException exception)
            {
                Assert.AreEqual(1, exception.InnerExceptions.Count);
                canceledException = exception.InnerException;
            }
            finally
            {
                if (File.Exists(fileDownloaded))
                {
                    File.Delete(fileDownloaded);
                }
            }

            Assert.IsNotNull(canceledException);
            Assert.IsInstanceOfType(canceledException, typeof(OperationCanceledException));

            // The async task ends in a Canceled state.
            Assert.AreEqual(TaskStatus.Canceled, downloadToFileTask.Status);

            CloudMediaContext newContext = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();

            IAsset retreivedAsset = newContext.Assets.Where(a => a.Id == asset.Id).Single();

            Assert.AreEqual(2, retreivedAsset.Locators.Count);
        }
Esempio n. 14
0
        private static void VerifyAssetStateAndDelete(IngestManifestState expectedState, string id)
        {
            IIngestManifest ingestManifest = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext().IngestManifests.Where(c => c.Id == id).FirstOrDefault();

            Assert.IsNotNull(ingestManifest);
            Assert.AreEqual(expectedState, ingestManifest.State);
            ingestManifest.Delete();
        }
Esempio n. 15
0
        private static void VerifyNameForExitingManifest(IIngestManifest ingestManifest, string newName, string id)
        {
            CloudMediaContext context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IIngestManifest   updatedIngestManifest = context.IngestManifests.Where(c => c.Id == id).FirstOrDefault();

            Assert.IsNotNull(updatedIngestManifest);
            Assert.AreSame(newName, ingestManifest.Name);
        }
Esempio n. 16
0
        public void MediaServicesCredentialsTestAuthorizationHeader()
        {
            var credentials = WindowsAzureMediaServicesTestConfiguration.CreateMediaServicesCredentials();
            var header      = credentials.GetAuthorizationHeader();

            Assert.IsNotNull(header);
            Assert.AreEqual("Bearer " + credentials.AccessToken, header);
        }
Esempio n. 17
0
 public void SetupTest()
 {
     _mediaContext = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
     _smallWmv     = WindowsAzureMediaServicesTestConfiguration.GetVideoSampleFilePath(TestContext,
                                                                                       WindowsAzureMediaServicesTestConfiguration.SmallWmv);
     _largeFile       = WindowsAzureMediaServicesTestConfiguration.GetVideoSampleFilePath(TestContext, "largeFile");
     _emptyFile       = WindowsAzureMediaServicesTestConfiguration.GetVideoSampleFilePath(TestContext, "emptyFile");
     _outputDirectory = "MediaDownloads";
 }
Esempio n. 18
0
        public void CreateEmptyBulkIngestManifestAsync()
        {
            CloudMediaContext      context        = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            const string           manifestName   = "";
            Task <IIngestManifest> taskManifest   = context.IngestManifests.CreateAsync(manifestName);
            IIngestManifest        ingestManifest = taskManifest.Result;

            Assert.IsTrue(String.IsNullOrEmpty(ingestManifest.Name));
        }
        public static void VerifyAllTasksFinished(string jobId)
        {
            CloudMediaContext context2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IJob job2 = context2.Jobs.Where(c => c.Id == jobId).Single();

            Assert.AreEqual(JobState.Finished, job2.State);

            foreach (ITask task in job2.Tasks)
            {
                Assert.AreEqual(JobState.Finished, task.State);
            }
        }
        public void MediaServicesCredentialsTestGetToken()
        {
            MediaServicesCredentials target = WindowsAzureMediaServicesTestConfiguration.CreateMediaServicesCredentials();

            Assert.IsNull(target.AccessToken);
            Assert.IsTrue(target.TokenExpiration < DateTime.UtcNow);

            target.RefreshToken();

            Assert.IsNotNull(target.AccessToken);
            Assert.IsTrue(target.AccessToken.Length > 0);
            Assert.IsTrue(target.TokenExpiration > DateTime.UtcNow.AddHours(1));
        }
Esempio n. 21
0
        public void When_Uploading_Multiple_Files_The_Progress_Event_Should_Only_Be_For_The_Bound_AssetFile()
        {
            IAsset        asset        = _mediaContext.Assets.Create("test", AssetCreationOptions.None);
            string        fileUploaded = _smallWmv;
            var           file         = new FileInfo(fileUploaded);
            IAssetFile    fileInfo     = asset.AssetFiles.Create(Path.GetFileName(_smallWmv));
            IAccessPolicy policy       = _mediaContext.AccessPolicies.Create("Write", TimeSpan.FromMinutes(10),
                                                                             AccessPermissions.Write);
            ILocator locator = _mediaContext.Locators.CreateLocator(LocatorType.Sas, asset, policy);
            var      btc     = new BlobTransferClient
            {
                NumberOfConcurrentTransfers = 5,
                ParallelTransferThreadCount = 5
            };

            int allProgressEventsFiredCount = 0;

            btc.TransferProgressChanged += (sender, args) => { allProgressEventsFiredCount++; };

            bool progressFired           = false;
            bool wrongFileSize           = true;
            int  fileProgressEventsCount = 0;

            fileInfo.UploadProgressChanged += (s, e) =>
            {
                progressFired = true;
                wrongFileSize = e.TotalBytes != file.Length;
                fileProgressEventsCount++;
            };

            Task uploadTask = fileInfo.UploadAsync(fileUploaded, btc, locator, CancellationToken.None);

            string competingFile = WindowsAzureMediaServicesTestConfiguration.GetVideoSampleFilePath(TestContext,
                                                                                                     WindowsAzureMediaServicesTestConfiguration.SmallMp41);

            var retryPolicy =
                _mediaContext.MediaServicesClassFactory.GetBlobStorageClientRetryPolicy()
                .AsAzureStorageClientRetryPolicy();

            btc.UploadBlob(CreateUrl(locator, Path.GetFileName(competingFile)), competingFile, null, null,
                           CancellationToken.None, retryPolicy).Wait();

            uploadTask.Wait();

            Assert.IsTrue(progressFired, "No upload progress event fired");
            Assert.IsFalse(wrongFileSize, "Received the wrong file size from the upload progress event");
            Assert.IsTrue(condition: fileProgressEventsCount < allProgressEventsFiredCount,
                          message:
                          "Unexpected number of fired events, it should be more than the events fired for the uploaded file.");
        }
Esempio n. 22
0
        public void DeleteManifestShouldDeleteAllManifestAssetsAndFiles()
        {
            CloudMediaContext context        = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IIngestManifest   ingestManifest = CreateManifestWithAssetsAndVerifyIt(context);

            VerifyExistenceofAssetsAndFilesForManifest(ingestManifest, context);
            ingestManifest.Delete();
            context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            int assetsCount = context.IngestManifestAssets.Where(c => c.ParentIngestManifestId == ingestManifest.Id).Count();
            int filescount  = context.IngestManifestFiles.Where(c => c.ParentIngestManifestId == ingestManifest.Id).Count();

            Assert.AreEqual(0, assetsCount, "There are assets belonging to manifest after manifest deletion");
            Assert.AreEqual(0, filescount, "There are files belonging to manifest assets after manifest deletion");
        }
        public void MediaServicesCredentialsPassingAcsEndPoint()
        {
            var    context1 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            string account  = WindowsAzureMediaServicesTestConfiguration.MediaServiceAccountName;
            string key      = WindowsAzureMediaServicesTestConfiguration.MediaServiceAccountKey;
            MediaServicesCredentials credentials = new MediaServicesCredentials(account, key, WindowsAzureMediaServicesTestConfiguration.MediaServicesAccessScope, WindowsAzureMediaServicesTestConfiguration.MediaServicesAcsBaseAddress);

            Assert.IsNull(credentials.AccessToken);
            Assert.IsTrue(credentials.TokenExpiration < DateTime.UtcNow);

            credentials.RefreshToken();

            Assert.IsNotNull(credentials.AccessToken);
            Assert.IsTrue(credentials.AccessToken.Length > 0);
            Assert.IsTrue(credentials.TokenExpiration > DateTime.UtcNow);
        }
Esempio n. 24
0
        public void AddingAdditionalFilesToAssetInManifest()
        {
            IIngestManifest ingestManifestCreated = CreateManifestWithAssetsAndVerifyIt(_mediaContext);

            _mediaContext = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            var ingestManifestRefreshed = _mediaContext.IngestManifests.Where(c => c.Id == ingestManifestCreated.Id).FirstOrDefault();

            Assert.IsNotNull(ingestManifestRefreshed.Statistics);
            Assert.IsNotNull(ingestManifestCreated.Statistics);
            Assert.AreEqual(2, ingestManifestRefreshed.Statistics.PendingFilesCount);

            AddFileToExistingManifestAssetInfo(_mediaContext, ingestManifestCreated.Id);
            _mediaContext           = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            ingestManifestRefreshed = _mediaContext.IngestManifests.Where(c => c.Id == ingestManifestCreated.Id).FirstOrDefault();
            Assert.AreEqual(3, ingestManifestRefreshed.Statistics.PendingFilesCount);
        }
        public static void WaitForJob(string jobId, JobState jobState, Action <string> verifyAction, Action <double> progressChangedAction = null)
        {
            DateTime start = DateTime.Now;

            while (true)
            {
                CloudMediaContext context2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
                IJob  job2    = context2.Jobs.Where(c => c.Id == jobId).Single();
                ITask jobtask = job2.Tasks.Where(t => t.State == JobState.Processing).FirstOrDefault();

                if (jobtask != null && jobtask.Progress > 0 && jobtask.Progress <= 100)
                {
                    if (progressChangedAction != null)
                    {
                        progressChangedAction(jobtask.Progress);
                    }
                }
                if (job2.State == jobState)
                {
                    verifyAction(jobId);
                    return;
                }
                if (job2.State == JobState.Error)
                {
                    StringBuilder str = new StringBuilder();
                    str.AppendFormat("Job should not fail - Current State = {0} Expected State = {1} jobId = {2}", job2.State, jobState, jobId);
                    str.AppendLine();
                    foreach (var task in job2.Tasks)
                    {
                        foreach (var error in task.ErrorDetails)
                        {
                            str.AppendFormat("Error Code: {0} ErrorMessage: {1}", error.Code, error.Message);
                            str.AppendLine();
                        }
                    }

                    throw new Exception(str.ToString());
                }

                if (DateTime.Now - start > TimeSpan.FromMinutes(JobTimeOutInMinutes))
                {
                    throw new Exception("Job Timed out - Current State " + job2.State.ToString() + " Expected State " + jobState + " jobId = " + jobId);
                }
                Thread.Sleep(TimeSpan.FromSeconds(10));
            }
        }
        public void ShouldDeleteLocatorWhenDeleteLocatorCalled()
        {
            // Arrange

            var accessPolicy = _mediaContext.AccessPolicies.Create("TestPolicy", TimeSpan.FromMinutes(10), AccessPermissions.List | AccessPermissions.Read);
            var asset        = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.None);
            var locator      = _mediaContext.Locators.CreateSasLocator(asset, accessPolicy);

            // Act
            locator.Delete();

            var context2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            var actual   = context2.Locators.Where(x => x.Id == locator.Id).FirstOrDefault();

            // Assert
            Assert.IsNull(actual);
        }
        public void MediaServicesCredentialsTestReuseToken()
        {
            var context1 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();

            Assert.IsNull(context1.Credentials.AccessToken);
            //In order to obtain token REST call need to be issued
            MakeRestCallAndVerifyToken(context1);
            MediaServicesCredentials credentials = new MediaServicesCredentials("whatever", "whatever")
            {
                AccessToken     = context1.Credentials.AccessToken,
                TokenExpiration = context1.Credentials.TokenExpiration
            };

            var context2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext(credentials);

            context2.Assets.FirstOrDefault();
        }
Esempio n. 28
0
        private static string CreateManifestEncryptFiles(out List <IIngestManifestFile> files, out IIngestManifest ingestManifestCreated)
        {
            CloudMediaContext context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();

            ingestManifestCreated = CreateManifestWithAssetsAndVerifyIt(context);
            var destination = @".\Resources\TestFiles\" + Guid.NewGuid();

            Directory.CreateDirectory(destination);
            ingestManifestCreated.EncryptFilesAsync(destination, CancellationToken.None).Wait();

            var manifestid = ingestManifestCreated.Id;

            //returning all encrypted files
            files = context.IngestManifestFiles.Where(c => c.ParentIngestManifestId == manifestid && c.IsEncrypted == true).ToList();
            Assert.AreEqual(2, files.Count);
            return(destination);
        }
        public void ShouldSubmitAndFinishEETaskWithStorageProtectedInputAndClearOutput()
        {
            //
            //  This test uses the same preset as the EE DRM tests but does not apply
            //  common encryption.  This preset gets split into multiple subtasks by EE.
            //

            IAsset asset = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted);

            // Load the EE preset to create a smooth streaming presentation with PlayReady protection
            string xmlPreset = File.ReadAllText(WindowsAzureMediaServicesTestConfiguration.EncodePlusEncryptWithEeXml);

            // Remove the DRM Section to produce clear content
            var doc = new XmlDocument();

            doc.LoadXml(xmlPreset);

            XmlNodeList drmNodes = doc.GetElementsByTagName("Drm");

            Assert.AreEqual(1, drmNodes.Count);

            XmlNode drmNode = drmNodes[0];

            drmNode.ParentNode.RemoveChild(drmNode);

            xmlPreset = doc.OuterXml;
            IMediaProcessor processor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName);
            IJob            job       = CreateAndSubmitOneTaskJob(_mediaContext, GenerateName("ShouldSubmitAndFinishEETaskWithStorageProtectedInputAndClearOutput"), processor, xmlPreset, asset, TaskOptions.None);

            Assert.AreEqual(1, job.Tasks.Count);
            Assert.AreEqual(TaskOptions.None, job.Tasks[0].Options);
            Assert.IsNull(job.Tasks[0].InitializationVector);
            Assert.IsTrue(String.IsNullOrEmpty(job.Tasks[0].EncryptionKeyId));
            Assert.IsNull(job.Tasks[0].EncryptionScheme);
            Assert.IsNull(job.Tasks[0].EncryptionVersion);

            WaitForJob(job.Id, JobState.Finished, VerifyAllTasksFinished);

            CloudMediaContext context2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IJob job2 = context2.Jobs.Where(c => c.Id == job.Id).Single();

            Assert.AreEqual(1, job2.Tasks.Count);
            Assert.AreEqual(1, job2.Tasks[0].OutputAssets.Count);
        }
        public void ShouldDeleteEmptyAsset()
        {
            IAsset asset = _mediaContext.Assets.Create("ShouldDeleteEmptyAsset", AssetCreationOptions.None);


            Assert.AreEqual(AssetState.Initialized, asset.State);
            foreach (ILocator locator in asset.Locators)
            {
                locator.Delete();
            }

            asset.Delete();

            Assert.IsNull(_mediaContext.Assets.Where(a => a.Id == asset.Id).SingleOrDefault());

            CloudMediaContext newContext = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();

            Assert.IsNull(newContext.Assets.Where(a => a.Id == asset.Id).SingleOrDefault());
        }