public void TestIngestManifestFileCreateFailedRetryMessageLengthLimitExceeded()
        {
            var expected = new IngestManifestFileData { Name = "testData" };

            var fakeException = new WebException("test", WebExceptionStatus.MessageLengthLimitExceeded);

            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 10, expected);

            dataContextMock.Setup((ctxt) => ctxt.AddObject("IngestManifestFiles", It.IsAny<object>()));

            _mediaContext.MediaServicesClassFactory = new TestMediaServicesClassFactory(dataContextMock.Object);

            var parent = new IngestManifestAssetData { Asset = new AssetData { } };
            var ingestManifestFiles = new IngestManifestFileCollection(_mediaContext, parent);

            var tempFile = "a:\\wherever\\whatever.mp3";
            try
            {
                IIngestManifestFile actual = ingestManifestFiles.Create(tempFile);

                Assert.AreEqual(expected.Name, actual.Name);
                dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny<object>()), Times.Exactly(2));
            }
            catch (AggregateException ax)
            {
                dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny<object>()), Times.Exactly(1));
                WebException x = (WebException)ax.GetBaseException();
                Assert.AreEqual(fakeException, x);
                throw x;
            }

            Assert.Fail("Expected exception");
        }
        public void TestIngestManifestFileCreateFailedRetry()
        {
            var expected = new IngestManifestFileData {
                Name = "testData"
            };
            var fakeException   = new WebException("test", WebExceptionStatus.ConnectionClosed);
            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 10, expected);

            dataContextMock.Setup((ctxt) => ctxt.AddObject("IngestManifestFiles", It.IsAny <object>()));

            _mediaContext.MediaServicesClassFactory = new TestMediaServicesClassFactory(dataContextMock.Object);

            var parent = new IngestManifestAssetData {
                Asset = new AssetData {
                }
            };
            var ingestManifestFiles = new IngestManifestFileCollection(_mediaContext, parent);

            var tempFile = "a:\\wherever\\whatever.mp3";

            try
            {
                IIngestManifestFile actual = ingestManifestFiles.Create(tempFile);
            }
            catch (AggregateException ax)
            {
                WebException x = (WebException)ax.GetBaseException();
                dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny <object>()), Times.AtLeast(3));
                Assert.AreEqual(fakeException, x);
                throw x;
            }

            Assert.Fail("Expected exception");
        }
        public void TestIngestManifestFileCreateRetry()
        {
            var expected = new IngestManifestFileData {
                Name = "testData"
            };
            var fakeException   = new WebException("test", WebExceptionStatus.ConnectionClosed);
            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 2, expected);

            dataContextMock.Setup((ctxt) => ctxt.AddObject("IngestManifestFiles", It.IsAny <object>()));

            _mediaContext.MediaServicesClassFactory = new TestMediaServicesClassFactory(dataContextMock.Object);

            var parent = new IngestManifestAssetData {
                Asset = new AssetData {
                }
            };
            var ingestManifestFiles = new IngestManifestFileCollection(_mediaContext, parent);

            var tempFile = "a:\\wherever\\whatever.mp3";
            IIngestManifestFile actual = ingestManifestFiles.Create(tempFile);

            Assert.AreEqual(expected.Name, actual.Name);
            dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny <object>()), Times.Exactly(2));
        }
        public void TestIngestManifestFileCreateRetry()
        {
            var expected = new IngestManifestFileData { Name = "testData" };
            var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);
            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 2, expected);

            dataContextMock.Setup((ctxt) => ctxt.AddObject("IngestManifestFiles", It.IsAny<object>()));

            _mediaContext.MediaServicesClassFactory = new TestMediaServicesClassFactory(dataContextMock.Object);

            var parent = new IngestManifestAssetData { Asset = new AssetData {} };
            var ingestManifestFiles = new IngestManifestFileCollection(_mediaContext, parent);

            var tempFile = "a:\\wherever\\whatever.mp3";
            IIngestManifestFile actual = ingestManifestFiles.Create(tempFile);

            Assert.AreEqual(expected.Name, actual.Name);
            dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny<object>()), Times.Exactly(2));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CloudMediaContext"/> class.
        /// </summary>
        /// <param name="apiServer">A <see cref="Uri"/> representing a the API endpoint.</param>
        /// <param name="accountName">The Microsoft WindowsAzure Media Services account name to authenticate with.</param>
        /// <param name="accountKey">The Microsoft WindowsAzure Media Services account key to authenticate with.</param>
        /// <param name="scope">The scope of authorization.</param>
        /// <param name="acsBaseAddress">The access control endpoint to authenticate against.</param>
        public CloudMediaContext(Uri apiServer, string accountName, string accountKey, string scope, string acsBaseAddress)
        {
            this.ParallelTransferThreadCount = 10;
            this.NumberOfConcurrentTransfers = 2;

            OAuthDataServiceAdapter dataServiceAdapter =
                new OAuthDataServiceAdapter(accountName, accountKey, scope, acsBaseAddress, NimbusRestApiCertificateThumbprint, NimbusRestApiCertificateSubject);
            ServiceVersionAdapter versionAdapter = new ServiceVersionAdapter(KnownApiVersions.Current);

            this._dataContextFactory = new AzureMediaServicesDataServiceContextFactory(apiServer, dataServiceAdapter, versionAdapter, this);

            this._jobs = new JobBaseCollection(this);
            this._jobTemplates = new JobTemplateBaseCollection(this);
            this._assets = new AssetCollection(this);
            this._files = new AssetFileCollection(this);
            this._accessPolicies = new AccessPolicyBaseCollection(this);
            this._contentKeys = new ContentKeyCollection(this);
            this._notificationEndPoints = new NotificationEndPointCollection(this);
            this._mediaProcessors = new MediaProcessorBaseCollection(this);
            this._locators = new LocatorBaseCollection(this);
            this._ingestManifests = new IngestManifestCollection(this);
            this._ingestManifestAssets = new IngestManifestAssetCollection(this,null);
            this._ingestManifestFiles = new IngestManifestFileCollection(this, null);
        }