コード例 #1
0
        public void TestAccessPolicyCreateRetry()
        {
            var dataContextMock = new Mock <IMediaDataServiceContext>();

            int exceptionCount = 2;

            var expected = new AccessPolicyData {
                Name = "testData"
            };
            var fakeResponse = new TestMediaDataServiceResponse {
                AsyncState = expected
            };
            var fakeException = new WebException("testException", WebExceptionStatus.ConnectionClosed);

            dataContextMock.Setup((ctxt) => ctxt.AddObject("AccessPolicies", It.IsAny <object>()));
            dataContextMock.Setup((ctxt) => ctxt
                                  .SaveChangesAsync(It.IsAny <object>()))
            .Returns(() => Task.Factory.StartNew <IMediaDataServiceResponse>(() =>
            {
                if (--exceptionCount > 0)
                {
                    throw fakeException;
                }
                return(fakeResponse);
            }));

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

            IAccessPolicy policy = _mediaContext.AccessPolicies.Create("Empty", TimeSpan.FromSeconds(1), AccessPermissions.None);

            Assert.AreEqual(expected.Name, policy.Name);
            Assert.AreEqual(0, exceptionCount);
        }
コード例 #2
0
        public void TestAccessPolicyDeleteRetry()
        {
            var dataContextMock = new Mock <IMediaDataServiceContext>();

            int exceptionCount = 2;

            var policy = new AccessPolicyData {
                Name = "testData"
            };
            var fakeResponse = new TestMediaDataServiceResponse {
                AsyncState = policy
            };
            var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);

            dataContextMock.Setup((ctxt) => ctxt.AttachTo("Files", policy));
            dataContextMock.Setup((ctxt) => ctxt.DeleteObject(policy));

            dataContextMock.Setup((ctxt) => ctxt
                                  .SaveChangesAsync(policy))
            .Returns(() => Task.Factory.StartNew <IMediaDataServiceResponse>(() =>
            {
                if (--exceptionCount > 0)
                {
                    throw fakeException;
                }
                return(fakeResponse);
            }));

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

            policy.SetMediaContext(_mediaContext);

            policy.Delete();

            Assert.AreEqual(0, exceptionCount);
        }
コード例 #3
0
        public void TestAccessPolicyDeleteRetry()
        {
            var dataContextMock = new Mock<IMediaDataServiceContext>();

            int exceptionCount = 2;

            var policy = new AccessPolicyData { Name = "testData" };
            var fakeResponse = new TestMediaDataServiceResponse { AsyncState = policy };
            var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);

            dataContextMock.Setup((ctxt) => ctxt.AttachTo("Files", policy));
            dataContextMock.Setup((ctxt) => ctxt.DeleteObject(policy));

            dataContextMock.Setup((ctxt) => ctxt
                .SaveChangesAsync(policy))
                .Returns(() => Task.Factory.StartNew<IMediaDataServiceResponse>(() =>
                {
                    if (--exceptionCount > 0) throw fakeException;
                    return fakeResponse;
                }));

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

            policy.SetMediaContext(_mediaContext);

            policy.Delete();

            Assert.AreEqual(0, exceptionCount);
        }
コード例 #4
0
        public void TestAccessPolicyCreateRetry()
        {
            var dataContextMock = new Mock<IMediaDataServiceContext>();

            int exceptionCount = 2;

            var expected = new AccessPolicyData { Name = "testData" };
            var fakeResponse = new TestMediaDataServiceResponse { AsyncState = expected };
            var fakeException = new WebException("testException", WebExceptionStatus.ConnectionClosed);

            dataContextMock.Setup((ctxt) => ctxt.AddObject("AccessPolicies", It.IsAny<object>()));
            dataContextMock.Setup((ctxt) => ctxt
                .SaveChangesAsync(It.IsAny<object>()))
                .Returns(() => Task.Factory.StartNew<IMediaDataServiceResponse>(() =>
                {
                    if (--exceptionCount > 0) throw fakeException;
                    return fakeResponse;
                }));

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

            IAccessPolicy policy = _mediaContext.AccessPolicies.Create("Empty", TimeSpan.FromSeconds(1), AccessPermissions.None);
            Assert.AreEqual(expected.Name, policy.Name);
            Assert.AreEqual(0, exceptionCount);
        }
コード例 #5
0
        public void InitilizeStubData()
        {
            string assetId = "nb:Id:" + Guid.NewGuid();

            StorageAccountData storageAccountData = new StorageAccountData
            {
                IsDefault = true,
                Name      = "test storage",
            };

            _persistedChanges.Add(StorageAccountBaseCollection.EntitySet,
                                  new List <StorageAccountData>
            {
                storageAccountData
            });

            AssetData assetData = new AssetData()
            {
                Id           = assetId,
                AlternateId  = String.Empty,
                Created      = DateTime.UtcNow,
                LastModified = DateTime.UtcNow,
                Name         = "Mock Asset",
                Options      = (int)AssetCreationOptions.None,
            };

            assetData.SetMediaContext(_mediaContextBase);
            _persistedChanges.Add(AssetCollection.AssetSet,
                                  new List <AssetData>
            {
                assetData
            });
            string accessPolicyId = Guid.NewGuid().ToString();

            AccessPolicyData accessPolicyData = new AccessPolicyData()
            {
                Id                = accessPolicyId,
                Name              = "Mock AccessPolicy",
                Created           = DateTime.UtcNow.AddDays(-1),
                DurationInMinutes = 10000,
                LastModified      = DateTime.UtcNow,
                Permissions       = (int)AccessPermissions.Read
            };

            accessPolicyData.SetMediaContext(_mediaContextBase);
            _persistedChanges.Add(AccessPolicyBaseCollection.AccessPolicySet,
                                  new List <AccessPolicyData>
            {
                accessPolicyData
            });

            LocatorData locatorData = new LocatorData()
            {
                Id             = Guid.NewGuid().ToString(),
                AssetId        = assetId,
                Name           = "Mock locator",
                AccessPolicyId = accessPolicyId,
                BaseUri        = "http://"
            };

            locatorData.SetMediaContext(_mediaContextBase);
            _persistedChanges.Add(LocatorBaseCollection.LocatorSet,
                                  new List <LocatorData>
            {
                locatorData
            });

            _persistedChanges.Add(AssetFileCollection.FileSet,
                                  new List <AssetFileData>
            {
                new AssetFileData()
                {
                    Id            = Guid.NewGuid().ToString(),
                    Created       = DateTime.UtcNow,
                    Name          = "Mock File",
                    ParentAssetId = assetId
                }
            });

            _persistedChanges.Add(MediaProcessorBaseCollection.MediaProcessorSet,
                                  new List <MediaProcessorData>
            {
                new MediaProcessorData()
                {
                    Id      = Guid.NewGuid().ToString(),
                    Name    = "Mock Processor",
                    Version = "1",
                    Vendor  = "mock"
                }
            });

            _persistedChanges.Add(JobBaseCollection.JobSet,
                                  new List <JobData>
            {
                new JobData()
                {
                    Id   = Guid.NewGuid().ToString(),
                    Name = "Mock Job",
                }
            });
        }