Beispiel #1
0
        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);
        }
Beispiel #2
0
        public TestWrapper <TSource, TDestination> CreateBasicSourceStructure()
        {
            WindowsFileSystemAdapter sourceAdapter = this.SourceAdapter as WindowsFileSystemAdapter;

            if (sourceAdapter == null)
            {
                throw new NotImplementedException();
            }

            if (this.SyncFileList == null)
            {
                this.SyncFileList = new List <string>();
            }

            this.SyncFileList.AddRange(new List <string>
            {
                TestHelper.CreateDirectory(sourceAdapter.Config.RootDirectory, "dir1"),
                TestHelper.CreateFile(sourceAdapter.Config.RootDirectory, "dir1\\file1.txt"),
                TestHelper.CreateFile(sourceAdapter.Config.RootDirectory, "dir1\\file2.txt"),
                TestHelper.CreateFile(sourceAdapter.Config.RootDirectory, "dir1\\file3.txt"),
                TestHelper.CreateDirectory(sourceAdapter.Config.RootDirectory, "dir2"),
                TestHelper.CreateFile(sourceAdapter.Config.RootDirectory, "dir2\\file1.txt"),
                TestHelper.CreateFile(sourceAdapter.Config.RootDirectory, "dir2\\file2.txt"),
                TestHelper.CreateFile(sourceAdapter.Config.RootDirectory, "dir2\\file3.txt"),
                TestHelper.CreateDirectory(sourceAdapter.Config.RootDirectory, "dir2\\dir3"),
                TestHelper.CreateDirectory(sourceAdapter.Config.RootDirectory, "dir2\\dir3\\dir4"),
                TestHelper.CreateFile(sourceAdapter.Config.RootDirectory, "dir2\\dir3\\dir4\\file100.txt"),
                TestHelper.CreateFile(sourceAdapter.Config.RootDirectory, "dir2\\dir3\\dir4\\file101.txt"),
                TestHelper.CreateFile(sourceAdapter.Config.RootDirectory, "dir2\\dir3\\dir4\\file102.txt"),
            });

            return(this);
        }
Beispiel #3
0
        public void BasicAnalyzeOnly()
        {
            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);
            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();

            ManualResetEvent evt = new ManualResetEvent(false);

            AnalyzeJob run1 = new AnalyzeJob(newRelationship);

            run1.Finished += (sender, args) => { evt.Set(); };
            bool finished = run1.Start().Wait(60000);

            // 10min max wait time
            if (!finished)
            {
                Assert.Fail("Timeout");
            }

            Assert.IsTrue(run1.HasFinished);
        }
Beispiel #4
0
        public TestWrapper <TSource, TDestination> CopySourceStructureToDestination()
        {
            WindowsFileSystemAdapter sourceAdapter = this.SourceAdapter as WindowsFileSystemAdapter;
            WindowsFileSystemAdapter destAdapter   = this.DestinationAdapter as WindowsFileSystemAdapter;

            if (sourceAdapter == null)
            {
                throw new NotImplementedException();
            }

            if (destAdapter == null)
            {
                throw new NotImplementedException();
            }

            DirectoryCopy(
                sourceAdapter.Config.RootDirectory,
                destAdapter.Config.RootDirectory,
                true);

            return(this);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
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);
        }
Beispiel #8
0
        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.");
                }
            }
        }
Beispiel #9
0
        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 WindowsFileSystemAdapterViewModel(WindowsFileSystemAdapter adapter)
     : base(adapter)
 {
     this.BrowsePathCommand = new DelegatedCommand(this.BrowsePath);
 }