public void ShouldCreateEncryptedInitilizedAsset()
        {
            IAsset asset = _mediaContext.Assets.Create("Test", AssetCreationOptions.StorageEncrypted);

            Assert.IsNotNull(asset, "Asset should be non null");
            Assert.AreNotEqual(Guid.Empty, asset.Id, "Asset ID shuold not be null");
            Assert.AreEqual(0, asset.AssetFiles.Count(), "Asset has files");
            Assert.AreEqual(AssetState.Initialized, asset.State, "Expecting initilized state");

            IAccessPolicy policy  = _mediaContext.AccessPolicies.Create("temp", TimeSpan.FromMinutes(10), AccessPermissions.Write);
            ILocator      locator = _mediaContext.Locators.CreateSasLocator(asset, policy);

            IAssetFile file = asset.AssetFiles.Create(Path.GetFileName(_smallWmv));

            Task task = file.UploadAsync(_smallWmv,
                                         _mediaContext.MediaServicesClassFactory.GetBlobTransferClient(),
                                         locator,
                                         CancellationToken.None);

            task.Wait();
            Assert.IsTrue(task.IsCompleted);
            Assert.IsTrue(!task.IsFaulted);
            locator.Delete();
            policy.Delete();
            IAsset refreshedAsset = _mediaContext.Assets.Where(c => c.Id == asset.Id).FirstOrDefault();

            Assert.AreEqual(asset.Name, refreshedAsset.Name);
            Assert.AreEqual(AssetState.Initialized, refreshedAsset.State);
            Assert.AreEqual(1, refreshedAsset.AssetFiles.Count(), "file count wrong");
            VerifyAndDownloadAsset(refreshedAsset, 1, false);
            ContentKeyTests.VerifyFileAndContentKeyMetadataForStorageEncryption(refreshedAsset, _mediaContext);
        }
Пример #2
0
        public void ShouldCreateEncryptedInitilizedAsset()
        {
            IAsset asset = _dataContext.Assets.Create("Test", AssetCreationOptions.StorageEncrypted);

            Assert.IsNotNull(asset, "Asset should be non null");
            Assert.AreNotEqual(Guid.Empty, asset.Id, "Asset ID shuold not be null");
            Assert.AreEqual(0, asset.AssetFiles.Count(), "Asset has files");
            Assert.AreEqual(AssetState.Initialized, asset.State, "Expecting initilized state");

            IAccessPolicy policy  = _dataContext.AccessPolicies.Create("temp", TimeSpan.FromMinutes(10), AccessPermissions.Write);
            ILocator      locator = _dataContext.Locators.CreateSasLocator(asset, policy);

            IAssetFile file = asset.AssetFiles.Create(Path.GetFileName(_smallWmv));

            Task task = file.UploadAsync(_smallWmv,
                                         new BlobTransferClient
            {
                NumberOfConcurrentTransfers = 10,
                ParallelTransferThreadCount = 10
            },
                                         locator,
                                         CancellationToken.None);

            task.Wait();
            Assert.IsTrue(task.IsCompleted);
            Assert.IsTrue(!task.IsFaulted);
            locator.Delete();
            policy.Delete();
            IAsset refreshedAsset = _dataContext.Assets.Where(c => c.Id == asset.Id).FirstOrDefault();

            Assert.AreEqual(asset.Name, refreshedAsset.Name);
            Assert.AreEqual(AssetState.Initialized, refreshedAsset.State);
            Assert.AreEqual(1, refreshedAsset.AssetFiles.Count(), "file count wrong");
            // TODO: Task 27827: Design and implement a KeyOracle Role to hold the Private key or keys used to protect content keys
            //VerifyAndDownloadAsset(refreshedAsset);
            ContentKeyTests.VerifyFileAndContentKeyMetadataForStorageEncryption(refreshedAsset, _dataContext);
        }