[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();
        }
        [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();
        }
        public void TestBadPath()
        {
            FindFile ff = new FindFile("C:\\?#%)(#!&_~&)@%^&%~_#()!$\"*@(#_)~*");

            ff.FileFound += (o, e) => Assert.Fail("Should not find a file");
            ff.Find();
        }
        public void TestBadFilePattern()
        {
            FindFile ff = new FindFile();

            ff.FileFound += (o, e) => Assert.Fail("Should not find a file");
            ff.Find("\":^|&");
        }
        public void TestDriveNotFound()
        {
            FindFile ff = new FindFile("ZZZ:\\WTF", "*");

            ff.FileFound += (o, e) => Assert.Fail("Should not find a file");
            ff.Find();
        }
        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();
        }
        public void TestFileNotFound()
        {
            FindFile ff = new FindFile(TestFolder, "foo", false, false);

            ff.FileFound += (o, e) => Assert.Fail("Should not find a file");
            ff.Find();
        }
        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);
        }
        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);
            }
        }
        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();
        }