예제 #1
0
        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));
        }
예제 #2
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);
        }