Exemplo n.º 1
0
 public void BasicSyncOnly()
 {
     TestWrapperFactory
     .CreateLocalToLocal(this.TestContext)
     .SaveRelationship()
     .CreateBasicSourceStructure()
     .CreateSyncJob()
     .RunToCompletion()
     .VerifySyncSuccess()
     .VerifyResultContainsAllFiles()
     .VerifyDatabaseHashes();
 }
Exemplo n.º 2
0
        public void SyncModifiedTimestampChange()
        {
            var testWrapper = TestWrapperFactory
                              .CreateLocalToLocal(this.TestContext)
                              .SaveRelationship()
                              .CreateSimpleSourceStructure();

            // First sync job
            testWrapper
            .CreateSyncJob()
            .RunToCompletion()
            .VerifySyncSuccess()
            .VerifyResultContainsAllFiles()
            .VerifyDatabaseHashes();

            Logger.Info("Logging database before last modified timestamp change:");
            using (var db = testWrapper.Relationship.GetDatabase())
            {
                TestHelper.LogConfiguration(testWrapper.Relationship.Configuration);
                TestHelper.LogDatabase(db);
            }

            // Update the creation time of a file
            string filePath        = Path.Combine(testWrapper.SourceAdapter.Config.RootDirectory, "dir1\\file1.txt");
            var    newModifiedTime = File.GetLastWriteTimeUtc(filePath).AddSeconds(1);

            File.SetLastWriteTimeUtc(filePath, newModifiedTime);

            // Second sync job
            var jobWrapper = testWrapper
                             .CreateSyncJob();

            jobWrapper
            .RunToCompletion()
            .VerifySyncSuccess()
            .VerifyAnalyzeEntryCount(1)
            .VerifyDatabaseHashes();

            SyncJob syncJob = (SyncJob)((AnalyzeJob)jobWrapper.CurrentJob).ContinuationJob;

            // Verify that only the created timestamp change was detected
            var changedSyncEntry = syncJob.AnalyzeResult.AdapterResults[1].EntryResults[0];

            Assert.AreEqual(changedSyncEntry.Flags, SyncEntryChangedFlags.ModifiedTimestamp);

            // Verify that the timestamp was copied
            filePath = Path.Combine(testWrapper.DestinationAdapter.Config.RootDirectory, "dir1\\file1.txt");
            var expectedModifiedTime = File.GetLastWriteTimeUtc(filePath);

            Assert.AreEqual(expectedModifiedTime, newModifiedTime);
        }
Exemplo n.º 3
0
        public void SyncWithFileRename()
        {
            var testWrapper = TestWrapperFactory
                              .CreateLocalToLocal(this.TestContext)
                              .SaveRelationship()
                              .CreateBasicSourceStructure();

            // First sync job
            testWrapper
            .CreateSyncJob()
            .RunToCompletion()
            .VerifySyncSuccess()
            .VerifyResultContainsAllFiles()
            .VerifyDatabaseHashes();

            Logger.Info("Logging database before delete:");
            using (var db = testWrapper.Relationship.GetDatabase())
            {
                TestHelper.LogConfiguration(testWrapper.Relationship.Configuration);
                TestHelper.LogDatabase(db);
            }

            var syncSourcePath = testWrapper.SourceAdapter.Config.RootDirectory;

            Directory.Move(
                Path.Combine(syncSourcePath, "dir1\\file2.txt"),
                Path.Combine(syncSourcePath, "dir1\\file2a.txt"));
            Directory.Move(
                Path.Combine(syncSourcePath, "dir2"),
                Path.Combine(syncSourcePath, "dir2a"));

            testWrapper.SyncFileList.Remove("dir1\\file2.txt");
            testWrapper.SyncFileList.Add("dir1\\file2a.txt");

            for (int i = 0; i < testWrapper.SyncFileList.Count; i++)
            {
                string path = testWrapper.SyncFileList[i];
                if (path.StartsWith("dir2\\") || path == "dir2")
                {
                    testWrapper.SyncFileList[i] = path.Insert(4, "a");
                }
            }

            // Second sync job
            testWrapper
            .CreateSyncJob()
            .RunToCompletion()
            .VerifySyncSuccess()
            .VerifyAnalyzeEntryCount(3)
            .VerifyDatabaseHashes();
        }
Exemplo n.º 4
0
        public void SyncWithAllExistingFiles()
        {
            var testWrapper = TestWrapperFactory
                              .CreateLocalToLocal(this.TestContext)
                              .SaveRelationship()
                              .CreateBasicSourceStructure()
                              .CopySourceStructureToDestination()
                              .CreateSyncJob()
                              .RunToCompletion();

            testWrapper
            .VerifySyncSuccess()
            .VerifyResultContainsAllFiles()
            .VerifyAnalyzeEntryCount(13)
            .VerifyEntryUpdateInfo(e => e.HasSyncEntryFlag(SyncEntryChangedFlags.DestinationExists));
        }
Exemplo n.º 5
0
        public void BasicBidirectionalSync()
        {
            var wrapper = TestWrapperFactory
                          .CreateLocalToLocal(this.TestContext);

            wrapper.Relationship.SyncScope = SyncScopeType.Bidirectional;

            wrapper
            .SaveRelationship()
            .CreateBasicSourceStructure()
            .CreateBasicDestinationStructure()
            .CreateSyncJob()
            .RunToCompletion()
            .VerifySyncSuccess()
            .VerifyResultContainsAllFiles()
            .VerifyDatabaseHashes();
        }
Exemplo n.º 6
0
        public void SyncLocalFilesWithEncryption()
        {
            var wrapper = TestWrapperFactory
                          .CreateLocalToLocal(this.TestContext)
                          .SaveRelationship()
                          .CreateSimpleSourceStructure();

            X509Certificate2 cert = ReadTestCert();

            wrapper.Relationship.EncryptionMode = EncryptionMode.Encrypt;
            wrapper.Relationship.EncryptionCertificateThumbprint = cert.Thumbprint;

            wrapper.CreateSyncJob()
            .RunToCompletion()
            .VerifySyncSuccess()
            .VerifyResultContainsAllFiles()
            .VerifyDatabaseHashes();
        }
Exemplo n.º 7
0
        public void BasicAnalyzeOnly()
        {
            var testWrapper = TestWrapperFactory
                              .CreateLocalToLocal(this.TestContext)
                              .SaveRelationship()
                              .CreateBasicSourceStructure();

            testWrapper
            .CreateAnalyzeJob()
            .RunToCompletion()
            .VerifyAnalyzeSuccess()
            .VerifyResultContainsAllFiles();

            // Ensure that the destination directory is empty (no files should be copied in analyze-only)
            var destFiles = Directory.GetFileSystemEntries(testWrapper.DestinationAdapter.Config.RootDirectory);

            Assert.AreEqual(0, destFiles.Length);
        }
Exemplo n.º 8
0
        public void SyncWithFileMoveRootToLeaf()
        {
            var testWrapper = TestWrapperFactory
                              .CreateLocalToLocal(this.TestContext)
                              .SaveRelationship()
                              .CreateBasicSourceStructure();

            // First sync job
            testWrapper
            .CreateSyncJob()
            .RunToCompletion()
            .VerifySyncSuccess()
            .VerifyResultContainsAllFiles()
            .VerifyDatabaseHashes();

            Logger.Info("Logging database before delete:");
            using (var db = testWrapper.Relationship.GetDatabase())
            {
                TestHelper.LogConfiguration(testWrapper.Relationship.Configuration);
                TestHelper.LogDatabase(db);
            }

            // Move the file we are going to test
            var syncSourcePath = testWrapper.SourceAdapter.Config.RootDirectory;

            Directory.Move(
                Path.Combine(syncSourcePath, "dir1\\file1.txt"),
                Path.Combine(syncSourcePath, "dir2\\dir3\\dir4\\file1.txt"));

            // Update the expected set of files
            testWrapper.SyncFileList.Remove("dir1\\file1.txt");
            testWrapper.SyncFileList.Add("dir2\\dir3\\dir4\\file1.txt");

            // Run the second sync job
            testWrapper
            .CreateSyncJob()
            .RunToCompletion()
            .VerifySyncSuccess()
            .VerifyAnalyzeEntryCount(2)
            .VerifyDatabaseHashes();
        }
Exemplo n.º 9
0
        public void SyncWithDelete()
        {
            var testWrapper = TestWrapperFactory
                              .CreateLocalToLocal(this.TestContext)
                              .SaveRelationship()
                              .CreateBasicSourceStructure();

            // First sync job
            testWrapper
            .CreateSyncJob()
            .RunToCompletion()
            .VerifySyncSuccess()
            .VerifyResultContainsAllFiles()
            .VerifyDatabaseHashes();

            Logger.Info("Logging database before delete:");
            using (var db = testWrapper.Relationship.GetDatabase())
            {
                TestHelper.LogConfiguration(testWrapper.Relationship.Configuration);
                TestHelper.LogDatabase(db);
            }

            // Delete dir2 and a file from dir1
            var syncSourcePath = testWrapper.SourceAdapter.Config.RootDirectory;

            File.Delete(Path.Combine(syncSourcePath, "dir1\\file2.txt"));
            Directory.Delete(Path.Combine(syncSourcePath, "dir2\\dir3"), true);

            testWrapper.SyncFileList.Remove("dir1\\file2.txt");
            testWrapper.SyncFileList.RemoveAll(e => e.StartsWith("dir2\\dir3"));

            // Second sync job
            testWrapper
            .CreateSyncJob()
            .RunToCompletion()
            .VerifySyncSuccess()
            .VerifyAnalyzeEntryCount(6)
            .VerifyDatabaseHashes();
        }
Exemplo n.º 10
0
        public void SyncIsIdempotent()
        {
            var testWrapper = TestWrapperFactory
                              .CreateLocalToLocal(this.TestContext)
                              .SaveRelationship()
                              .CreateBasicSourceStructure();

            // First sync job
            testWrapper
            .CreateSyncJob()
            .RunToCompletion()
            .VerifySyncSuccess()
            .VerifyResultContainsAllFiles()
            .VerifyDatabaseHashes();

            // Second sync job
            testWrapper
            .CreateSyncJob()
            .RunToCompletion()
            .VerifyAnalyzeSuccess()
            .VerifySyncNotRun()
            .VerifyAnalyzeEntryCount(0);
        }
Exemplo n.º 11
0
        public void SyncException()
        {
            var testWrapper = TestWrapperFactory
                              .CreateLocalToLocal(this.TestContext)
                              .SaveRelationship()
                              .CreateBasicSourceStructure();

            // First sync job
            testWrapper
            .CreateSyncJob()
            .RunToCompletion()
            .VerifySyncSuccess()
            .VerifyResultContainsAllFiles()
            .VerifyDatabaseHashes();

            Logger.Info("Logging database before delete:");
            using (var db = testWrapper.Relationship.GetDatabase())
            {
                TestHelper.LogConfiguration(testWrapper.Relationship.Configuration);
                TestHelper.LogDatabase(db);
            }

            // Create a new file
            string relativePath = TestHelper.CreateFile(
                testWrapper.SourceAdapter.Config.RootDirectory,
                "dir1\\file4.txt");

            string filePath = Path.Combine(
                testWrapper.SourceAdapter.Config.RootDirectory,
                relativePath);

            // Run an analyze path to detect the file
            var analyzeResult = testWrapper
                                .CreateAnalyzeJob()
                                .RunToCompletion()
                                .GetAnalyzeResult();

            // Change the permissions of the file
            FileSecurity fileSecurity = File.GetAccessControl(filePath);

            if (fileSecurity == null)
            {
                throw new Exception("Failed to create file security");
            }

            SecurityIdentifier currentUser = WindowsIdentity.GetCurrent().User;

            Pre.Assert(currentUser != null, "currentUser != null");

            // Create a new rule denying ready access to the current user
            FileSystemAccessRule newRule = new FileSystemAccessRule(
                currentUser,
                FileSystemRights.Read,
                AccessControlType.Deny);

            fileSecurity.AddAccessRule(newRule);
            File.SetAccessControl(filePath, fileSecurity);

            // Second sync job
            var syncRun = testWrapper
                          .CreateSyncJob(analyzeResult)
                          .RunToCompletion()
                          .VerifySyncFailed();

            var syncAnalyzeResult = syncRun.GetAnalyzeResult();

            var entryResult = syncAnalyzeResult.AdapterResults.First().Value.EntryResults[0];

            Assert.AreEqual("file4.txt", entryResult.Entry.Name);
            Assert.IsTrue(!string.IsNullOrWhiteSpace(entryResult.ErrorMessage));
        }