Esempio n. 1
0
        public void UploadsFile()
        {
            var subDirectorPath = Path.Combine(_testDirectory, _subDirectoryName);

            if (!Directory.Exists(subDirectorPath))
            {
                Directory.CreateDirectory(subDirectorPath);
            }

            File.WriteAllText(Path.Combine(_testDirectory, _subDirectoryName, _subFileName),
                              _contents);

            var sourceDirectory = new LocalDirectoryObject(_testDirectory);

            var targetDirectory = new MemoryDirectoryObject("dir");

            var syncNet = new Processor(sourceDirectory, targetDirectory, new SyncTaskQueue());

            syncNet.CopyFile(
                new LocalFileObject(sourceDirectory.FullName + "\\" + _subDirectoryName + "\\" + _subFileName));

            var subDirectory = targetDirectory.GetDirectories().First();

            Assert.AreEqual(_subDirectoryName, subDirectory.Name);

            var fileObject = subDirectory.GetFiles().First();

            Assert.AreEqual(_subFileName, fileObject.Name);
            using (var sr = new StreamReader(fileObject.GetStream()))
            {
                Assert.AreEqual(_contents, sr.ReadToEnd().Replace("\0", string.Empty));
            }
        }
        public void Initialize()
        {
            var memoryDirectoryObject = DirectoryHelper.CreateFullDirectory();

            _sourceDirectory = memoryDirectoryObject;

            _targetDirectory = new MemoryDirectoryObject("targetDirectory");

            _syncNet = new Processor(_sourceDirectory, _targetDirectory, new SyncTaskQueue());
        }
Esempio n. 3
0
        public void ThrowsWhenFileIsLocked()
        {
            var file            = new MemoryFileObject("name", "contents");
            var targetDirectory = new MemoryDirectoryObject("target");

            file.IsReady = false;
            file.Exists  = true;

            var copyFile = new CopyFileTask(file,
                                            targetDirectory, new TimeSpan(0, 0, 1));

            copyFile.Execute();
        }
Esempio n. 4
0
        public void CreatesTargetFile()
        {
            IDirectoryObject sourceDirectory = DirectoryHelper.CreateDirectoryWithFile();

            IDirectoryObject targetDirectory = new MemoryDirectoryObject("directory");
            var syncNet = new Processor(sourceDirectory, targetDirectory, new SyncTaskQueue());

            syncNet.ProcessSourceDirectory();

            var targetFile = targetDirectory.GetFile(DirectoryHelper.FileName);

            Assert.IsTrue(targetFile.Exists);
        }
Esempio n. 5
0
        public void CreatesSubDirectory()
        {
            var sourceDirectory = new MemoryDirectoryObject("directory")
                                  .AddDirectory(DirectoryHelper.SubDirectoryName);

            IDirectoryObject targetDirectory = new MemoryDirectoryObject("directory");
            var syncNet = new Processor(sourceDirectory, targetDirectory, new SyncTaskQueue());

            syncNet.ProcessSourceDirectory();

            var directoryObject = targetDirectory.GetDirectory(DirectoryHelper.SubDirectoryName);

            Assert.IsTrue(directoryObject.Exists);
        }
Esempio n. 6
0
        public void FiresProgressEvent()
        {
            IDirectoryObject sourceDirectory = DirectoryHelper.CreateDirectoryWithFile();

            IDirectoryObject targetDirectory = new MemoryDirectoryObject("directory");

            var syncNet = new Processor(sourceDirectory, targetDirectory, new SyncTaskQueue());


            var fired = false;

            syncNet.ProgressChanged += delegate { fired = true; };
            syncNet.ProcessSourceDirectory();

            Assert.IsTrue(fired);
        }
Esempio n. 7
0
        public void Init()
        {
            var amazonS3Client = new AmazonS3Client(RegionEndpoint.USEast1);

            _s3DirectoryInfo = new S3DirectoryInfo(amazonS3Client, _testDirectory);

            if (_s3DirectoryInfo.Exists)
            {
                _s3DirectoryInfo.Delete(true);
            }
            _s3DirectoryInfo.Create();

            _targetDirectory = new S3DirectoryObject(amazonS3Client, _testDirectory);

            _sourceObject = DirectoryHelper.CreateFullDirectory();
        }
Esempio n. 8
0
        public void WritesFileContentToTargetFile()
        {
            IDirectoryObject sourceDirectory = DirectoryHelper.CreateDirectoryWithFile();

            IDirectoryObject targetDirectory = new MemoryDirectoryObject("directory");
            var syncNet = new Processor(sourceDirectory, targetDirectory, new SyncTaskQueue());

            syncNet.ProcessSourceDirectory();

            var targetFile = targetDirectory.GetFile(DirectoryHelper.FileName);

            using (var sr = new StreamReader(targetFile.GetStream()))
            {
                var targetFileContents = sr.ReadToEnd().Replace("\0", string.Empty);
                Assert.AreEqual(DirectoryHelper.Contents, targetFileContents);
            }
        }
        public void ReturnsFilesNotInTargetDirectory()
        {
            var sourceDirectory = new MemoryDirectoryObject("directory")
                                  .AddFile(_fileName, _contents)
                                  .AddFile(_fileName2, _contents);

            sourceDirectory.AddDirectory(new MemoryDirectoryObject(_subDirectoryName, sourceDirectory.FullName)
                                         .AddFile(_subFileName, _contents)
                                         .AddFile(_subFileName2, _contents));

            IDirectoryObject targetDirectory = new MemoryDirectoryObject("directory");

            var scanner     = new DirectoryScanner(sourceDirectory, targetDirectory);
            var filesToCopy = scanner.GetFilesToCopy();

            Assert.AreEqual(4, filesToCopy.Count);
            Assert.IsTrue(filesToCopy.Any(x => x.Name == _fileName));
            Assert.IsTrue(filesToCopy.Any(x => x.Name == _fileName2));
            Assert.IsTrue(filesToCopy.Any(x => x.Name == _subFileName));
            Assert.IsTrue(filesToCopy.Any(x => x.Name == _subFileName2));
        }
Esempio n. 10
0
        public void RemovesFileFromQueueWhenDeleted()
        {
            var sourceDirectory = DirectoryHelper.CreateDirectoryWithFiles();

            var targetDirectory = new MemoryDirectoryObject("targetDirectory");

            var queue   = new ManualTaskQueue();
            var syncNet = new Processor(sourceDirectory, targetDirectory, queue);

            syncNet.ProcessSourceDirectory();

            var fileToDelete = sourceDirectory.GetFiles().First();

            (fileToDelete as MemoryFileObject).Exists = false;

            queue.ExecuteAll();

            var fileObjects = targetDirectory.GetFiles().Where(x => x.Exists);

            Assert.AreEqual(1, fileObjects.Count());
            Assert.AreEqual(DirectoryHelper.FileName2, fileObjects.First().Name);
        }
Esempio n. 11
0
        public void ReturnsOnlyNewerFiles()
        {
            var now = DateTime.Now;

            var lastUpdated  = now.AddDays(-1);
            var lastUpdated2 = now.AddDays(1);

            IDirectoryObject sourceDirectory = new MemoryDirectoryObject("directory")
                                               .AddFile(_fileName, _contents, lastUpdated)
                                               .AddFile(_fileName2, _contents, lastUpdated2);

            IDirectoryObject targetDirectory = new MemoryDirectoryObject("directory")
                                               .AddFile(_fileName, _contents, now)
                                               .AddFile(_fileName2, _contents, now);

            var scanner     = new DirectoryScanner(sourceDirectory, targetDirectory);
            var filesToCopy = scanner.GetFilesToCopy();


            Assert.AreEqual(1, filesToCopy.Count);
            Assert.IsTrue(filesToCopy.Any(x => x.Name == _fileName2));
        }
Esempio n. 12
0
        public void WritesFileToLocalFileSystem()
        {
            var directoryInfo = new DirectoryInfo(_testDirectory);

            if (directoryInfo.Exists)
            {
                directoryInfo.Delete(true);
            }

            directoryInfo.Create();
            var targetDirectory = new LocalDirectoryObject(directoryInfo);

            var sourceDirectory = new MemoryDirectoryObject("integrationTests")
                                  .AddFile(_fileName, _contents)
                                  .AddFile(_fileName2, _contents);

            sourceDirectory.AddDirectory(new MemoryDirectoryObject(_subDirectoryName, sourceDirectory.FullName)
                                         .AddFile(_subFileName, _contents)
                                         .AddFile(_subFileName2, _contents));

            var syncNet = new Processor(sourceDirectory, targetDirectory, new SyncTaskQueue());

            syncNet.ProcessSourceDirectory();

            var fileInfos = directoryInfo.GetFiles();

            Assert.AreEqual(2, fileInfos.Length);

            var directoryInfos = directoryInfo.GetDirectories();

            Assert.AreEqual(1, directoryInfos.Length);
            Assert.AreEqual(_subDirectoryName, directoryInfos[0].Name);

            var file          = fileInfos[0];
            var localContents = File.ReadAllText(file.FullName);

            Assert.AreEqual(_contents, localContents);
        }
Esempio n. 13
0
        public void RenamesDirectory()
        {
            IDirectoryObject sourceDirectory = DirectoryHelper.CreateFullDirectory();

            IDirectoryObject targetDirectory = new MemoryDirectoryObject("targetDir");

            var mock = new Mock <ITaskQueue>();

            var syncNet = new Processor(sourceDirectory, targetDirectory, mock.Object);

            syncNet.ProcessSourceDirectory();

            var newName      = "newName";
            var subDirectory = sourceDirectory.GetDirectories().First();

            syncNet.RenameDirectory(subDirectory, newName);

            var targetFile = targetDirectory.GetDirectories().First();

            mock.Verify(x => x.Queue(
                            It.Is <RenameDirectoryTask>(t => t.Directory.FullName == targetFile.FullName && t.NewName == newName))
                        );
        }
Esempio n. 14
0
        public void CreatesDirectoryStructure()
        {
            var sourceDirectory = DirectoryHelper.CreateFullDirectory();

            IDirectoryObject targetDirectory = new MemoryDirectoryObject("directory");

            var syncNet = new Processor(sourceDirectory, targetDirectory, new SyncTaskQueue());

            syncNet.ProcessSourceDirectory();

            Assert.AreEqual(2, targetDirectory.GetFiles().Count());

            var subDirectories = targetDirectory.GetDirectories();

            Assert.AreEqual(1, subDirectories.Count());
            Assert.AreEqual(DirectoryHelper.SubDirectoryName, subDirectories.First().Name);

            var files = subDirectories.First().GetFiles();

            Assert.AreEqual(2, files.Count());

            Assert.IsTrue(files.Any(x => x.Name == DirectoryHelper.SubFileName));
            Assert.IsTrue(files.Any(x => x.Name == DirectoryHelper.SubFileName2));
        }
Esempio n. 15
0
        public void CountsFilesLeft()
        {
            var sourceDirectory = DirectoryHelper.CreateFullDirectory();

            var targetDirectory = new MemoryDirectoryObject("directory");

            var queue   = new ManualTaskQueue();
            var syncNet = new Processor(sourceDirectory, targetDirectory, queue);

            var progressUpdates = new List <SyncNetProgressChangedEventArgs>();

            syncNet.ProgressChanged += delegate(Processor sender, SyncNetProgressChangedEventArgs e)
            {
                progressUpdates.Add(e);
            };

            syncNet.ProcessSourceDirectory();

            queue.ExecuteAll();
            Assert.AreEqual(3, progressUpdates[0].FilesLeft);
            Assert.AreEqual(2, progressUpdates[1].FilesLeft);
            Assert.AreEqual(1, progressUpdates[2].FilesLeft);
            Assert.AreEqual(0, progressUpdates[3].FilesLeft);
        }