예제 #1
0
        public void PlannerUsesRenamePluginIfDestinationEssenceFilenameIsPresent()
        {
            var wfsPluginMock = CreateWfsMock("1");

            wfsPluginMock.SetupGet(p => p.Busy).Returns(false);
            wfsPluginMock.Setup(p => p.CheckAndEstimate(It.IsAny <ExecutionTask>())).Returns(true);
            var fileRenamerPluginMock = CreateFileRenamerMock("1");

            fileRenamerPluginMock.SetupGet(p => p.Busy).Returns(false);
            fileRenamerPluginMock.Setup(p => p.CheckAndEstimate(It.IsAny <ExecutionTask>())).Returns(true);

            var planner = new SimplePlanner(new List <IPlugin> {
                wfsPluginMock.Object, fileRenamerPluginMock.Object
            }, JobRepository, Logging, _callBackService.Object);
            var job = CreateNewWfsJob();

            job.Destination.Files = new List <EssenceFile> {
                EssenceFile.Template("NewName_%index%.%ext%")
            };
            var jobUrn = job.Urn;

            JobRepository.Add(job);
            planner.Calculate();
            Assert.That(JobRepository.Get(jobUrn).Plan.Tasks.Count, Is.EqualTo(2));
            Assert.That(JobRepository.Get(jobUrn).Plan.Tasks[1].PluginUrn, Is.EqualTo(fileRenamerPluginMock.Object.Urn));
        }
예제 #2
0
        public void DoWorkMapsToCorrectDestinationFileNames()
        {
            string path = TestRoot;

            Directory.CreateDirectory(path);
            string name1    = "RenamerTestFile1.mov";
            string name2    = "RenamerTestFile2.mov";
            var    tempFile = File.Create(Path.Combine(path, name1));

            tempFile.Close();
            var tempFile2 = File.Create(Path.Combine(path, name2));

            tempFile2.Close();
            var targetName1 = "name_1.mov";
            var targetName2 = "name_2.mov";
            var targetPath1 = Path.Combine(path, "name_1.mov");
            var targetPath2 = Path.Combine(path, "name_2.mov");

            if (File.Exists(targetPath1))
            {
                File.Delete(targetPath1);
            }
            if (File.Exists(targetPath2))
            {
                File.Delete(targetPath2);
            }

            var et = new ExecutionTask
            {
                To = new Essence {
                    Files = new List <EssenceFile>()
                },
                From = new Essence {
                    Files = new List <EssenceFile>()
                }
            };

            et.To.Files.Add(EssenceFile.Template("name_%index%.%ext%"));
            et.To.Path = path;
            et.From.Files.Add(name1);
            et.From.Files.Add(name2);
            et.From.Path = path;

            sut.Assign(et);
            sut.Pulse(et);

            Assert.That(et.To.Files[0].Value, Is.EqualTo(targetName1));
            Assert.That(et.To.Files[1].Value, Is.EqualTo(targetName2));

            File.Delete(targetPath1);
            File.Delete(targetPath2);
        }
예제 #3
0
 private static IList <EssenceFile> ConvertDestinationFilenameToEssenceFile(string destinationFilename)
 {
     if (string.IsNullOrEmpty(destinationFilename))
     {
         return(null);
     }
     return(new List <EssenceFile> {
         EssenceFile.Template(
             destinationFilename.Contains('%') ?
             destinationFilename :
             $"{destinationFilename}_%index%.%ext%")
     });
 }
예제 #4
0
        public void CheckAndEstimateSetsTaskEstimationToFiveSeconds()
        {
            var et = new ExecutionTask
            {
                To = new Essence {
                    Files = new List <EssenceFile>()
                }
            };

            et.To.Files.Add(EssenceFile.Template("FileName.%ext%"));
            sut.CheckAndEstimate(et);

            Assert.That(et.Estimation, Is.EqualTo(TimeSpan.FromSeconds(5)));
        }
예제 #5
0
        public void CheckAndEstimateReturnsCorrectBoolValue(int destinationFilesCount, string fileTemplate, bool expectedResult)
        {
            var et = new ExecutionTask
            {
                To = new Essence {
                    Files = new List <EssenceFile>()
                }
            };

            for (var i = 0; i < destinationFilesCount; i++)
            {
                et.To.Files.Add(EssenceFile.Template(fileTemplate + i));
            }

            Assert.That(sut.CheckAndEstimate(et), Is.EqualTo(expectedResult));
        }
예제 #6
0
        public void DoWorkSetsStateCorrect()
        {
            string path = TestRoot;

            Directory.CreateDirectory(path);
            string name     = "RenamerTestFile.mov";
            var    tempPath = Path.Combine(path, name);
            var    tempFile = File.Create(tempPath);

            tempFile.Close();

            var et = new ExecutionTask
            {
                To = new Essence {
                    Files = new List <EssenceFile>()
                },
                From = new Essence {
                    Files = new List <EssenceFile>()
                }
            };

            et.To.Files.Add(EssenceFile.Template("name_%index%.%ext%"));
            et.To.Path = path;
            et.From.Files.Add("RenamerTestFile.mov");
            et.From.Path = path;
            var targetPath1 = Path.Combine(path, "name_1.mov");

            if (File.Exists(targetPath1))
            {
                File.Delete(targetPath1);
            }

            sut.Assign(et);
            sut.Pulse(et);

            Assert.That(sut.GetStatus().CurrentTask.State, Is.EqualTo(ExecutionState.Done));

            sut.Pulse(et);

            // Do work sets state to failed if file target exists
            Assert.That(et.State, Is.EqualTo(ExecutionState.Failed));

            File.Delete(tempPath);
            File.Delete(targetPath1);
        }