示例#1
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";
 }
示例#2
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.");
        }
 public void SetupTest()
 {
     _mediaContext     = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
     _smallWmv         = WindowsAzureMediaServicesTestConfiguration.GetVideoSampleFilePath(TestContext, WindowsAzureMediaServicesTestConfiguration.SmallWmv);
     _downloadProgress = 0;
 }
        public void RunAllGetEffectiveDeliveryPolicyTestCases()
        {
            string testCaseDataFilePath = WindowsAzureMediaServicesTestConfiguration.GetVideoSampleFilePath(TestContext, c_TestCaseDataFile);

            string[] testCases = File.ReadAllLines(testCaseDataFilePath);
            Assert.IsNotNull(testCases);
            Assert.AreEqual(401, testCases.Length); // ensure we have the expected number of cases

            int failureCount = 0;

            StringBuilder builder = new StringBuilder();

            builder.Append(testCases[0]);
            builder.Append(",ActualAssetType,ActualIsStreamable,ActualEffectiveEncryptionState");
            builder.AppendLine();

            for (int i = 1; i < testCases.Length; i++)
            {
                string[]                parameters              = testCases[i].Split(',');
                AssetCreationOptions    options                 = (AssetCreationOptions)Enum.Parse(typeof(AssetCreationOptions), parameters[0]);
                AssetType               assetType               = (AssetType)Enum.Parse(typeof(AssetType), parameters[1]);
                AssetDeliveryProtocol   assetDeliveryProtocol   = (AssetDeliveryProtocol)Enum.Parse(typeof(AssetDeliveryProtocol), parameters[2]);
                AssetDeliveryPolicyType assetDeliveryPolicyType = (AssetDeliveryPolicyType)Enum.Parse(typeof(AssetDeliveryPolicyType), parameters[3]);
                AssetEncryptionState    expectedEncryptionState = (AssetEncryptionState)Enum.Parse(typeof(AssetEncryptionState), parameters[4]);
                bool      expectedIsStreamable = bool.Parse(parameters[5]);
                AssetType expectedAssetType    = (AssetType)Enum.Parse(typeof(AssetType), parameters[6]);

                IAsset asset = GetTestAsset(options, assetType, assetDeliveryProtocol, assetDeliveryPolicyType);

                AssetEncryptionState actualEncryptionState = asset.GetEncryptionState(assetDeliveryProtocol);

                if (false == ((expectedAssetType == asset.AssetType) &&
                              (expectedIsStreamable == asset.IsStreamable) &&
                              (expectedEncryptionState == actualEncryptionState)
                              )
                    )
                {
                    // We had a failure so increase our failed count and then save the details of the test case and where it failed
                    failureCount++;

                    builder.Append(testCases[i]);
                    builder.Append(",");
                    builder.Append(asset.AssetType.ToString());
                    builder.Append(",");
                    builder.Append(asset.IsStreamable.ToString());
                    builder.Append(",");
                    builder.Append(actualEncryptionState.ToString());
                    builder.AppendLine();
                }
            }

            if (failureCount > 0)
            {
                Assert.Fail("Some RunAllGetEffectiveDeliveryPolicyTestCases failed");

                // If there are a lot of failures the best way to debug then is to dump
                // failed test case input and output data to a csv file for more detailed
                // analysis
                //File.WriteAllText("output.csv", builder.ToString());
            }
        }