public void BasicSyncUploadOnly() { if (!GlobalTestSettings.RunNetworkTests) { Assert.Inconclusive(GlobalTestSettings.NetworkTestsDisabledMessage); } string testRootPath = Path.Combine(this.TestContext.TestLogsDir, this.TestContext.TestName); Directory.CreateDirectory(testRootPath); string syncDestinationPath = Path.Combine(testRootPath, "Destination"); Directory.CreateDirectory(syncDestinationPath); TokenResponse currentToken = GetCurrentToken(); Global.Initialize(testRootPath); SyncRelationship newRelationship = SyncRelationship.Create(); OneDriveAdapter sourceAdapter = new OneDriveAdapter(newRelationship) { CurrentToken = currentToken, }; sourceAdapter.Config.TargetPath = "OneDrive/SyncTest"; sourceAdapter.Config.IsOriginator = true; sourceAdapter.InitializeClient().Wait(); WindowsFileSystemAdapter destAdapter = new WindowsFileSystemAdapter(newRelationship); destAdapter.Config.RootDirectory = syncDestinationPath; newRelationship.Adapters.Add(sourceAdapter); newRelationship.Adapters.Add(destAdapter); newRelationship.SourceAdapter = sourceAdapter; newRelationship.DestinationAdapter = destAdapter; newRelationship.Name = "Test Relationship #1"; newRelationship.Description = "Test Relationship Description #1"; newRelationship.SaveAsync().Wait(); AnalyzeJob analyzeJob = new AnalyzeJob(newRelationship); analyzeJob.ContinuationJob = new SyncJob(newRelationship, analyzeJob.AnalyzeResult) { TriggerType = SyncTriggerType.Manual }; analyzeJob.Start(); SyncJob syncJob = (SyncJob)analyzeJob.WaitForCompletion(); Assert.IsTrue(syncJob.HasFinished); //Assert.AreEqual(syncFileList.Count, run1.AnalyzeResult.EntryResults.Count); }
public void ExitingSyncModifyFiles() { if (!GlobalTestSettings.RunNetworkTests) { Assert.Inconclusive(GlobalTestSettings.NetworkTestsDisabledMessage); } string testRootPath = Path.Combine(this.TestContext.TestLogsDir, this.TestContext.TestName); Directory.CreateDirectory(testRootPath); string syncSourcePath = Path.Combine(testRootPath, "Source"); Directory.CreateDirectory(syncSourcePath); // Create temp files/folders List <string> syncFileList = new List <string> { TestHelper.CreateDirectory(syncSourcePath, "dir1"), TestHelper.CreateFile(syncSourcePath, "dir1\\file1.txt"), TestHelper.CreateFile(syncSourcePath, "dir1\\file2.txt"), TestHelper.CreateFile(syncSourcePath, "dir1\\file3.txt"), TestHelper.CreateDirectory(syncSourcePath, "dir2"), TestHelper.CreateFile(syncSourcePath, "dir2\\file1.txt"), TestHelper.CreateFile(syncSourcePath, "dir2\\file2.txt"), TestHelper.CreateFile(syncSourcePath, "dir2\\file3.txt") }; Global.Initialize(testRootPath); SyncRelationship newRelationship = SyncRelationship.Create(); WindowsFileSystemAdapter sourceAdapter = new WindowsFileSystemAdapter(newRelationship); sourceAdapter.Config.RootDirectory = syncSourcePath; TAdapter destAdapter = CreateDestinationAdapter(newRelationship, GetCurrentMethod()); newRelationship.Adapters.Add(sourceAdapter); newRelationship.Adapters.Add(destAdapter); newRelationship.SourceAdapter = sourceAdapter; newRelationship.DestinationAdapter = destAdapter; newRelationship.Name = "Test Relationship #1"; newRelationship.Description = "Test Relationship Description #1"; newRelationship.SaveAsync().Wait(); AnalyzeJob analyzeJob = new AnalyzeJob(newRelationship); analyzeJob.ContinuationJob = new SyncJob(newRelationship, analyzeJob.AnalyzeResult) { TriggerType = SyncTriggerType.Manual }; analyzeJob.Start(); SyncJob syncJob = (SyncJob)analyzeJob.WaitForCompletion(); Assert.IsTrue(syncJob.HasFinished); Assert.AreEqual( syncFileList.Count, syncJob.AnalyzeResult.AdapterResults.SelectMany(r => r.Value.EntryResults).Count()); syncFileList.Add(TestHelper.UpdateFile(syncSourcePath, "dir1\\file1.txt")); syncFileList.Add(TestHelper.UpdateFile(syncSourcePath, "dir2\\file1.txt")); // Short sleep to ensure that the timestamp when the file is written to the remote // adapter differs from the initial write. Thread.Sleep(2000); AnalyzeJob analyzeJob2 = new AnalyzeJob(newRelationship); analyzeJob2.ContinuationJob = new SyncJob(newRelationship, analyzeJob2.AnalyzeResult) { TriggerType = SyncTriggerType.Manual }; analyzeJob2.Start(); SyncJob syncJob2 = (SyncJob)analyzeJob2.WaitForCompletion(); Assert.IsTrue(syncJob2.HasFinished); AssertSyncJobSuccess(syncJob2, 2); AnalyzeJob analyzeJob3 = new AnalyzeJob(newRelationship); analyzeJob3.Start(); analyzeJob3.WaitForCompletion(); AssertAnalyzeJobSuccess(analyzeJob3, 0); }
public void ExitingSyncAddFiles() { if (!GlobalTestSettings.RunNetworkTests) { Assert.Inconclusive(GlobalTestSettings.NetworkTestsDisabledMessage); } string testRootPath = Path.Combine(this.TestContext.TestLogsDir, this.TestContext.TestName); Directory.CreateDirectory(testRootPath); string syncSourcePath = Path.Combine(testRootPath, "Source"); Directory.CreateDirectory(syncSourcePath); // Create temp files/folders List <string> syncFileList = new List <string> { TestHelper.CreateDirectory(syncSourcePath, "dir1"), TestHelper.CreateFile(syncSourcePath, "dir1\\file1.txt"), TestHelper.CreateFile(syncSourcePath, "dir1\\file2.txt"), TestHelper.CreateFile(syncSourcePath, "dir1\\file3.txt"), TestHelper.CreateDirectory(syncSourcePath, "dir2"), TestHelper.CreateFile(syncSourcePath, "dir2\\file1.txt"), TestHelper.CreateFile(syncSourcePath, "dir2\\file2.txt"), TestHelper.CreateFile(syncSourcePath, "dir2\\file3.txt") }; Global.Initialize(testRootPath); SyncRelationship newRelationship = SyncRelationship.Create(); WindowsFileSystemAdapter sourceAdapter = new WindowsFileSystemAdapter(newRelationship); sourceAdapter.Config.RootDirectory = syncSourcePath; TAdapter destAdapter = CreateDestinationAdapter(newRelationship, GetCurrentMethod()); newRelationship.Adapters.Add(sourceAdapter); newRelationship.Adapters.Add(destAdapter); newRelationship.SourceAdapter = sourceAdapter; newRelationship.DestinationAdapter = destAdapter; newRelationship.Name = "Test Relationship #1"; newRelationship.Description = "Test Relationship Description #1"; newRelationship.SaveAsync().Wait(); AnalyzeJob analyzeJob = new AnalyzeJob(newRelationship); analyzeJob.ContinuationJob = new SyncJob(newRelationship, analyzeJob.AnalyzeResult) { TriggerType = SyncTriggerType.Manual }; analyzeJob.Start(); SyncJob syncJob = (SyncJob)analyzeJob.WaitForCompletion(); AssertSyncJobSuccess(syncJob, syncFileList.Count); syncFileList.Add(TestHelper.CreateFile(syncSourcePath, "dir1\\file4.txt")); syncFileList.Add(TestHelper.CreateFile(syncSourcePath, "dir2\\file4.txt")); AnalyzeJob analyzeJob2 = new AnalyzeJob(newRelationship); analyzeJob2.ContinuationJob = new SyncJob(newRelationship, analyzeJob2.AnalyzeResult) { TriggerType = SyncTriggerType.Manual }; analyzeJob2.Start(); SyncJob syncJob2 = (SyncJob)analyzeJob2.WaitForCompletion(); AssertSyncJobSuccess(syncJob2, 2); }
public void BasicSyncDownloadOnly() { if (!GlobalTestSettings.RunNetworkTests) { Assert.Inconclusive(GlobalTestSettings.NetworkTestsDisabledMessage); } string testRootPath = Path.Combine(this.TestContext.TestLogsDir, this.TestContext.TestName); Directory.CreateDirectory(testRootPath); string syncDestinationPath = Path.Combine(testRootPath, "Destination"); Directory.CreateDirectory(syncDestinationPath); Global.Initialize(testRootPath, true); SyncRelationship newRelationship = SyncRelationship.Create(); TAdapter sourceAdapter = CreateSourceAdapter(newRelationship, GetCurrentMethod()); WindowsFileSystemAdapter destAdapter = new WindowsFileSystemAdapter(newRelationship); destAdapter.Config.RootDirectory = syncDestinationPath; newRelationship.Adapters.Add(sourceAdapter); newRelationship.Adapters.Add(destAdapter); newRelationship.SourceAdapter = sourceAdapter; newRelationship.DestinationAdapter = destAdapter; newRelationship.Name = "Test Relationship #1"; newRelationship.Description = "Test Relationship Description #1"; newRelationship.SaveAsync().Wait(); // The list of files and folders that we expect to be present List <Tuple <string, long, SyncEntryType> > syncFileList = new List <Tuple <string, long, SyncEntryType> > { new Tuple <string, long, SyncEntryType>("FolderA", 0, SyncEntryType.Directory), new Tuple <string, long, SyncEntryType>("FolderA\\EmptyFolder", 0, SyncEntryType.Directory), new Tuple <string, long, SyncEntryType>("FolderA\\Book1.xlsx", 7954, SyncEntryType.File), new Tuple <string, long, SyncEntryType>("FolderA\\Document1.docx", 14994, SyncEntryType.File), new Tuple <string, long, SyncEntryType>("FolderA\\NewTextFile1.txt", 3, SyncEntryType.File), new Tuple <string, long, SyncEntryType>("FolderA\\NewTextFile2.txt", 3, SyncEntryType.File), new Tuple <string, long, SyncEntryType>("FolderA\\NewTextFile3.txt", 3, SyncEntryType.File), new Tuple <string, long, SyncEntryType>("FolderA\\NewTextFile4.txt", 3, SyncEntryType.File), new Tuple <string, long, SyncEntryType>("FolderA\\Presentation1.pptx", 30274, SyncEntryType.File), new Tuple <string, long, SyncEntryType>("FolderB", 0, SyncEntryType.Directory), new Tuple <string, long, SyncEntryType>("FolderB\\FolderC", 0, SyncEntryType.Directory), new Tuple <string, long, SyncEntryType>("FolderB\\FolderC\\gitignore_global.txt", 236, SyncEntryType.File), new Tuple <string, long, SyncEntryType>("sample_photo_00.jpg", 61813, SyncEntryType.File), new Tuple <string, long, SyncEntryType>("sample_photo_01.jpg", 119264, SyncEntryType.File), new Tuple <string, long, SyncEntryType>("sample_photo_02.jpg", 76929, SyncEntryType.File), new Tuple <string, long, SyncEntryType>("sample_photo_03.jpg", 35859, SyncEntryType.File) }; AnalyzeJob analyzeJob = new AnalyzeJob(newRelationship); analyzeJob.ContinuationJob = new SyncJob(newRelationship, analyzeJob.AnalyzeResult) { TriggerType = SyncTriggerType.Manual }; analyzeJob.Start(); SyncJob syncJob = (SyncJob)analyzeJob.WaitForCompletion(); Assert.IsTrue(syncJob.HasFinished); int expectedFileCount = syncFileList.Count; if (sourceAdapter.Configuration.DirectoriesAreUniqueEntities == false) { expectedFileCount--; } // Ensure that the right number of entries are present in the result Assert.AreEqual(expectedFileCount, syncJob.AnalyzeResult.AdapterResults.SelectMany(r => r.Value.EntryResults).Count()); string[] localFiles = Directory.GetFileSystemEntries(syncDestinationPath, "*", SearchOption.AllDirectories); // Ensure that the number of files downloaded is the same as the number expected Assert.AreEqual(expectedFileCount, localFiles.Length); foreach (string fileSystemEntry in localFiles) { string relativePath = fileSystemEntry.Substring(syncDestinationPath.Length + 1); var syncFile = syncFileList.FirstOrDefault(f => f.Item1 == relativePath); // Ensure that the item found on disk was found in the list Assert.IsNotNull(syncFile); if (Directory.Exists(fileSystemEntry) && syncFile.Item3 != SyncEntryType.Directory) { Assert.Fail("The item is type is incorrect (should be Directory)"); } if (File.Exists(fileSystemEntry)) { if (syncFile.Item3 != SyncEntryType.File) { Assert.Fail("The item is type is incorrect (should be File)"); } FileInfo f = new FileInfo(fileSystemEntry); Assert.IsTrue(syncFile.Item2 >= f.Length, "File length is incorrect."); } } }
public void UploadLargeFile() { if (!GlobalTestSettings.RunNetworkTests) { Assert.Inconclusive(GlobalTestSettings.NetworkTestsDisabledMessage); } string testRootPath = Path.Combine(this.TestContext.TestLogsDir, this.TestContext.TestName); Directory.CreateDirectory(testRootPath); string syncSourcePath = Path.Combine(testRootPath, "Source"); Directory.CreateDirectory(syncSourcePath); // Allocate a 15M buffer int bufferSize = 15 * 1024 * 1024; byte[] data = new byte[bufferSize]; // Fill with non-empty data for (int i = 0; i < bufferSize; i++) { data[i] = (byte)(i % sizeof(byte)); } // Create temp files/folders List <string> syncFileList = new List <string> { TestHelper.CreateDirectory(syncSourcePath, "dir1"), TestHelper.CreateFile(syncSourcePath, "dir1\\bigFile.txt", data), }; Global.Initialize(testRootPath); SyncRelationship newRelationship = SyncRelationship.Create(); WindowsFileSystemAdapter sourceAdapter = new WindowsFileSystemAdapter(newRelationship); sourceAdapter.Config.RootDirectory = syncSourcePath; TAdapter destAdapter = CreateDestinationAdapter(newRelationship, GetCurrentMethod()); newRelationship.Adapters.Add(sourceAdapter); newRelationship.Adapters.Add(destAdapter); newRelationship.SourceAdapter = sourceAdapter; newRelationship.DestinationAdapter = destAdapter; newRelationship.Name = "Test Relationship #1"; newRelationship.Description = "Test Relationship Description #1"; newRelationship.SaveAsync().Wait(); AnalyzeJob analyzeJob = new AnalyzeJob(newRelationship); analyzeJob.ContinuationJob = new SyncJob(newRelationship, analyzeJob.AnalyzeResult) { TriggerType = SyncTriggerType.Manual }; analyzeJob.Start(); SyncJob syncJob = (SyncJob)analyzeJob.WaitForCompletion(); AssertSyncJobSuccess(syncJob, syncFileList.Count); }
public void BasicSyncLocalToOneDrive() { if (!GlobalTestSettings.RunNetworkTests) { Assert.Inconclusive(GlobalTestSettings.NetworkTestsDisabledMessage); } string testRootPath = Path.Combine(this.TestContext.TestLogsDir, this.TestContext.TestName); Directory.CreateDirectory(testRootPath); string syncSourcePath = Path.Combine(testRootPath, "Source"); Directory.CreateDirectory(syncSourcePath); // Create temp files/folders List <string> syncFileList = new List <string> { TestHelper.CreateDirectory(syncSourcePath, "dir1"), TestHelper.CreateFile(syncSourcePath, "dir1\\file1.txt"), TestHelper.CreateFile(syncSourcePath, "dir1\\file2.txt"), TestHelper.CreateFile(syncSourcePath, "dir1\\file3.txt"), TestHelper.CreateDirectory(syncSourcePath, "dir2"), TestHelper.CreateFile(syncSourcePath, "dir2\\file1.txt"), TestHelper.CreateFile(syncSourcePath, "dir2\\file2.txt"), TestHelper.CreateFile(syncSourcePath, "dir2\\file3.txt") }; TokenResponse currentToken = GetCurrentToken(); Guid remoteTestFolderName = Guid.NewGuid(); Item remoteTestFolder = CreateOneDriveTestDirectory(currentToken, remoteTestFolderName.ToString("D")).Result; SyncRelationship newRelationship = SetupRelationship(testRootPath, syncSourcePath, remoteTestFolder); AnalyzeJob analyzeJob = new AnalyzeJob(newRelationship); analyzeJob.ContinuationJob = new SyncJob(newRelationship, analyzeJob.AnalyzeResult) { TriggerType = SyncTriggerType.Manual }; analyzeJob.Start(); SyncJob syncJob = (SyncJob)analyzeJob.WaitForCompletion(); Assert.IsTrue(syncJob.HasFinished); Assert.AreEqual(syncFileList.Count, syncJob.AnalyzeResult.AdapterResults.SelectMany(r => r.Value.EntryResults).Count()); OneDriveAdapter oneDriveAdapter = newRelationship.Adapters.First(a => !a.Configuration.IsOriginator) as OneDriveAdapter; OneDriveClient client = new OneDriveClient(GetCurrentToken()); foreach (string syncFile in syncFileList.Where(f => f.EndsWith(".txt"))) { string localPath = Path.Combine(syncSourcePath, syncFile); using (var sha1 = new SHA1Managed()) { byte[] content = File.ReadAllBytes(localPath); byte[] localFileHash = sha1.ComputeHash(content); EntryUpdateInfo entryResult; using (var db = newRelationship.GetDatabase()) { entryResult = syncJob.AnalyzeResult.AdapterResults.SelectMany(r => r.Value.EntryResults).FirstOrDefault( r => r.Entry.GetRelativePath(db, "\\") == syncFile); } Assert.IsNotNull(entryResult); byte[] databaseHash = entryResult.Entry.OriginalSha1Hash; Assert.AreEqual( TestHelper.HashToHex(localFileHash), TestHelper.HashToHex(databaseHash), "Local file hash does not match database hash."); Pre.Assert(oneDriveAdapter != null, "oneDriveAdapter != null"); var adapterEntry = entryResult.Entry.AdapterEntries.First(e => e.AdapterId == oneDriveAdapter.Configuration.Id); string itemId = adapterEntry.AdapterEntryId; var item = client.GetItemByItemIdAsync(itemId); var oneDriveHash = "0x" + item.Result.File.Hashes.Sha1Hash; Assert.AreEqual( TestHelper.HashToHex(localFileHash), oneDriveHash, "Local file hash does not match OneDrive hash."); } } }