Exemple #1
0
        public void Store_Directory()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterDirectory(@"C:\dir");

            var dateTime = new MockDateTime(new DateTime(2010, 10, 1, 0, 0, 0));

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);
            serviceContainer.Register <IDateTimeService>(dateTime);

            var executionContext = new ExecutionContext(serviceContainer);

            var directory = new DirectoryObject(@"C:\dir", fileSystem);

            var storage         = new DirectoryStorage(@"C:\backup");
            var storageInstance = storage.CreateInstance(executionContext);

            var backupContext = new BackupContext(null, executionContext);
            var result        = storageInstance.Store(directory, backupContext).ToArray();

            var expected = new IOperation[] {
                new CreateDirectoryOperation(new DirectoryObject(@"C:\backup\2010-10-01 00-00-00\C\dir", fileSystem), fileSystem, executionContext)
            };

            CollectionAssert.AreEqual(expected, result);
        }
Exemple #2
0
        public void FindObject_File_NonExisting()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterDirectory(@"C:\left");
            fileSystem.RegisterFile(@"C:\left\file");
            fileSystem.RegisterDirectory(@"C:\right");

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);

            var executionContext = new ExecutionContext(serviceContainer);

            var directoryContainer         = new DirectoryContainer(@"C:\right");
            var directoryContainerInstance = directoryContainer.CreateInstance(executionContext);

            var file = new FileObject(@"C:\left\file", fileSystem);

            file.Metadata["BasePath"] = Path.Parse(@"C:\left");

            var syncContext = new SyncContext(null, executionContext);
            var result      = directoryContainerInstance.FindObject(file, syncContext);

            Assert.AreEqual(null, result);
        }
Exemple #3
0
        public void UpdateObject_Directory_NameCasingChange()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterDirectory(@"C:\left");
            fileSystem.RegisterDirectory(@"C:\left\dir");
            fileSystem.RegisterDirectory(@"C:\right");
            fileSystem.RegisterDirectory(@"C:\right\DIR");

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);

            var executionContext = new ExecutionContext(serviceContainer);

            var directoryContainer         = new DirectoryContainer(@"C:\right");
            var directoryContainerInstance = directoryContainer.CreateInstance(executionContext);

            var leftDirectory = new DirectoryObject(@"C:\left\dir", fileSystem);

            leftDirectory.Metadata["BasePath"] = Path.Parse(@"C:\left");

            var rightDirectory = new DirectoryObject(@"C:\right\dir", fileSystem);

            var change = new NameCasingChange();

            var syncContext = new SyncContext(null, executionContext);
            var result      = directoryContainerInstance.UpdateObject(rightDirectory, leftDirectory, change, syncContext).ToArray();

            var expected = new IOperation[] {
                new RenameDirectoryOperation(rightDirectory, leftDirectory.ActualName, fileSystem, executionContext)
            };

            CollectionAssert.AreEqual(expected, result);
        }
Exemple #4
0
        public void RemoveObject_Directory()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterDirectory(@"C:\left");
            fileSystem.RegisterDirectory(@"C:\right");
            fileSystem.RegisterDirectory(@"C:\right\dir");

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);

            var executionContext = new ExecutionContext(serviceContainer);

            var directoryContainer         = new DirectoryContainer(@"C:\right");
            var directoryContainerInstance = directoryContainer.CreateInstance(executionContext);

            var rightDirectory = new DirectoryObject(@"C:\right\dir", fileSystem);

            var syncContext = new SyncContext(null, executionContext);
            var result      = directoryContainerInstance.RemoveObject(rightDirectory, syncContext).ToArray();

            var expected = new IOperation[] {
                new DeleteDirectoryOperation(rightDirectory, fileSystem, executionContext)
            };

            CollectionAssert.AreEqual(expected, result);
        }
Exemple #5
0
        public void GetChanges_Directory_NameCasingChanged()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterDirectory(@"C:\left\dir");
            fileSystem.RegisterDirectory(@"C:\right\DIR");

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);

            var executionContext = new ExecutionContext(serviceContainer);

            var directoryContainer         = new DirectoryContainer(@"C:\right");
            var directoryContainerInstance = directoryContainer.CreateInstance(executionContext);

            var leftDirectory  = new DirectoryObject(@"C:\left\dir", fileSystem);
            var rightDirectory = new DirectoryObject(@"C:\right\dir", fileSystem);

            var syncContext = new SyncContext(null, executionContext);
            var result      = directoryContainerInstance.GetChanges(rightDirectory, leftDirectory, syncContext).ToArray();

            var expected = new IChange[] {
                new NameCasingChange()
            };

            Assert.AreEqual(expected, result);
        }
Exemple #6
0
        public void UpdateObject_File_ContentChange()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterDirectory(@"C:\left");
            fileSystem.RegisterFile(@"C:\left\file");
            fileSystem.RegisterDirectory(@"C:\right");
            fileSystem.RegisterFile(@"C:\right\file");

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);

            var executionContext = new ExecutionContext(serviceContainer);

            var directoryContainer         = new DirectoryContainer(@"C:\right");
            var directoryContainerInstance = directoryContainer.CreateInstance(executionContext);

            var leftFile = new FileObject(@"C:\left\file", fileSystem);

            leftFile.Metadata["BasePath"] = Path.Parse(@"C:\left");

            var rightFile = new FileObject(@"C:\right\file", fileSystem);

            var change = new ContentChange();

            var syncContext = new SyncContext(null, executionContext);
            var result      = directoryContainerInstance.UpdateObject(rightFile, leftFile, change, syncContext).ToArray();

            var expected = new IOperation[] {
                new CopyFileOperation(leftFile, rightFile, fileSystem, executionContext)
            };

            CollectionAssert.AreEqual(expected, result);
        }
Exemple #7
0
        public void GetChanges_File_LastWriteTimeChanged()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterFile(@"C:\left\file", length: 100, lastWriteTime: DateTime.MinValue);
            fileSystem.RegisterFile(@"C:\right\file", length: 100, lastWriteTime: DateTime.MinValue.AddDays(1));

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);

            var executionContext = new ExecutionContext(serviceContainer);

            var directoryContainer         = new DirectoryContainer(@"C:\right");
            var directoryContainerInstance = directoryContainer.CreateInstance(executionContext);

            var leftFile  = new FileObject(@"C:\left\file", fileSystem);
            var rightFile = new FileObject(@"C:\right\file", fileSystem);

            var syncContext = new SyncContext(null, executionContext);
            var result      = directoryContainerInstance.GetChanges(rightFile, leftFile, syncContext).ToArray();

            var expected = new IChange[] {
                new ContentChange()
            };

            Assert.AreEqual(expected, result);
        }
Exemple #8
0
        public void GetObjects()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterDirectory(@"C:\dir");
            fileSystem.RegisterDirectory(@"C:\dir\dir1");
            fileSystem.RegisterDirectory(@"C:\dir\dir2");
            fileSystem.RegisterFile(@"C:\dir\file1");
            fileSystem.RegisterFile(@"C:\dir\file2");

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);

            var executionContext = new ExecutionContext(serviceContainer);

            var directoryContainer         = new DirectoryContainer(@"C:\dir");
            var directoryContainerInstance = directoryContainer.CreateInstance(executionContext);

            var syncContext = new SyncContext(null, executionContext);
            var result      = directoryContainerInstance.GetObjects(syncContext).ToArray();

            var expected = new IFileSystemObject[] {
                new FileObject(@"C:\dir\file1", fileSystem),
                new FileObject(@"C:\dir\file2", fileSystem),
                new DirectoryObject(@"C:\dir\dir1", fileSystem),
                new DirectoryObject(@"C:\dir\dir2", fileSystem)
            };

            CollectionAssert.AreEqual(expected, result);
        }
Exemple #9
0
        public void GetObjects()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterDirectory(@"C:\dir");
            fileSystem.RegisterDirectory(@"C:\dir\dir1");
            fileSystem.RegisterFile(@"C:\dir\file1");
            fileSystem.RegisterFile(@"C:\file2");

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);

            var executionContext = new ExecutionContext(serviceContainer);

            var roots = new IFileSystemRoot[] {
                new DirectoryRoot(@"C:\dir", fileSystem),
                new FileRoot(@"C:\file2", fileSystem)
            };

            var source         = new FileSystemSource(roots);
            var sourceInstance = source.CreateInstance(executionContext);

            var backupContext = new BackupContext(null, executionContext);
            var result        = sourceInstance.GetObjects(backupContext).ToArray();

            var expected = new IObject[] {
                new DirectoryObject(@"C:\dir", fileSystem),
                new FileObject(@"C:\dir\file1", fileSystem),
                new DirectoryObject(@"C:\dir\dir1", fileSystem),
                new FileObject(@"C:\file2", fileSystem)
            };

            CollectionAssert.AreEqual(expected, result);
        }
Exemple #10
0
        public void GetObjects_SingleRoot_TrueInclude_NoExclude()
        {
            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <ITextFormatter>(new TextFormatter(serviceContainer));

            var context = new ExecutionContext(serviceContainer);

            var fileSystem = new MockFileSystem();

            fileSystem.RegisterFile(@"C:\file1");

            var root           = new FileRoot(@"C:\file1", fileSystem);
            var include        = new IRule[] { new TrueRule() };
            var objectProvider = new FileSystemObjectProvider(root, include, null);

            var result = objectProvider.GetObjects(context).ToArray();

            var expected = new IFileSystemObject[]
            {
                new FileObject(@"C:\file1", fileSystem),
            };

            CollectionAssert.AreEqual(expected, result);
        }
Exemple #11
0
        public void GetObjects_MultiRoot()
        {
            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <ITextFormatter>(new TextFormatter(serviceContainer));

            var context = new ExecutionContext(serviceContainer);

            var fileSystem = new MockFileSystem();

            fileSystem.RegisterFile(@"C:\file1");
            fileSystem.RegisterFile(@"C:\file2");

            var root1          = new FileRoot(@"C:\file1", fileSystem);
            var root2          = new FileRoot(@"C:\file2", fileSystem);
            var roots          = new IFileSystemRoot[] { root1, root2 };
            var objectProvider = new FileSystemObjectProvider(roots, null, null);

            var result = objectProvider.GetObjects(context).ToArray();

            var expected = new IFileSystemObject[]
            {
                new FileObject(@"C:\file1", fileSystem),
                new FileObject(@"C:\file2", fileSystem)
            };

            CollectionAssert.AreEqual(expected, result);
        }
Exemple #12
0
        public void Store_Drive()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterDrive(@"C:");

            var dateTime = new MockDateTime(new DateTime(2010, 10, 1, 0, 0, 0));

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);
            serviceContainer.Register <IDateTimeService>(dateTime);

            var executionContext = new ExecutionContext(serviceContainer);

            var drive = new DriveObject(@"C:", fileSystem);

            var storage         = new DirectoryStorage(@"C:\backup");
            var storageInstance = storage.CreateInstance(executionContext);

            var backupContext = new BackupContext(null, executionContext);
            var result        = storageInstance.Store(drive, backupContext).ToArray();
        }
Exemple #13
0
        public void BackupDirectoryPath()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterFile(@"C:\file");

            var dateTime = new MockDateTime(new DateTime(2010, 10, 1, 0, 0, 0));

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);
            serviceContainer.Register <IDateTimeService>(dateTime);

            var executionContext = new ExecutionContext(serviceContainer);

            var file = new FileObject(@"C:\file", fileSystem);

            var storage         = new DirectoryStorage(@"C:\backup");
            var storageInstance = (DirectoryStorageInstance)storage.CreateInstance(executionContext);

            var expected = Path.Parse(@"C:\backup").Combine(dateTime.GetCurrentDateTime().ToString("yyyy-MM-dd HH-mm-ss"));

            Assert.AreEqual(expected, storageInstance.BackupDirectoryPath);
        }
Exemple #14
0
        public void GetObjects_NonExistingFile()
        {
            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <ITextFormatter>(new TextFormatter(serviceContainer));

            var context = new ExecutionContext(serviceContainer);

            var fileSystem = new MockFileSystem();
            var root       = new FileRoot(@"C:\root", fileSystem);
            var result     = root.GetObjects(context).ToArray();

            var expected = new IFileSystemObject[]
            {
            };

            CollectionAssert.AreEqual(expected, result);
        }
Exemple #15
0
        public void GetObjects_1Level()
        {
            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <ITextFormatter>(new TextFormatter(serviceContainer));

            var context = new ExecutionContext(serviceContainer);

            var fileSystem = new MockFileSystem();

            fileSystem.RegisterDirectory(@"C:\root\dir1");

            var root   = new DirectoryRoot(@"C:\root", fileSystem);
            var result = root.GetObjects(context).ToArray();

            var expected = new IFileSystemObject[]
            {
                new DirectoryObject(@"C:\root", fileSystem),
                new DirectoryObject(@"C:\root\dir1", fileSystem)
            };

            CollectionAssert.AreEqual(expected, result);
        }