Exemplo n.º 1
0
        public void TestExecute()
        {
            var scheduler = new SimpleTestScheduler();

            const int executorsCount = 5;
            var       processors     = new DebugProcessor[executorsCount];

            for (int i = 0; i < processors.Length; i++)
            {
                processors[i] = new DebugProcessor(new MockDataProcessor());
            }

            CheckExecutionCount(0, processors);

            scheduler.Builder.Append(new SourceSplitter(processors));
            scheduler.Start();

            scheduler.ExecuteBlocking(new MockFileSource());

            CheckExecutionCount(1, processors);

            scheduler.ExecuteBlocking(new MockFileSource());

            CheckExecutionCount(2, processors);
        }
Exemplo n.º 2
0
        public void TestRename(string directory, string newFileName, string additionalFolders)
        {
            var  scheduler  = new SimpleTestScheduler();
            var  source     = new TempFileSource();
            long sourceSize = source.FileInfo.Length;

            string destinationPath = newFileName;
            string rootFolderPath  = source.Path;

            if (directory != null)
            {
                destinationPath = Path.Combine(
                    additionalFolders == null ? directory : Path.Combine(directory, additionalFolders),
                    destinationPath);
                rootFolderPath = Path.Combine(rootFolderPath, directory);
            }

            string fullDestinationPath = Path.Combine(source.Path, destinationPath);

            Assert.IsFalse(File.Exists(destinationPath));

            scheduler.Builder.Append(new SourceRenamer(f => destinationPath));
            scheduler.Start();

            scheduler.ExecuteBlocking(source);

            Assert.IsTrue(File.Exists(fullDestinationPath));
            Assert.AreEqual(sourceSize, new FileInfo(fullDestinationPath).Length);

            File.Delete(fullDestinationPath);
            if (directory != null)
            {
                Directory.Delete(rootFolderPath, true);
            }
        }
        private static void TestEval(Func <IFileSource, bool> evalFunc, bool useSourceB = false)
        {
            var scheduler = new SimpleTestScheduler();
            int execCount = 0;

            scheduler.Scheduler.Executor.LifeCycleEvent += Executed;

            scheduler.Builder.Append(useSourceB
                                ? new ConditionalProcessor(evalFunc, null, new MockDataProcessor())
                                : new ConditionalProcessor(evalFunc, new MockDataProcessor(), null));

            scheduler.Start();

            scheduler.ExecuteBlocking(new MockFileSource());

            Assert.AreEqual(1, execCount);

            void Executed(object sender, ExecutorLifeCycleEventArgs args)
            {
                if (args.EventType == ExecutorLifeCycleEventType.SourceExecutionFinished)
                {
                    execCount++;
                }
            }
        }
Exemplo n.º 4
0
        private static SimpleTestScheduler InitVars(out IFileSource source, out string newFolderPath)
        {
            var scheduler = new SimpleTestScheduler();

            source = new TempFileSource();

            newFolderPath = Path.Combine(Path.GetTempPath(), ".clone");

            return(scheduler);
        }
Exemplo n.º 5
0
        private static SimpleTestScheduler PrepareMove(out TempFileSource source, out long sourceSize,
                                                       out string destinationPath)
        {
            var scheduler = new SimpleTestScheduler();

            source     = new TempFileSource();
            sourceSize = source.FileInfo.Length;

            destinationPath = Path.Combine(Path.GetTempPath(), ".subfolder");
            return(scheduler);
        }
Exemplo n.º 6
0
        private static void TestFileMovement(string destinationFile, SimpleTestScheduler scheduler, IFileSource source,
                                             long sourceSize, string destinationPath)
        {
            Assert.AreEqual(false, File.Exists(destinationFile));

            scheduler.ExecuteBlocking(source);

            Assert.IsTrue(File.Exists(destinationFile));
            Assert.AreEqual(sourceSize, new FileInfo(destinationFile).Length);

            Directory.Delete(destinationPath, true);
        }
Exemplo n.º 7
0
        private static void TestBasicClone(IFileSource source, string newFilePath, SimpleTestScheduler scheduler,
                                           string newFolderPath)
        {
            Assert.AreEqual(true, File.Exists(source.FileInfo.FullName));
            Assert.AreEqual(false, File.Exists(newFilePath));

            scheduler.ExecuteBlocking(source);

            Assert.AreEqual(true, File.Exists(source.FileInfo.FullName));
            Assert.AreEqual(true, File.Exists(newFilePath));

            Directory.Delete(newFolderPath, true);
        }
Exemplo n.º 8
0
        public void TestDeleteSource()
        {
            var scheduler = new SimpleTestScheduler();
            var source    = new TempFileSource();

            scheduler.Builder.Append(new SourceDeleter());

            Assert.AreEqual(true, File.Exists(source.FileInfo.FullName));

            scheduler.Execute(source);

            Assert.AreEqual(false, File.Exists(source.FileInfo.FullName));
        }
Exemplo n.º 9
0
 private static void AppendDeleteAndExecute(SimpleTestScheduler scheduler, IFileSource source)
 {
     scheduler.Builder.Append(new SourceDeleter());
     scheduler.ExecuteBlocking(source);
 }