public void EnumerateSingleEntryListWithWildcardFilter()
        {
            List <ProjectedFileInfo> entries = new List <ProjectedFileInfo>()
            {
                new ProjectedFileInfo("a", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 1))
            };

            ActiveEnumeration activeEnumeration = CreateActiveEnumeration(entries);

            activeEnumeration.TrySaveFilterString("*").ShouldEqual(true);
            this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries);

            activeEnumeration = CreateActiveEnumeration(entries);
            activeEnumeration.TrySaveFilterString("?").ShouldEqual(true);
            this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries);

            activeEnumeration = CreateActiveEnumeration(entries);
            string filter = "*.*";

            activeEnumeration.TrySaveFilterString(filter).ShouldEqual(true);

            // "*.*" should only match when there is a . in the name
            activeEnumeration.IsCurrentValid.ShouldEqual(false);
            activeEnumeration.Current.ShouldEqual(null);

            activeEnumeration.MoveNext().ShouldEqual(false);
            activeEnumeration.IsCurrentValid.ShouldEqual(false);
            activeEnumeration.Current.ShouldEqual(null);

            activeEnumeration.RestartEnumeration(filter);
            activeEnumeration.IsCurrentValid.ShouldEqual(false);
            activeEnumeration.Current.ShouldEqual(null);
        }
        public void CannotSetMoreThanOneFilter()
        {
            string filterString = "*.*";

            ActiveEnumeration activeEnumeration = CreateActiveEnumeration(new List <ProjectedFileInfo>());

            activeEnumeration.TrySaveFilterString(filterString).ShouldEqual(true);
            activeEnumeration.TrySaveFilterString(null).ShouldEqual(false);
            activeEnumeration.TrySaveFilterString(string.Empty).ShouldEqual(false);
            activeEnumeration.TrySaveFilterString("?").ShouldEqual(false);
            activeEnumeration.GetFilterString().ShouldEqual(filterString);
        }
Exemplo n.º 3
0
        public void RestartingScanWithFilterAdvancesEnumeratorToNewMatchingEntry()
        {
            List <ProjectedFileInfo> entries = new List <ProjectedFileInfo>()
            {
                new ProjectedFileInfo("a", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 1)),
                new ProjectedFileInfo("B", size: 0, isFolder: true, sha: Sha1Id.None),
                new ProjectedFileInfo("c", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 2)),
                new ProjectedFileInfo("D.txt", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 3)),
                new ProjectedFileInfo("E.txt", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 4)),
                new ProjectedFileInfo("E.bat", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 5)),
            };

            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.Current.ShouldBeSameAs(entries[0]);
                activeEnumeration.TrySaveFilterString("D.txt").ShouldEqual(true);
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.Current.Name.ShouldEqual("D.txt");

                activeEnumeration.RestartEnumeration("c");
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.Current.Name.ShouldEqual("c");
            }
        }
Exemplo n.º 4
0
        public void EnumerateMultipleEntryListWithMatchingFilter()
        {
            List <ProjectedFileInfo> entries = new List <ProjectedFileInfo>()
            {
                new ProjectedFileInfo("a", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 1)),
                new ProjectedFileInfo("B", size: 0, isFolder: true, sha: Sha1Id.None),
                new ProjectedFileInfo("c", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 2)),
                new ProjectedFileInfo("D.txt", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 3)),
                new ProjectedFileInfo("E.txt", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 4)),
                new ProjectedFileInfo("E.bat", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 5)),
            };

            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.TrySaveFilterString("E.bat").ShouldEqual(true);
                this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries.Where(entry => entry.Name == "E.bat"));
            }

            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.TrySaveFilterString("e.bat").ShouldEqual(true);
                this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries.Where(entry => string.Compare(entry.Name, "e.bat", StringComparison.OrdinalIgnoreCase) == 0));
            }
        }
Exemplo n.º 5
0
        public void EnumerateMultipleEntryListWithEmptyFilter()
        {
            List <ProjectedFileInfo> entries = new List <ProjectedFileInfo>()
            {
                new ProjectedFileInfo("a", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 1)),
                new ProjectedFileInfo("B", size: 0, isFolder: true, sha: Sha1Id.None),
                new ProjectedFileInfo("c", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 2)),
                new ProjectedFileInfo("D.txt", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 3)),
                new ProjectedFileInfo("E.txt", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 4)),
                new ProjectedFileInfo("E.bat", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 5)),
            };

            // Test empty string ("") filter
            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.TrySaveFilterString(string.Empty).ShouldEqual(true);
                this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries);
            }

            // Test null filter
            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.TrySaveFilterString(null).ShouldEqual(true);
                this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries);
            }
        }
        public void EnumerateSingleEntryListWithMatchingFilter()
        {
            List <ProjectedFileInfo> entries = new List <ProjectedFileInfo>()
            {
                new ProjectedFileInfo("a", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 1))
            };

            ActiveEnumeration activeEnumeration = CreateActiveEnumeration(entries);

            activeEnumeration.TrySaveFilterString("a").ShouldEqual(true);
            this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries);

            activeEnumeration = CreateActiveEnumeration(entries);
            activeEnumeration.TrySaveFilterString("A").ShouldEqual(true);
            this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries);
        }
        public void EnumerateSingleEntryListWithEmptyFilter()
        {
            List <ProjectedFileInfo> entries = new List <ProjectedFileInfo>()
            {
                new ProjectedFileInfo("a", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 1))
            };

            // Test empty string ("") filter
            ActiveEnumeration activeEnumeration = CreateActiveEnumeration(entries);

            activeEnumeration.TrySaveFilterString(string.Empty).ShouldEqual(true);
            this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries);

            // Test null filter
            activeEnumeration = CreateActiveEnumeration(entries);
            activeEnumeration.TrySaveFilterString(null).ShouldEqual(true);
            this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries);
        }
Exemplo n.º 8
0
        public void EnumerateSingleEntryListWithNonMatchingFilter()
        {
            List <ProjectedFileInfo> entries = new List <ProjectedFileInfo>()
            {
                new ProjectedFileInfo("a", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 1))
            };

            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                string filter = "b";
                activeEnumeration.TrySaveFilterString(filter).ShouldEqual(true);
                activeEnumeration.IsCurrentValid.ShouldEqual(false);
                activeEnumeration.MoveNext().ShouldEqual(false);
                activeEnumeration.RestartEnumeration(filter);
                activeEnumeration.IsCurrentValid.ShouldEqual(false);
            }
        }
        public void SettingFilterAdvancesEnumeratorToMatchingEntry()
        {
            List <ProjectedFileInfo> entries = new List <ProjectedFileInfo>()
            {
                new ProjectedFileInfo("a", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 1)),
                new ProjectedFileInfo("B", size: 0, isFolder: true, sha: Sha1Id.None),
                new ProjectedFileInfo("c", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 2)),
                new ProjectedFileInfo("D.txt", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 3)),
                new ProjectedFileInfo("E.txt", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 4)),
                new ProjectedFileInfo("E.bat", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 5)),
            };

            ActiveEnumeration activeEnumeration = CreateActiveEnumeration(entries);

            activeEnumeration.TrySaveFilterString("D.txt").ShouldEqual(true);
            activeEnumeration.IsCurrentValid.ShouldEqual(true);
            activeEnumeration.Current.Name.ShouldEqual("D.txt");
        }
Exemplo n.º 10
0
        public void RestartingScanWithFilterAdvancesEnumeratorToFirstMatchingEntry()
        {
            List <ProjectedFileInfo> entries = new List <ProjectedFileInfo>()
            {
                new ProjectedFileInfo("C.TXT", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 1)),
                new ProjectedFileInfo("D.txt", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 2)),
                new ProjectedFileInfo("E.txt", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 3)),
                new ProjectedFileInfo("E.bat", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 4)),
            };

            ActiveEnumeration activeEnumeration = CreateActiveEnumeration(entries);

            activeEnumeration.TrySaveFilterString("D.txt").ShouldEqual(true);
            activeEnumeration.IsCurrentValid.ShouldEqual(true);
            activeEnumeration.Current.Name.ShouldEqual("D.txt");

            activeEnumeration.RestartEnumeration("c*");
            activeEnumeration.IsCurrentValid.ShouldEqual(true);
            activeEnumeration.Current.Name.ShouldEqual("C.TXT");
        }
Exemplo n.º 11
0
        public void EnumerateMultipleEntryListWithNonMatchingFilter()
        {
            List <ProjectedFileInfo> entries = new List <ProjectedFileInfo>()
            {
                new ProjectedFileInfo("a", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 1)),
                new ProjectedFileInfo("B", size: 0, isFolder: true, sha: Sha1Id.None),
                new ProjectedFileInfo("c", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 2)),
                new ProjectedFileInfo("D.txt", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 3)),
                new ProjectedFileInfo("E.txt", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 4)),
                new ProjectedFileInfo("E.bat", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 5)),
            };

            ActiveEnumeration activeEnumeration = CreateActiveEnumeration(entries);
            string            filter            = "g";

            activeEnumeration.TrySaveFilterString(filter).ShouldEqual(true);
            activeEnumeration.IsCurrentValid.ShouldEqual(false);
            activeEnumeration.MoveNext().ShouldEqual(false);
            activeEnumeration.RestartEnumeration(filter);
            activeEnumeration.IsCurrentValid.ShouldEqual(false);
        }
Exemplo n.º 12
0
        public void EnumerateMultipleEntryListWithWildcardFilter()
        {
            List <ProjectedFileInfo> entries = new List <ProjectedFileInfo>()
            {
                new ProjectedFileInfo(".txt", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 1)),
                new ProjectedFileInfo("a", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 2)),
                new ProjectedFileInfo("B", size: 0, isFolder: true, sha: Sha1Id.None),
                new ProjectedFileInfo("c", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 3)),
                new ProjectedFileInfo("D.", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 4)),
                new ProjectedFileInfo("D.txt", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 5)),
                new ProjectedFileInfo("E..log", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 6)),
                new ProjectedFileInfo("E.txt", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 7)),
                new ProjectedFileInfo("E.bat", size: 0, isFolder: false, sha: new Sha1Id(1, 1, 8)),
            };

            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.TrySaveFilterString("*").ShouldEqual(true);
                this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries);
            }

            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.TrySaveFilterString("*.*").ShouldEqual(true);
                this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries.Where(entry => entry.Name.Contains(".")));
            }

            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.TrySaveFilterString("*.txt").ShouldEqual(true);
                this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries.Where(entry => entry.Name.EndsWith(".txt", System.StringComparison.OrdinalIgnoreCase)));
            }

            // '<' = DOS_STAR, matches 0 or more characters until encountering and matching
            //                 the final . in the name
            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.TrySaveFilterString("<.txt").ShouldEqual(true);
                this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries.Where(entry => entry.Name.EndsWith(".txt", System.StringComparison.OrdinalIgnoreCase)));
            }

            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.TrySaveFilterString("?").ShouldEqual(true);
                this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries.Where(entry => entry.Name.Length == 1));
            }

            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.TrySaveFilterString("?.txt").ShouldEqual(true);
                this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries.Where(entry => entry.Name.Length == 5 && entry.Name.EndsWith(".txt", System.StringComparison.OrdinalIgnoreCase)));
            }

            // '>' = DOS_QM, matches any single character, or upon encountering a period or
            //               end of name string, advances the expression to the end of the
            //               set of contiguous DOS_QMs.
            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.TrySaveFilterString(">.txt").ShouldEqual(true);
                this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries.Where(entry => entry.Name.Length <= 5 && entry.Name.EndsWith(".txt", System.StringComparison.OrdinalIgnoreCase)));
            }

            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.TrySaveFilterString("E.???").ShouldEqual(true);
                this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries.Where(entry => entry.Name.Length == 5 && entry.Name.StartsWith("E.", System.StringComparison.OrdinalIgnoreCase)));
            }

            // '"' = DOS_DOT, matches either a . or zero characters beyond name string.
            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.TrySaveFilterString("E\"*").ShouldEqual(true);
                this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries.Where(entry => entry.Name.StartsWith("E.", System.StringComparison.OrdinalIgnoreCase) || entry.Name.Equals("E", System.StringComparison.OrdinalIgnoreCase)));
            }

            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.TrySaveFilterString("e\"*").ShouldEqual(true);
                this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries.Where(entry => entry.Name.StartsWith("E.", System.StringComparison.OrdinalIgnoreCase) || entry.Name.Equals("E", System.StringComparison.OrdinalIgnoreCase)));
            }

            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.TrySaveFilterString("B\"*").ShouldEqual(true);
                this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries.Where(entry => entry.Name.StartsWith("B.", System.StringComparison.OrdinalIgnoreCase) || entry.Name.Equals("B", System.StringComparison.OrdinalIgnoreCase)));
            }

            using (ActiveEnumeration activeEnumeration = new ActiveEnumeration(entries))
            {
                activeEnumeration.IsCurrentValid.ShouldEqual(true);
                activeEnumeration.TrySaveFilterString("e.???").ShouldEqual(true);
                this.ValidateActiveEnumeratorReturnsAllEntries(activeEnumeration, entries.Where(entry => entry.Name.Length == 5 && entry.Name.StartsWith("E.", System.StringComparison.OrdinalIgnoreCase)));
            }
        }