private static AdapterBase GetAdapter(Dictionary <string, string> args) { SyncRelationship relationship = GetRelationship(args); string strAdapterId; if (!args.TryGetValue("adapterId", out strAdapterId)) { throw new Exception("/adapterId parameter not provided."); } int adapterId = int.Parse(strAdapterId); AdapterBase adapter = relationship.Adapters.FirstOrDefault(a => a.Configuration.Id == adapterId); if (adapter == null) { throw new Exception("No adapter found with ID " + adapterId); } return(adapter); }
private SyncRelationship SetupRelationship(string testRootPath, string syncSourcePath, Item syncDestinationPath) { Global.Initialize(testRootPath); SyncRelationship newRelationship = SyncRelationship.Create(); WindowsFileSystemAdapter sourceAdapter = new WindowsFileSystemAdapter(newRelationship); sourceAdapter.Config.RootDirectory = syncSourcePath; sourceAdapter.Configuration.IsOriginator = true; OneDriveAdapter destAdapter = new OneDriveAdapter(newRelationship) { CurrentToken = GetCurrentToken(), }; destAdapter.Config.TargetPath = "OneDrive/Testing/" + syncDestinationPath.Name; destAdapter.InitializeClient().Wait(); 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(); foreach (AdapterBase adapter in newRelationship.Adapters) { adapter.InitializeAsync().Wait(); } return(newRelationship); }
public AzureStorageAdapter(SyncRelationship relationship) : base(relationship, new AzureStorageAdapterConfiguration()) { }
public AzureStorageAdapter(SyncRelationship relationship, AdapterConfiguration configuration) : base(relationship, configuration) { }
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."); } } }
protected abstract TAdapter CreateDestinationAdapter(SyncRelationship newRelationship, string testMethodName);
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."); } } }
protected override OneDriveAdapter CreateDestinationAdapter(SyncRelationship newRelationship, string testMethodName) { throw new NotImplementedException(); }
public OneDriveAdapter(SyncRelationship relationship, OneDriveAdapterConfiguration configuration) : base(relationship, configuration) { }
public OneDriveAdapter(SyncRelationship relationship) : base(relationship, new OneDriveAdapterConfiguration()) { }
public WindowsFileSystemAdapter(SyncRelationship relationship) : base(relationship, new WindowsFileSystemAdapterConfiguration()) { }