public void DefaultMediaRetryPolicyTestExecuteActionNonTransient()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(null);

            int exceptionCount = 2;
            int expected       = 10;
            //IOException should not be retried when using default TestMediaServicesClassFactory instead of
            //CustomTestMediaServicesClassFactory
            var fakeException = new IOException("CustomRetryPolicyException");

            Func <int> func = () =>
            {
                if (--exceptionCount > 0)
                {
                    throw fakeException;
                }
                return(expected);
            };

            try
            {
                target.ExecuteAction(func);
            }
            catch (IOException x)
            {
                Assert.AreEqual(1, exceptionCount);
                Assert.AreEqual(fakeException, x);
                throw;
            }

            Assert.Fail("Expected exception");
        }
        public void TestAssetCreateFailedRetryMessageLengthLimitExceeded()
        {
            var expected = new AssetData {
                Name = "testData"
            };

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

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

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

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

            try
            {
                IAsset asset = _mediaContext.Assets.Create("Empty", "some storage", AssetCreationOptions.None);
            }
            catch (WebException x)
            {
                dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny <object>()), Times.Exactly(1));
                Assert.AreEqual(fakeException, x);
                throw;
            }

            Assert.Fail("Expected exception");
        }
        public void MediaRetryPolicyTestExecuteActionNonTransient()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy();

            int exceptionCount = 2;
            int expected = 10;
            var fakeException = new WebException("test", WebExceptionStatus.RequestCanceled);

            Func<int> func = () =>
            {
                if (--exceptionCount > 0) throw fakeException;
                return expected;
            };

            try
            {
                target.ExecuteAction(func);
            }
            catch (WebException x)
            {
                Assert.AreEqual(1, exceptionCount);
                Assert.AreEqual(fakeException, x);
                throw;
            }

            Assert.Fail("Expected exception");
        }
示例#4
0
        public void TestSendDeleteOperationRetry()
        {
            var data = new StreamingEndpointData {
                Name = "testData", Id = "1"
            };

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

            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 2, data);

            dataContextMock.Setup(ctxt => ctxt.AttachTo("StreamingEndpoints", data));
            dataContextMock.Setup(ctxt => ctxt.DeleteObject(data));

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

            data.SetMediaContext(_mediaContext);

            try
            {
                data.SendDeleteOperation();
            }
            catch (NotImplementedException x)
            {
                Assert.AreEqual(TestMediaDataServiceResponse.TestMediaDataServiceResponseExceptionMessage, x.Message);
            }

            dataContextMock.Verify(ctxt => ctxt.SaveChangesAsync(data), Times.Exactly(2));
        }
示例#5
0
        public void MediaRetryPolicyTestExecuteActionNonTransient()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy();

            int exceptionCount = 2;
            int expected       = 10;
            var fakeException  = new WebException("test", WebExceptionStatus.RequestCanceled);

            Func <int> func = () =>
            {
                if (--exceptionCount > 0)
                {
                    throw fakeException;
                }
                return(expected);
            };

            try
            {
                target.ExecuteAction(func);
            }
            catch (WebException x)
            {
                Assert.AreEqual(1, exceptionCount);
                Assert.AreEqual(fakeException, x);
                throw;
            }

            Assert.Fail("Expected exception");
        }
        public void MediaRetryPolicyTestExecuteActionBackoff()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy();

            int exceptionCount = 5;
            int expected = 10;
            var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);

            TimeSpan lastInterval = TimeSpan.Zero;
            DateTime lastInvoked = DateTime.UtcNow;

            Func<int> func = () =>
            {
                TimeSpan newInterval = DateTime.UtcNow - lastInvoked;
                TimeSpan delta = newInterval - lastInterval;
                Assert.IsTrue(exceptionCount > 3 || delta.TotalMilliseconds > 1, "Iterations left:{0} interval increase too small from {1} to {2}", exceptionCount, lastInterval, newInterval, delta);
                lastInvoked = DateTime.UtcNow;
                lastInterval = newInterval;
                if (--exceptionCount > 0) throw fakeException;
                return expected;
            };

            int actual = target.ExecuteAction(func);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(0, exceptionCount);
        }
示例#7
0
        public void MediaRetryPolicyTestExecuteAsyncNonTransient()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy();

            int exceptionCount = 2;
            int expected       = 10;
            var fakeException  = new WebException("test", WebExceptionStatus.RequestCanceled);

            Func <int> func = () =>
            {
                if (--exceptionCount > 0)
                {
                    throw fakeException;
                }
                return(expected);
            };

            try
            {
                var task = target.ExecuteAsync(() => Task.Factory.StartNew <int>(() => func()));
                task.Wait();
                var result = task.Result;
            }
            catch (AggregateException ax)
            {
                WebException x = (WebException)ax.Flatten().InnerException;
                Assert.AreEqual(1, exceptionCount);
                Assert.AreEqual(fakeException, x);
                throw x;
            }

            Assert.Fail("Expected exception");
        }
示例#8
0
        public void MediaRetryPolicyTestExecuteAsyncBackoff()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy();

            int exceptionCount = 5;
            int expected       = 10;
            var fakeException  = new WebException("test", WebExceptionStatus.ConnectionClosed);

            TimeSpan lastInterval = TimeSpan.Zero;
            DateTime lastInvoked  = DateTime.UtcNow;

            Func <int> func = () =>
            {
                TimeSpan newInterval = DateTime.UtcNow - lastInvoked;
                TimeSpan delta       = newInterval - lastInterval;
                Assert.IsTrue(exceptionCount > 3 || delta.TotalMilliseconds > 1, "Iterations left:{0} interval increase too small from {1} to {2}", exceptionCount, lastInterval, newInterval, delta);
                lastInvoked  = DateTime.UtcNow;
                lastInterval = newInterval;
                if (--exceptionCount > 0)
                {
                    throw fakeException;
                }
                return(expected);
            };

            var task = target.ExecuteAsync(() => Task.Factory.StartNew <int>(() => func()));

            Assert.AreEqual(expected, task.Result);
            Assert.AreEqual(0, exceptionCount);
        }
        public void TestNotificationEndPointCreateFailedRetryMessageLengthLimitExceeded()
        {
            var expected = new NotificationEndPoint { Name = "testData" };

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

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

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

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

            try
            {
                _mediaContext.NotificationEndPoints.Create("Empty", NotificationEndPointType.AzureQueue, "127.0.0.1");
            }
            catch (WebException x)
            {
                dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny<object>()), Times.Exactly(1));
                Assert.AreEqual(fakeException, x);
                throw;
            }

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

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

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

            try
            {
                _mediaContext.ContentKeyAuthorizationPolicies.CreateAsync(expected.Name).Wait();
            }
            catch (AggregateException ax)
            {
                dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny <object>()), Times.AtLeast(3));
                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 TestContentKeyAuthorizationPolicyOptionCreateFailedRetryMessageLengthLimitExceeded()
        {
            var expected = new ContentKeyAuthorizationPolicyOptionData {
                Name = "testData"
            };

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

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

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

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

            try
            {
                IContentKeyAuthorizationPolicyOption actual = _mediaContext.ContentKeyAuthorizationPolicyOptions.Create("Empty", ContentKeyDeliveryType.None, null, null);
            }
            catch (WebException x)
            {
                dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny <object>()), Times.Exactly(1));
                Assert.AreEqual(fakeException, x);
                throw;
            }

            Assert.Fail("Expected exception");
        }
示例#13
0
        public void TestAssetDeliveryPolicyCreateFailedRetryMessageLengthLimitExceeded()
        {
            var expected = new AssetDeliveryPolicyData {
                Name = "testData"
            };

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

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

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

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

            try
            {
                _mediaContext.AssetDeliveryPolicies.CreateAsync(expected.Name, AssetDeliveryPolicyType.None, AssetDeliveryProtocol.None, null).Wait();
            }
            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");
        }
示例#14
0
        public void MediaRetryPolicyTestExecuteAsyncTrivial()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(null);
            int expected            = 10;
            var task = target.ExecuteAsync(() => Task.Factory.StartNew <int>(() => expected));

            Assert.AreEqual(expected, task.Result);
        }
示例#15
0
        public void MediaRetryPolicyTestExecuteActionTrivial()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(null);
            int        expected     = 10;
            Func <int> func         = () => expected;
            int        actual       = target.ExecuteAction(func);

            Assert.AreEqual(expected, actual);
        }
        public void QueryRetrySimple()
        {
            MediaRetryPolicy queryRetryPolicy = new TestMediaServicesClassFactory(null).GetQueryRetryPolicy();

            var mock = new ThrowingQueryable();

            var target = new MediaQueryable <string, string>(mock, queryRetryPolicy);

            Assert.AreEqual(mock.Inner.First(), target.First());
        }
        public void TestNotificationEndPointCreateRetry()
        {
            var expected = new NotificationEndPoint { Name = "testData" };
            var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);
            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 2, expected);

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

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

            INotificationEndPoint actual = _mediaContext.NotificationEndPoints.Create("Empty", NotificationEndPointType.AzureQueue, "127.0.0.1");
            Assert.AreEqual(expected.Name, actual.Name);
            dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny<object>()), Times.Exactly(2));
        }
示例#18
0
        public void TestJobGetContentKeysRetry()
        {
            var data = new JobData {
                Name = "testData", Id = "testId"
            };

            var dataContextMock = TestMediaServicesClassFactory.CreateLoadPropertyMockConnectionClosed(2, data);

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

            data.SetMediaContext(_mediaContext);

            var actual = ((IJob)data).InputMediaAssets;

            dataContextMock.Verify((ctxt) => ctxt.LoadProperty(data, "InputMediaAssets"), Times.Exactly(2));
        }
示例#19
0
        public void TestContentKeyAuthorizationPolicyOptionCreateRetry()
        {
            var expected = new ContentKeyAuthorizationPolicyOptionData {
                Name = "testData"
            };
            var fakeException   = new WebException("test", WebExceptionStatus.ConnectionClosed);
            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 2, expected);

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

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

            IContentKeyAuthorizationPolicyOption actual = _mediaContext.ContentKeyAuthorizationPolicyOptions.Create("Empty", ContentKeyDeliveryType.None, null, null);

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

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

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

            IIngestManifest actual = _mediaContext.IngestManifests.CreateAsync(expected.Name, "some storage").Result;

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

            dataContextMock.Setup((ctxt) => ctxt.AttachTo("NotificationEndPoints", data));
            dataContextMock.Setup((ctxt) => ctxt.UpdateObject(data));

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

            data.SetMediaContext(_mediaContext);

            data.Update();

            dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(data), Times.Exactly(2));
        }
示例#22
0
        public void TestAssetCreateRetry()
        {
            var expected = new AssetData {
                Name = "testData"
            };
            var fakeException   = new WebException("test", WebExceptionStatus.ConnectionClosed);
            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 2, expected);

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

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

            IAsset asset = _mediaContext.Assets.Create("Empty", "some storage", AssetCreationOptions.None);

            Assert.AreEqual(expected.Name, asset.Name);
            dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny <object>()), Times.Exactly(2));
        }
        public void LinkCollectionTestRemoveRetry()
        {
            var data = new AssetData {
            };

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

            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 2, data);

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

            data.SetMediaContext(_mediaContext);

            var target = new LinkCollection <IAsset, AssetData>(dataContextMock.Object, data, "", new IAsset[] { data });

            target.RemoveAt(0);

            dataContextMock.Verify((ctxt) => ctxt.SaveChanges(), Times.Exactly(2));
        }
        public void MediaRetryPolicyTestExecuteActionAdapter()
        {
            var adapter = new TestRetryAdapter();
            MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(adapter);

            int exceptionCount = 2;
            int expected = 10;
            var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);

            Func<int> func = () =>
            {
                if (--exceptionCount > 0) throw fakeException;
                return expected;
            };

            Assert.AreEqual(expected, target.ExecuteAction(func));
            Assert.AreEqual(2, adapter.FuncExecutedCountByExecuteAction);
            Assert.AreEqual(1, adapter.NumberOfAdaptCalled);
        }
        public void TestStreamingEndpointCreateRetry()
        {
            var expected = new ChannelData { Name = "testData" };
            var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);
            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 2, expected);

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

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

            try
            {
                var actual = _mediaContext.StreamingEndpoints.Create("unittest", 0);
            }
            catch (NotImplementedException x)
            {
                Assert.AreEqual(TestMediaDataServiceResponse.TestMediaDataServiceResponseExceptionMessage, x.Message);
            }
            dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny<object>()), Times.Exactly(2));
        }
示例#26
0
        public void TestAssetDeliveryPolicyCreateRetry()
        {
            var expected = new AssetDeliveryPolicyData {
                Name = "testData"
            };
            var fakeException   = new WebException("test", WebExceptionStatus.ConnectionClosed);
            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 2, expected);

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

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

            var task = _mediaContext.AssetDeliveryPolicies.CreateAsync(expected.Name, AssetDeliveryPolicyType.None, AssetDeliveryProtocol.None, null);

            task.Wait();
            IAssetDeliveryPolicy actual = task.Result;

            Assert.AreEqual(expected.Name, actual.Name);
            dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny <object>()), Times.Exactly(2));
        }
        public void TestIngestManifestFileDeleteRetry()
        {
            var data = new IngestManifestAssetData {
            };

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

            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 2, data);

            dataContextMock.Setup((ctxt) => ctxt.AttachTo("IngestManifestAssets", data));
            dataContextMock.Setup((ctxt) => ctxt.DeleteObject(data));

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

            data.SetMediaContext(_mediaContext);

            data.Delete();

            dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(data), Times.Exactly(2));
        }
示例#28
0
        public void MediaRetryPolicyTestExecuteActionRetry()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(null);

            int exceptionCount = 2;
            int expected       = 10;
            var fakeException  = new WebException("test", WebExceptionStatus.ConnectionClosed);

            Func <int> func = () => {
                if (--exceptionCount > 0)
                {
                    throw fakeException;
                }
                return(expected);
            };

            int actual = target.ExecuteAction(func);

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(0, exceptionCount);
        }
示例#29
0
        public void TestRestEntityDeleteRetry()
        {
            RestEntity <ProgramData> data = new ProgramData {
                Name = "testData", Id = "1"
            };

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

            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 2, data);

            dataContextMock.Setup((ctxt) => ctxt.AttachTo("Origins", data));
            dataContextMock.Setup((ctxt) => ctxt.DeleteObject(data));

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

            data.SetMediaContext(_mediaContext);

            data.Delete();

            dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(data), Times.Exactly(2));
        }
示例#30
0
        public void TestProgramCreateRetryAsyn()
        {
            var expected = new ProgramData {
                Name = "testData"
            };
            var fakeException   = new WebException("test", WebExceptionStatus.ConnectionClosed);
            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 2, expected);

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

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

            IChannel channel = new ChannelData();
            ProgramBaseCollection programs = new ProgramBaseCollection(_mediaContext, channel);

            var actual = programs.Create(expected.Name, TimeSpan.FromHours(1), Guid.NewGuid().ToString());

            Assert.AreEqual(expected.Name, actual.Name);

            dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny <object>()), Times.Exactly(2));
        }
        public void TestAssetDeleteRetryWithKeepAzureContainerOption()
        {
            var data = new AssetData {
                Name = "testData"
            };

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

            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 2, data);

            dataContextMock.Setup((ctxt) => ctxt.AttachTo("Assets", data));
            dataContextMock.Setup((ctxt) => ctxt.DeleteObject(data));

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

            data.SetMediaContext(_mediaContext);

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

            dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(data), Times.Exactly(2));
        }
        public void TestContentKeyAuthorizationPolicyDeleteRetry()
        {
            var data = new ContentKeyAuthorizationPolicyData {
                Name = "testData"
            };

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

            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 2, data);

            dataContextMock.Setup((ctxt) => ctxt.AttachTo("ContentKeyAuthorizationPolicies", data));
            dataContextMock.Setup((ctxt) => ctxt.DeleteObject(data));

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

            data.SetMediaContext(_mediaContext);

            data.Delete();

            dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(data), Times.Exactly(2));
        }
示例#33
0
        public void MediaRetryPolicyTestExecuteAsyncRetry()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(null);

            int exceptionCount = 2;
            int expected       = 10;
            var fakeException  = new WebException("test", WebExceptionStatus.ConnectionClosed);

            Func <int> func = () =>
            {
                if (--exceptionCount > 0)
                {
                    throw fakeException;
                }
                return(expected);
            };

            var task = target.ExecuteAsync(() => Task.Factory.StartNew <int>(() => func()));

            Assert.AreEqual(expected, task.Result);
            Assert.AreEqual(0, exceptionCount);
        }
        public void MediaRetryPolicyTestExecuteAsyncRetryHasBeenAdaptedOnce()
        {
            var adapter = new TestRetryAdapter();
            MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(adapter);

            int exceptionCount = 2;
            int expected = 10;
            var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);

            Func<int> func = () =>
            {
                if (--exceptionCount > 0) throw fakeException;
                return expected;
            };

            var task = target.ExecuteAsync(() => Task.Factory.StartNew<int>(() => func()));
            Assert.AreEqual(expected, task.Result);
            Assert.AreEqual(0, exceptionCount);
            Assert.AreEqual(1, adapter.NumberOfAdaptCalled);
            Assert.AreEqual(2, adapter.FuncExecutedCountByExecuteAsync1);
        }
        public void DefaultMediaRetryPolicyTestExecuteActionNonTransient()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(null);

            int exceptionCount = 2;
            int expected = 10;
            //IOException should not be retried when using default TestMediaServicesClassFactory instead of
            //CustomTestMediaServicesClassFactory
            var fakeException = new IOException("CustomRetryPolicyException");

            Func<int> func = () =>
            {
                if (--exceptionCount > 0) throw fakeException;
                return expected;
            };

            try
            {
                target.ExecuteAction(func);
            }
            catch (IOException x)
            {
                Assert.AreEqual(1, exceptionCount);
                Assert.AreEqual(fakeException, x);
                throw;
            }

            Assert.Fail("Expected exception");
        }
        public void MediaRetryPolicyTestExecuteActionRetry()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy();

            int exceptionCount = 2;
            int expected = 10;
            var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);

            Func<int> func = () => {
                    if (--exceptionCount > 0) throw fakeException;
                    return expected;
                };

            int actual = target.ExecuteAction(func);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(0, exceptionCount);
        }
 public void MediaRetryPolicyTestExecuteActionTrivial()
 {
     MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy();
     int expected = 10;
     Func<int> func = () => expected;
     int actual = target.ExecuteAction(func);
     Assert.AreEqual(expected, actual);
 }
        public void MediaRetryPolicyTestExecuteAsyncNonTransient()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy();

            int exceptionCount = 2;
            int expected = 10;
            var fakeException = new WebException("test", WebExceptionStatus.RequestCanceled);

            Func<int> func = () =>
            {
                if (--exceptionCount > 0) throw fakeException;
                return expected;
            };

            try
            {
                var task = target.ExecuteAsync(() => Task.Factory.StartNew<int>(() => func()));
                task.Wait();
                var result = task.Result;
            }
            catch (AggregateException ax)
            {
                WebException x = (WebException)ax.Flatten().InnerException;
                Assert.AreEqual(1, exceptionCount);
                Assert.AreEqual(fakeException, x);
                throw x;
            }

            Assert.Fail("Expected exception");
        }
 public void MediaRetryPolicyTestExecuteAsyncTrivial()
 {
     MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy();
     int expected = 10;
     var task = target.ExecuteAsync(() => Task.Factory.StartNew<int>(() => expected));
     Assert.AreEqual(expected, task.Result);
 }
        public void MediaRetryPolicyTestExecuteAsyncRetry()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy();

            int exceptionCount = 2;
            int expected = 10;
            var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);

            Func<int> func = () =>
            {
                if (--exceptionCount > 0) throw fakeException;
                return expected;
            };

            var task = target.ExecuteAsync(() => Task.Factory.StartNew<int>(() => func()));
            Assert.AreEqual(expected, task.Result);
            Assert.AreEqual(0, exceptionCount);
        }