Esempio n. 1
0
 [Test, ExpectedException(typeof(System.ComponentModel.Win32Exception))]// : The specified path is invalid
 public void TestPathError()
 {
     FindFile ff = new FindFile(@"\\\", "*", false, false);
     ff.FileFound += (o, e) => Assert.Fail("Should not find a file");
     ff.Find();
 }
Esempio n. 2
0
        public void TestAccessDenied()
        {
            string child2 = Path.Combine(TestFolder, @"child1\child2");
            
            DirectorySecurity acl = Directory.GetAccessControl(child2);
            byte[] original = acl.GetSecurityDescriptorBinaryForm();
            acl.AddAccessRule(
                new FileSystemAccessRule(
                    new SecurityIdentifier(WellKnownSidType.WorldSid, null),
                    FileSystemRights.ListDirectory,
                    AccessControlType.Deny)
                );
            Directory.SetAccessControl(child2, acl);
            try
            {
                //By default it ignores AccessDenied
                FindFile ff = new FindFile(child2, "*", false, false);
                ff.FileFound += (o, e) => Assert.Fail("Should not find a file");
                ff.Find();

                //Now raise the AccessDenied
                ff.RaiseOnAccessDenied = true;
                try
                {
                    ff.Find();
                    Assert.Fail("Should throw Access Denied.");
                }
                catch(System.ComponentModel.Win32Exception we)
                { Assert.AreEqual(5, we.NativeErrorCode); }
            }
            finally
            {
                acl.SetSecurityDescriptorBinaryForm(original, AccessControlSections.All);
                Directory.SetAccessControl(child2, acl);
            }
        }
Esempio n. 3
0
 public void TestBadFilePattern()
 {
     FindFile ff = new FindFile();
     ff.FileFound += (o, e) => Assert.Fail("Should not find a file");
     ff.Find("\":^|&");
 }
Esempio n. 4
0
 [Test, ExpectedException(typeof(System.ComponentModel.Win32Exception))]// : The network path was not found
 public void TestServerNotFound()
 {
     FindFile ff = new FindFile(@"\\127.0.0.2\C$", "*", false, false);
     ff.FileFound += (o, e) => Assert.Fail("Should not find a file");
     ff.Find();
 }
Esempio n. 5
0
 public void TestDriveNotFound()
 {
     FindFile ff = new FindFile("ZZZ:\\WTF", "*");
     ff.FileFound += (o, e) => Assert.Fail("Should not find a file");
     ff.Find();
 }
Esempio n. 6
0
 public void TestBadPath()
 {
     FindFile ff = new FindFile("C:\\?#%)(#!&_~&)@%^&%~_#()!$\"*@(#_)~*");
     ff.FileFound += (o, e) => Assert.Fail("Should not find a file");
     ff.Find();
 }
Esempio n. 7
0
 public void TestPathNotFound()
 {
     FindFile ff = new FindFile(Path.Combine(TestFolder, "foo"), "*", false);
     ff.FileFound += (o, e) => Assert.Fail("Should not find a file");
     ff.Find();
 }
Esempio n. 8
0
 public void TestFileNotFound()
 {
     FindFile ff = new FindFile(TestFolder, "foo", false, false);
     ff.FileFound += (o, e) => Assert.Fail("Should not find a file");
     ff.Find();
 }
Esempio n. 9
0
        public void TestFindFileByPattern()
        {
            List<string> found = new List<string>();
            FindFile ff = new FindFile(TestFolder, "a.*", true, true, true);
            ff.FileFound += (o, e) => found.Add(e.FullPath);
            ff.Find();

            Assert.AreEqual(2, found.Count);
        }
Esempio n. 10
0
        public void TestFindFileProperties()
        {
            FindFile ff = new FindFile();
            Assert.AreEqual("", ff.BaseDirectory);
            Assert.AreEqual("*", ff.FilePattern);
            Assert.AreEqual(true, ff.Recursive);
            Assert.AreEqual(true, ff.IncludeFiles);
            Assert.AreEqual(true, ff.IncludeFolders);
            Assert.AreEqual(false, ff.RaiseOnAccessDenied);
            Assert.AreEqual(4096, ff.MaxPath);

            Assert.AreEqual(TestFolder, ff.BaseDirectory = TestFolder);
            Assert.AreEqual("a.*", ff.FilePattern = "a.*");
            Assert.AreEqual(false, ff.Recursive = false);
            Assert.AreEqual(false, ff.IncludeFiles = false);
            Assert.AreEqual(false, ff.IncludeFolders = false);
            Assert.AreEqual(true, ff.RaiseOnAccessDenied = true);
            Assert.AreEqual(1024, ff.MaxPath = 1024);

            ff.FileFound += (o, e) => Assert.Fail("Should not find anything.");
            ff.Find();
        }
Esempio n. 11
0
 /// <summary> Enumerates the files and folders anywhere under the directory specified </summary>
 public static void AllFilesAndFoldersIn(string directory, Action<FileFoundEventArgs> e)
 {
     FindFile ff = new FindFile(directory, STAR, true, true, true);
     ff.FileFound = (o, a) => e(a);
     ff.Find();
 }