public void TestNoFiltering() { FilteringDirectoryNode d = new FilteringDirectoryNode(fs.Root, new HashSet <string>()); Assert.AreEqual(3, d.EntryCount); Assert.AreEqual(dirA.Name, d.GetEntry(dirA.Name).Name); Assert.AreEqual(true, d.GetEntry(dirA.Name).IsDirectoryEntry); Assert.AreEqual(false, d.GetEntry(dirA.Name).IsDocumentEntry); Assert.AreEqual(true, d.GetEntry(dirB.Name).IsDirectoryEntry); Assert.AreEqual(false, d.GetEntry(dirB.Name).IsDocumentEntry); Assert.AreEqual(false, d.GetEntry(eRoot.Name).IsDirectoryEntry); Assert.AreEqual(true, d.GetEntry(eRoot.Name).IsDocumentEntry); IEnumerator <Entry> i = d.Entries; i.MoveNext(); Assert.AreEqual(dirA, i.Current); i.MoveNext(); Assert.AreEqual(dirB, i.Current); i.MoveNext(); Assert.AreEqual(eRoot, i.Current); i.MoveNext(); Assert.AreEqual(null, i.Current); }
public void TestNestedFiltering() { List <string> excl = new List <string>(new string[] { dirA.Name + "/" + "MadeUp", dirA.Name + "/" + eA.Name, dirA.Name + "/" + dirAA.Name + "/Test", eRoot.Name }); FilteringDirectoryNode d = new FilteringDirectoryNode(fs.Root, excl); // Check main Assert.AreEqual(2, d.EntryCount); Assert.AreEqual(true, d.HasEntry(dirA.Name)); Assert.AreEqual(true, d.HasEntry(dirB.Name)); Assert.AreEqual(false, d.HasEntry(eRoot.Name)); // Check filtering down Assert.AreEqual(true, d.GetEntry(dirA.Name) is FilteringDirectoryNode); Assert.AreEqual(false, d.GetEntry(dirB.Name) is FilteringDirectoryNode); DirectoryEntry fdA = (DirectoryEntry)d.GetEntry(dirA.Name); Assert.AreEqual(false, fdA.HasEntry(eA.Name)); Assert.AreEqual(true, fdA.HasEntry(dirAA.Name)); DirectoryEntry fdAA = (DirectoryEntry)fdA.GetEntry(dirAA.Name); Assert.AreEqual(true, fdAA.HasEntry(eAA.Name)); }
public void TestNoFiltering() { FilteringDirectoryNode d = new FilteringDirectoryNode(fs.Root, new HashSet<String>()); Assert.AreEqual(3, d.EntryCount); Assert.AreEqual(dirA.Name, d.GetEntry(dirA.Name).Name); Assert.AreEqual(true, d.GetEntry(dirA.Name).IsDirectoryEntry); Assert.AreEqual(false, d.GetEntry(dirA.Name).IsDocumentEntry); Assert.AreEqual(true, d.GetEntry(dirB.Name).IsDirectoryEntry); Assert.AreEqual(false, d.GetEntry(dirB.Name).IsDocumentEntry); Assert.AreEqual(false, d.GetEntry(eRoot.Name).IsDirectoryEntry); Assert.AreEqual(true, d.GetEntry(eRoot.Name).IsDocumentEntry); IEnumerator<Entry> i = d.Entries; i.MoveNext(); Assert.AreEqual(dirA, i.Current); i.MoveNext(); Assert.AreEqual(dirB, i.Current); i.MoveNext(); Assert.AreEqual(eRoot, i.Current); i.MoveNext(); Assert.AreEqual(null, i.Current); }
/** * Copies nodes from one Directory to the other minus the excepts * * @param filteredSource The filtering source Directory to copy from * @param filteredTarget The filtering target Directory to copy to */ public static void CopyNodes(FilteringDirectoryNode filteredSource, FilteringDirectoryNode filteredTarget) { // Nothing special here, just overloaded types to make the // recommended new way to handle this clearer CopyNodes((DirectoryEntry)filteredSource, (DirectoryEntry)filteredTarget); }
public void TestAreDirectoriesIdentical() { POIFSFileSystem fs = new POIFSFileSystem(); DirectoryEntry dirA = fs.CreateDirectory("DirA"); DirectoryEntry dirB = fs.CreateDirectory("DirB"); // Names must match Assert.AreEqual(false, EntryUtils.AreDirectoriesIdentical(dirA, dirB)); // Empty dirs are fine DirectoryEntry dirA1 = dirA.CreateDirectory("TheDir"); DirectoryEntry dirB1 = dirB.CreateDirectory("TheDir"); Assert.AreEqual(0, dirA1.EntryCount); Assert.AreEqual(0, dirB1.EntryCount); Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(dirA1, dirB1)); // Otherwise children must match dirA1.CreateDocument("Entry1", new ByteArrayInputStream(dataSmallA)); Assert.AreEqual(false, EntryUtils.AreDirectoriesIdentical(dirA1, dirB1)); dirB1.CreateDocument("Entry1", new ByteArrayInputStream(dataSmallA)); Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(dirA1, dirB1)); dirA1.CreateDirectory("DD"); Assert.AreEqual(false, EntryUtils.AreDirectoriesIdentical(dirA1, dirB1)); dirB1.CreateDirectory("DD"); Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(dirA1, dirB1)); // Excludes support List<String> excl = new List<string>(new String[] { "Ignore1", "IgnDir/Ign2" }); FilteringDirectoryNode fdA = new FilteringDirectoryNode(dirA1, excl); FilteringDirectoryNode fdB = new FilteringDirectoryNode(dirB1, excl); Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(fdA, fdB)); // Add an ignored doc, no notice is taken fdA.CreateDocument("Ignore1", new ByteArrayInputStream(dataSmallA)); Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(fdA, fdB)); // Add a directory with filtered contents, not the same DirectoryEntry dirAI = dirA1.CreateDirectory("IgnDir"); Assert.AreEqual(false, EntryUtils.AreDirectoriesIdentical(fdA, fdB)); DirectoryEntry dirBI = dirB1.CreateDirectory("IgnDir"); Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(fdA, fdB)); // Add something to the filtered subdir that gets ignored dirAI.CreateDocument("Ign2", new ByteArrayInputStream(dataSmallA)); Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(fdA, fdB)); // And something that doesn't dirAI.CreateDocument("IgnZZ", new ByteArrayInputStream(dataSmallA)); Assert.AreEqual(false, EntryUtils.AreDirectoriesIdentical(fdA, fdB)); dirBI.CreateDocument("IgnZZ", new ByteArrayInputStream(dataSmallA)); Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(fdA, fdB)); }
public void TestAreDirectoriesIdentical() { POIFSFileSystem fs = new POIFSFileSystem(); DirectoryEntry dirA = fs.CreateDirectory("DirA"); DirectoryEntry dirB = fs.CreateDirectory("DirB"); // Names must match Assert.AreEqual(false, EntryUtils.AreDirectoriesIdentical(dirA, dirB)); // Empty dirs are fine DirectoryEntry dirA1 = dirA.CreateDirectory("TheDir"); DirectoryEntry dirB1 = dirB.CreateDirectory("TheDir"); Assert.AreEqual(0, dirA1.EntryCount); Assert.AreEqual(0, dirB1.EntryCount); Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(dirA1, dirB1)); // Otherwise children must match dirA1.CreateDocument("Entry1", new ByteArrayInputStream(dataSmallA)); Assert.AreEqual(false, EntryUtils.AreDirectoriesIdentical(dirA1, dirB1)); dirB1.CreateDocument("Entry1", new ByteArrayInputStream(dataSmallA)); Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(dirA1, dirB1)); dirA1.CreateDirectory("DD"); Assert.AreEqual(false, EntryUtils.AreDirectoriesIdentical(dirA1, dirB1)); dirB1.CreateDirectory("DD"); Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(dirA1, dirB1)); // Excludes support List <String> excl = new List <string>(new String[] { "Ignore1", "IgnDir/Ign2" }); FilteringDirectoryNode fdA = new FilteringDirectoryNode(dirA1, excl); FilteringDirectoryNode fdB = new FilteringDirectoryNode(dirB1, excl); Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(fdA, fdB)); // Add an ignored doc, no notice is taken fdA.CreateDocument("Ignore1", new ByteArrayInputStream(dataSmallA)); Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(fdA, fdB)); // Add a directory with filtered contents, not the same DirectoryEntry dirAI = dirA1.CreateDirectory("IgnDir"); Assert.AreEqual(false, EntryUtils.AreDirectoriesIdentical(fdA, fdB)); DirectoryEntry dirBI = dirB1.CreateDirectory("IgnDir"); Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(fdA, fdB)); // Add something to the filtered subdir that gets ignored dirAI.CreateDocument("Ign2", new ByteArrayInputStream(dataSmallA)); Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(fdA, fdB)); // And something that doesn't dirAI.CreateDocument("IgnZZ", new ByteArrayInputStream(dataSmallA)); Assert.AreEqual(false, EntryUtils.AreDirectoriesIdentical(fdA, fdB)); dirBI.CreateDocument("IgnZZ", new ByteArrayInputStream(dataSmallA)); Assert.AreEqual(true, EntryUtils.AreDirectoriesIdentical(fdA, fdB)); }
public void TestChildFiltering() { List <string> excl = new List <string>(new string[] { "NotThere", "AlsoNotThere", eRoot.Name }); FilteringDirectoryNode d = new FilteringDirectoryNode(fs.Root, excl); Assert.AreEqual(2, d.EntryCount); Assert.AreEqual(true, d.HasEntry(dirA.Name)); Assert.AreEqual(true, d.HasEntry(dirB.Name)); Assert.AreEqual(false, d.HasEntry(eRoot.Name)); Assert.AreEqual(dirA, d.GetEntry(dirA.Name)); Assert.AreEqual(dirB, d.GetEntry(dirB.Name)); try { d.GetEntry(eRoot.Name); Assert.Fail("Should be filtered"); } catch (FileNotFoundException) { } IEnumerator <Entry> i = d.Entries; i.MoveNext(); Assert.AreEqual(dirA, i.Current); i.MoveNext(); Assert.AreEqual(dirB, i.Current); i.MoveNext(); Assert.AreEqual(null, i.Current); // Filter more excl = new List <string>(new string[] { "NotThere", "AlsoNotThere", eRoot.Name, dirA.Name }); d = new FilteringDirectoryNode(fs.Root, excl); Assert.AreEqual(1, d.EntryCount); Assert.AreEqual(false, d.HasEntry(dirA.Name)); Assert.AreEqual(true, d.HasEntry(dirB.Name)); Assert.AreEqual(false, d.HasEntry(eRoot.Name)); try { d.GetEntry(dirA.Name); Assert.Fail("Should be filtered"); } catch (FileNotFoundException) { } Assert.AreEqual(dirB, d.GetEntry(dirB.Name)); try { d.GetEntry(eRoot.Name); Assert.Fail("Should be filtered"); } catch (FileNotFoundException) { } i = d.Entries; i.MoveNext(); Assert.AreEqual(dirB, i.Current); i.MoveNext(); Assert.AreEqual(null, i.Current); // Filter everything excl = new List <string>(new string[] { "NotThere", eRoot.Name, dirA.Name, dirB.Name }); d = new FilteringDirectoryNode(fs.Root, excl); Assert.AreEqual(0, d.EntryCount); Assert.AreEqual(false, d.HasEntry(dirA.Name)); Assert.AreEqual(false, d.HasEntry(dirB.Name)); Assert.AreEqual(false, d.HasEntry(eRoot.Name)); try { d.GetEntry(dirA.Name); Assert.Fail("Should be filtered"); } catch (FileNotFoundException) { } try { d.GetEntry(dirB.Name); Assert.Fail("Should be filtered"); } catch (FileNotFoundException) { } try { d.GetEntry(eRoot.Name); Assert.Fail("Should be filtered"); } catch (FileNotFoundException) { } i = d.Entries; i.MoveNext(); Assert.AreEqual(null, i.Current); }
public void TestChildFiltering() { List<String> excl = new List<string>(new String[] { "NotThere", "AlsoNotThere", eRoot.Name }); FilteringDirectoryNode d = new FilteringDirectoryNode(fs.Root, excl); Assert.AreEqual(2, d.EntryCount); Assert.AreEqual(true, d.HasEntry(dirA.Name)); Assert.AreEqual(true, d.HasEntry(dirB.Name)); Assert.AreEqual(false, d.HasEntry(eRoot.Name)); Assert.AreEqual(dirA, d.GetEntry(dirA.Name)); Assert.AreEqual(dirB, d.GetEntry(dirB.Name)); try { d.GetEntry(eRoot.Name); Assert.Fail("Should be filtered"); } catch (FileNotFoundException) { } IEnumerator<Entry> i = d.Entries; i.MoveNext(); Assert.AreEqual(dirA, i.Current); i.MoveNext(); Assert.AreEqual(dirB, i.Current); i.MoveNext(); Assert.AreEqual(null, i.Current); // Filter more excl = new List<string>(new String[] { "NotThere", "AlsoNotThere", eRoot.Name, dirA.Name }); d = new FilteringDirectoryNode(fs.Root, excl); Assert.AreEqual(1, d.EntryCount); Assert.AreEqual(false, d.HasEntry(dirA.Name)); Assert.AreEqual(true, d.HasEntry(dirB.Name)); Assert.AreEqual(false, d.HasEntry(eRoot.Name)); try { d.GetEntry(dirA.Name); Assert.Fail("Should be filtered"); } catch (FileNotFoundException) { } Assert.AreEqual(dirB, d.GetEntry(dirB.Name)); try { d.GetEntry(eRoot.Name); Assert.Fail("Should be filtered"); } catch (FileNotFoundException) { } i = d.Entries; i.MoveNext(); Assert.AreEqual(dirB, i.Current); i.MoveNext(); Assert.AreEqual(null, i.Current); // Filter everything excl = new List<string>(new String[] { "NotThere", eRoot.Name, dirA.Name, dirB.Name }); d = new FilteringDirectoryNode(fs.Root, excl); Assert.AreEqual(0, d.EntryCount); Assert.AreEqual(false, d.HasEntry(dirA.Name)); Assert.AreEqual(false, d.HasEntry(dirB.Name)); Assert.AreEqual(false, d.HasEntry(eRoot.Name)); try { d.GetEntry(dirA.Name); Assert.Fail("Should be filtered"); } catch (FileNotFoundException) { } try { d.GetEntry(dirB.Name); Assert.Fail("Should be filtered"); } catch (FileNotFoundException) { } try { d.GetEntry(eRoot.Name); Assert.Fail("Should be filtered"); } catch (FileNotFoundException) { } i = d.Entries; i.MoveNext(); Assert.AreEqual(null, i.Current); }
public void TestNestedFiltering() { List<String> excl = new List<string>(new String[] { dirA.Name+"/"+"MadeUp", dirA.Name+"/"+eA.Name, dirA.Name+"/"+dirAA.Name+"/Test", eRoot.Name }); FilteringDirectoryNode d = new FilteringDirectoryNode(fs.Root, excl); // Check main Assert.AreEqual(2, d.EntryCount); Assert.AreEqual(true, d.HasEntry(dirA.Name)); Assert.AreEqual(true, d.HasEntry(dirB.Name)); Assert.AreEqual(false, d.HasEntry(eRoot.Name)); // Check filtering down Assert.AreEqual(true, d.GetEntry(dirA.Name) is FilteringDirectoryNode); Assert.AreEqual(false, d.GetEntry(dirB.Name) is FilteringDirectoryNode); DirectoryEntry fdA = (DirectoryEntry)d.GetEntry(dirA.Name); Assert.AreEqual(false, fdA.HasEntry(eA.Name)); Assert.AreEqual(true, fdA.HasEntry(dirAA.Name)); DirectoryEntry fdAA = (DirectoryEntry)fdA.GetEntry(dirAA.Name); Assert.AreEqual(true, fdAA.HasEntry(eAA.Name)); }