Beispiel #1
0
        public void DeleteUnsavedTemplate()
        {
            var data = new JobTemplateData {
            };

            data.Delete();
        }
Beispiel #2
0
        public void DeleteTemplate()
        {
            var dataContextMock = new Mock <IMediaDataServiceContext>();

            var fakeResponse = new string[] { "" };

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

            var data = new JobTemplateData
            {
                JobTemplateBodyCopied = "taskTemplateId=\"nb:ttid:UUID:1\"",
                Name          = Guid.NewGuid().ToString(),
                Id            = "1",
                TaskTemplates = new List <TaskTemplateData>
                {
                    new TaskTemplateData {
                    }
                },
            };

            dataContextMock.Setup((ctxt) => ctxt
                                  .SaveChangesAsync(data))
            .Returns(() => Task.Factory.StartNew <IMediaDataServiceResponse>((d) =>
            {
                return(null);
            }, data));

            data.SetMediaContext(_mediaContext);

            data.Delete();

            dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(data), Times.Once);
        }
Beispiel #3
0
        public void SaveSavedTemplate()
        {
            var data = new JobTemplateData {
                Id = "1"
            };

            data.Save();
        }
Beispiel #4
0
        public void JobTemplateTestSaveAsyncRetry()
        {
            JobTemplateData data = new JobTemplateData {
                JobTemplateBodyCopied = ""
            };

            var fakeResponse = new TestMediaDataServiceResponse {
                AsyncState = data
            };
            var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);

            var dataContextMock = new Mock <IMediaDataServiceContext>();

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

            int saveChangesExceptionCount = 2;

            dataContextMock.Setup((ctxt) => ctxt
                                  .SaveChangesAsync(SaveChangesOptions.Batch, data))
            .Returns(() => Task.Factory.StartNew <IMediaDataServiceResponse>(() =>
            {
                if (--saveChangesExceptionCount > 0)
                {
                    throw fakeException;
                }
                return(fakeResponse);
            }));

            int loadPropertiesExceptionCount = 2;

            dataContextMock.Setup((ctxt) => ctxt
                                  .LoadProperty(data, It.IsAny <string>()))
            .Returns(() =>
            {
                if (--loadPropertiesExceptionCount > 0)
                {
                    throw fakeException;
                }
                return(null);
            });

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

            data.SetMediaContext(_mediaContext);

            data.SaveAsync().Wait();

            dataContextMock.Verify((ctxt) => ctxt.LoadProperty(data, "TaskTemplates"), Times.Exactly(2));
            Assert.AreEqual(0, saveChangesExceptionCount);
            Assert.AreEqual(0, loadPropertiesExceptionCount);
        }
Beispiel #5
0
        public void TemplateType()
        {
            var data = new JobTemplateData
            {
                TemplateType = (int)JobTemplateType.AccountLevel
            };

            IJobTemplate iData = (IJobTemplate)data;

            Assert.AreEqual(JobTemplateType.AccountLevel, iData.TemplateType);

            iData.TemplateType = JobTemplateType.SystemLevel;

            Assert.AreEqual((int)JobTemplateType.SystemLevel, data.TemplateType);
        }
        public void CopyTemplate()
        {
            var data = new JobTemplateData
            {
                JobTemplateBodyCopied = "taskTemplateId=\"nb:ttid:UUID:1\"",
                Name = Guid.NewGuid().ToString(),
                TaskTemplates = new List<TaskTemplateData>
                 {
                     new TaskTemplateData {}
                 },
            };
            data.SetMediaContext(_mediaContext);
            var copy = data.Copy();

            Assert.AreEqual(data.Name, copy.Name);
        }
Beispiel #7
0
        public QueryOperationResponse LoadProperty(object entity, string propertyName)
        {
            //Example of Load property simulation
            if (entity is AssetData)
            {
                AssetData assetData = (AssetData)(entity);
                switch (propertyName)
                {
                case "Locators":
                    assetData.Locators = new List <LocatorData>(CreateQuery <LocatorData>("Locators").Where(c => c.AssetId == c.AssetId).ToList());
                    break;

                default: break;
                }
            }
            if (entity is LocatorData)
            {
                LocatorData data = (LocatorData)(entity);
                switch (propertyName)
                {
                case "Asset":
                    data.Asset = CreateQuery <AssetData>("Assets").Where(c => c.Id == data.AssetId).FirstOrDefault();
                    break;

                case "AccessPolicy":
                    data.AccessPolicy = CreateQuery <AccessPolicyData>(AccessPolicyBaseCollection.AccessPolicySet).Where(c => c.Id == data.AccessPolicyId).FirstOrDefault();
                    break;

                default: break;
                }
            }
            if (entity is JobTemplateData)
            {
                JobTemplateData data = (JobTemplateData)(entity);
                switch (propertyName)
                {
                case "TaskTemplates":
                    data.TaskTemplates = CreateQuery <TaskTemplateData>("TaskTemplates").ToList();
                    break;

                default: break;
                }
            }
            return(null);
        }
Beispiel #8
0
        public void CopyTemplate()
        {
            var data = new JobTemplateData
            {
                JobTemplateBodyCopied = "taskTemplateId=\"nb:ttid:UUID:1\"",
                Name          = Guid.NewGuid().ToString(),
                TaskTemplates = new List <TaskTemplateData>
                {
                    new TaskTemplateData {
                    }
                },
            };

            data.SetMediaContext(_mediaContext);
            var copy = data.Copy();

            Assert.AreEqual(data.Name, copy.Name);
        }
Beispiel #9
0
        public void SaveTemplate()
        {
            var data = new JobTemplateData
            {
                JobTemplateBodyCopied = "taskTemplateId=\"nb:ttid:UUID:1\"",
                TaskTemplates         = new List <TaskTemplateData>
                {
                    new TaskTemplateData {
                    }
                }
            };

            data.SetMediaContext(_mediaContext);
            data.Save();

            var newTaskTemplateId = data.TaskTemplates.Single().Id.Substring("nb:ttid:UUID:".Length);

            Guid.Parse(newTaskTemplateId);
        }
Beispiel #10
0
        public void JobTemplateTestDeleteRetry()
        {
            JobTemplateData data = new JobTemplateData {
                JobTemplateBodyCopied = "", Id = "fakeId"
            };

            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));
        }
        public void DeleteTemplate()
        {
            var dataContextMock = new Mock<IMediaDataServiceContext>();

            var fakeResponse = new string[] { "" };

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

            var data = new JobTemplateData
            {
                JobTemplateBodyCopied = "taskTemplateId=\"nb:ttid:UUID:1\"",
                Name = Guid.NewGuid().ToString(),
                Id = "1",
                TaskTemplates = new List<TaskTemplateData>
                 {
                     new TaskTemplateData {}
                 },
            };

            dataContextMock.Setup((ctxt) => ctxt
                .SaveChangesAsync(data))
                .Returns(() => Task.Factory.StartNew<IMediaDataServiceResponse>((d) =>
                {
                    return null;
                }, data));

            data.SetMediaContext(_mediaContext);

            data.Delete();

            dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(data), Times.Once);
        }
        public void TemplateType()
        {
            var data = new JobTemplateData
            {
                TemplateType = (int)JobTemplateType.AccountLevel
            };

            IJobTemplate iData = (IJobTemplate)data;

            Assert.AreEqual(JobTemplateType.AccountLevel, iData.TemplateType);

            iData.TemplateType = JobTemplateType.SystemLevel;

            Assert.AreEqual((int)JobTemplateType.SystemLevel, data.TemplateType);
        }
        public void SaveTemplate()
        {
            var data = new JobTemplateData
            {
                JobTemplateBodyCopied = "taskTemplateId=\"nb:ttid:UUID:1\"",
                TaskTemplates = new List<TaskTemplateData>
                 {
                     new TaskTemplateData {}
                 }
            };
            data.SetMediaContext(_mediaContext);
            data.Save();

            var newTaskTemplateId = data.TaskTemplates.Single().Id.Substring("nb:ttid:UUID:".Length);
            Guid.Parse(newTaskTemplateId);
        }
 public void SaveSavedTemplate()
 {
     var data = new JobTemplateData { Id = "1" };
     data.Save();
 }
        public void JobTemplateTestSaveAsyncRetry()
        {
            JobTemplateData data = new JobTemplateData { JobTemplateBodyCopied = "" };

            var fakeResponse = new TestMediaDataServiceResponse { AsyncState = data };
            var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);

            var dataContextMock = new Mock<IMediaDataServiceContext>();

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

            int saveChangesExceptionCount = 2;

            dataContextMock.Setup((ctxt) => ctxt
                .SaveChangesAsync(SaveChangesOptions.Batch, data))
                .Returns(() => Task.Factory.StartNew<IMediaDataServiceResponse>(() =>
                {
                    if (--saveChangesExceptionCount > 0) throw fakeException;
                    return fakeResponse;
                }));

            int loadPropertiesExceptionCount = 2;
            dataContextMock.Setup((ctxt) => ctxt
                .LoadProperty(data, It.IsAny<string>()))
                .Returns(() =>
                {
                    if (--loadPropertiesExceptionCount > 0) throw fakeException;
                    return null;
                });

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

            data.SetMediaContext(_mediaContext);

            data.SaveAsync().Wait();

            dataContextMock.Verify((ctxt) => ctxt.LoadProperty(data, "TaskTemplates"), Times.Exactly(2));
            Assert.AreEqual(0, saveChangesExceptionCount);
            Assert.AreEqual(0, loadPropertiesExceptionCount);
        }
        public void JobTemplateTestDeleteRetry()
        {
            JobTemplateData data = new JobTemplateData { JobTemplateBodyCopied = "", Id = "fakeId" };

            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));
        }
 public void DeleteUnsavedTemplate()
 {
     var data = new JobTemplateData { };
     data.Delete();
 }