private void CreateFile(string basePath, string filePath, CreateDirective directive) { var rootAFile = Path.Combine(basePath, RootA, filePath); var rootBFile = Path.Combine(basePath, RootB, filePath); switch (directive) { case CreateDirective.OnlyInA: WriteFile(rootAFile, December2017); break; case CreateDirective.OnlyInB: WriteFile(rootBFile, December2017); break; case CreateDirective.RootANewer: WriteFile(rootAFile, December2017); WriteFile(rootBFile, June2016); break; case CreateDirective.RootBNewer: WriteFile(rootAFile, June2016); WriteFile(rootBFile, December2017); break; case CreateDirective.SameAge: WriteFile(rootAFile, December2017); WriteFile(rootBFile, December2017); break; } }
private void HelperTest_Status(CreateDirective directive) { InitializeTest(out string basePath); var filePath = "File1.txt"; CreateFile(basePath, filePath, directive); var replInfo = new ReplInfo(filePath, Roots); var status = replInfo.Status(); if (directive == CreateDirective.OnlyInA || directive == CreateDirective.OnlyInB) { // File does not exist across all roots Assert.AreEqual(ReplicationStatus.IncompleteReplication, status); } else if (directive == CreateDirective.RootANewer || directive == CreateDirective.RootBNewer) { // One file n the roots are is more recent Assert.AreEqual(ReplicationStatus.WriteDateMismatch, status); } else if (directive == CreateDirective.SameAge) { // Replication has completed and the files are the same age Assert.AreEqual(ReplicationStatus.Synced, status); } }
private void HelperTest_Sync(CreateDirective directive) { InitializeTest(out string basePath); var filePath = "File1.txt"; CreateFile(basePath, filePath, directive); var replInfo = new ReplInfo(filePath, Roots); var status = replInfo.Sync(); var aPath = Path.Combine(Roots[IndexRootA], filePath); var bPath = Path.Combine(Roots[IndexRootB], filePath); switch (directive) { case CreateDirective.OnlyInA: Assert.IsTrue(File.Exists(bPath)); Assert.AreEqual(December2017, GetLastWriteDate(bPath)); Assert.AreEqual(ReplicationStatus.Synced, status); break; case CreateDirective.OnlyInB: Assert.IsTrue(File.Exists(aPath)); Assert.AreEqual(December2017, GetLastWriteDate(aPath)); Assert.AreEqual(ReplicationStatus.Synced, status); break; case CreateDirective.RootANewer: Assert.IsTrue(File.Exists(bPath)); Assert.AreEqual(December2017, GetLastWriteDate(bPath)); Assert.AreEqual(ReplicationStatus.Synced, status); break; case CreateDirective.RootBNewer: Assert.IsTrue(File.Exists(aPath)); Assert.AreEqual(December2017, GetLastWriteDate(aPath)); Assert.AreEqual(ReplicationStatus.Synced, status); break; case CreateDirective.SameAge: Assert.AreEqual(ReplicationStatus.Synced, status); break; } }
private void HelperTest_Constructor(CreateDirective directive) { InitializeTest(out string basePath); var filePath = "File1.txt"; CreateFile(basePath, filePath, directive); var replInfo = new ReplInfo(filePath, Roots); // Assert all roots are present for (var rootId = 0; rootId < replInfo.Roots.Count; rootId++) { Assert.AreEqual(Roots[rootId], replInfo.Roots[rootId]); } // Assert that the Removed flag is false Assert.IsFalse(replInfo.Removed); }
private void HelperTest_Remove(CreateDirective directive) { InitializeTest(out string basePath); var filePath = "File1.txt"; CreateFile(basePath, filePath, directive); var replInfo = new ReplInfo(filePath, Roots); var aPath = Path.Combine(Roots[IndexRootA], filePath); var bPath = Path.Combine(Roots[IndexRootB], filePath); var status = replInfo.Remove(); Assert.AreEqual(ReplicationStatus.Removed, status); Assert.IsFalse(File.Exists(aPath)); Assert.IsFalse(File.Exists(bPath)); }
private void HelperTest_GetFileDictionary(CreateDirective directive) { InitializeTest(out string basePath); var filePath = "File1.txt"; CreateFile(basePath, filePath, directive); var replInfo = new ReplInfo(filePath, Roots); var files = replInfo.GetFileDictionary(); if (directive != CreateDirective.OnlyInB) { Assert.IsNotNull(files[IndexRootA]); Assert.AreEqual(files[IndexRootA].Name, filePath); } if (directive != CreateDirective.OnlyInA) { Assert.IsNotNull(files[IndexRootB]); Assert.AreEqual(files[IndexRootB].Name, filePath); } }