示例#1
0
        public void Constructor()
        {
            try
            {
                ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(null);
            }
            catch (ArgumentNullException)
            {
                Assert.IsTrue(true);
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }

            try
            {
                ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(String.Empty);
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(true);
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }
        }
示例#2
0
        public void ToStringTest()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");
            Directory.CreateDirectory(path);

            DirectoryInfo di = new DirectoryInfo(path);
            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);
            Assert.IsNotNull(edi);

            Assert.AreEqual(di.ToString(), edi.ToString());
        }
示例#3
0
        public void SetAccessControl()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");
            Directory.CreateDirectory(path);

            DirectoryInfo di = new DirectoryInfo(path);
            DirectorySecurity expected = di.GetAccessControl(AccessControlSections.All);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);
            Assert.IsNotNull(edi);

            DirectorySecurity directorySecurity = new DirectorySecurity();
            directorySecurity.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow));

            edi.SetAccessControl(directorySecurity);

            Assert.AreNotEqual(expected.GetSecurityDescriptorBinaryForm(), edi.GetAccessControl().GetSecurityDescriptorBinaryForm());

            DirectorySecurity actualDirectorySecurity = Directory.GetAccessControl(path);
            AuthorizationRuleCollection rules = actualDirectorySecurity.GetAccessRules(true, true, typeof(NTAccount));
            foreach (AuthorizationRule rule in rules)
            {
                FileSystemAccessRule accessRule = (FileSystemAccessRule)rule;

                if (accessRule.IdentityReference.Value == "Everyone")
                {
                    Assert.IsTrue(accessRule.AccessControlType == AccessControlType.Allow);
                    Assert.IsTrue(accessRule.FileSystemRights == FileSystemRights.FullControl);
                }
            }

            di.SetAccessControl(expected);
        }
示例#4
0
        public void Serialization()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");
            Directory.CreateDirectory(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);
            Assert.IsNotNull(edi);
            byte[] data = null;

            using (MemoryStream stream = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(stream, edi);
                data = stream.ToArray();
            }

            Assert.IsNotNull(data);
            ConditionAssert.Greater(data.Length, 0);

            using (MemoryStream stream = new MemoryStream(data))
            {
                    BinaryFormatter bf = new BinaryFormatter();
                    ExtendedDirectoryInfo edi2 = bf.Deserialize(stream) as ExtendedDirectoryInfo;
                    Assert.IsNotNull(edi2);
                    Assert.AreEqual(edi.FullName, edi2.FullName);
            }
        }
示例#5
0
        public void Refresh()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");
            Directory.CreateDirectory(path);
            DirectoryInfo di = new DirectoryInfo(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);
            Assert.IsNotNull(edi);

            Assert.AreEqual(edi.Attributes, di.Attributes);

            di.Attributes |= FileAttributes.ReadOnly;
            edi.Refresh();

            Assert.AreEqual(edi.Attributes, di.Attributes);

            di.Attributes &= ~FileAttributes.ReadOnly;
        }
示例#6
0
        public void Properties2()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");
            Directory.CreateDirectory(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);
            Assert.IsNotNull(edi);

            edi.CreationTime = new DateTime(2006, 1, 1);

            DirectoryInfo di = new DirectoryInfo(path);

            Assert.AreEqual(edi.CreationTime, di.CreationTime);
        }
示例#7
0
        public void Properties()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");
            Directory.CreateDirectory(path);
            DirectoryInfo di = new DirectoryInfo(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);
            Assert.IsNotNull(edi);

            Assert.AreEqual(edi.Root.FullName, di.Root.FullName);
            Assert.AreEqual(edi.Parent.FullName, di.Parent.FullName);
            Assert.AreEqual(edi.Name, di.Name);
            Assert.AreEqual(edi.LastWriteTimUtc, di.LastWriteTimeUtc);
            Assert.AreEqual(edi.LastWriteTime, di.LastWriteTime);
            Assert.AreEqual(edi.LastAccessTimeUtc, di.LastAccessTimeUtc);
            Assert.AreEqual(edi.LastAccessTime, di.LastAccessTime);
            Assert.AreEqual(edi.FullName, di.FullName);
            Assert.AreEqual(edi.Extension, di.Extension);
            Assert.AreEqual(edi.Exists, di.Exists);
            Assert.AreEqual(edi.CreationTime, di.CreationTime);
            Assert.AreEqual(edi.CreateTimeUtc, di.CreationTimeUtc);
            Assert.AreEqual(edi.Attributes, di.Attributes);
        }
示例#8
0
        public void Delete1()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");
            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }

            Assert.IsFalse(Directory.Exists(path), "Unable to delete the test directory.");

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);
            Assert.IsNotNull(edi);

            string path2 = edi.CreateSubdirectory("Subdir").FullName;
            Assert.IsTrue(Directory.Exists(path));

            File.WriteAllText(Path.Combine(path2, "testfile.txt"), "This is a test.");
            edi.Delete(true);

            Assert.IsFalse(Directory.Exists(path), "Unable to delete the test directory.");
        }
示例#9
0
        public void GetFileSystemInfos1()
        {
            string path = Path.GetTempPath();
            DirectoryInfo di = new DirectoryInfo(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);
            Assert.IsNotNull(edi);

            FileSystemInfo[] actual = edi.GetFileSystemInfos("*");
            FileSystemInfo[] expected = di.GetFileSystemInfos("*");

            CustomAssert.IsNotEmpty(actual);
            CollectionAssert.AllItemsAreNotNull(actual);

            foreach (FileSystemInfo f in actual)
            {
                Assert.IsTrue(Array.Exists(expected,
                    delegate(FileSystemInfo o)
                    {
                        return (f.FullName == o.FullName);
                    }));
            }
        }
示例#10
0
        public void GetDirectories2()
        {
            string path = Path.GetTempPath();
            DirectoryInfo di = new DirectoryInfo(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);
            Assert.IsNotNull(edi);

            DirectoryInfo[] actual = edi.GetDirectories("*", SearchOption.TopDirectoryOnly);
            DirectoryInfo[] expected = di.GetDirectories("*", SearchOption.TopDirectoryOnly);

            CollectionAssert.AreEqual(expected, actual, ComparisonComparer<DirectoryInfo>.Create((a, b) => a.FullName.CompareTo(b.FullName)));

            foreach (DirectoryInfo d in actual)
            {
                Assert.IsTrue(Array.Exists(expected,
                    delegate(DirectoryInfo o)
                    {
                        return (d.FullName == o.FullName);
                    }));
            }
        }
示例#11
0
        public void GetAccessControl1()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");
            Directory.CreateDirectory(path);
            DirectoryInfo di = new DirectoryInfo(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);
            Assert.IsNotNull(edi);

            DirectorySecurity actual = edi.GetAccessControl(AccessControlSections.All);
            DirectorySecurity expected = di.GetAccessControl(AccessControlSections.All);

            CollectionAssert.AreEqual(expected.GetSecurityDescriptorBinaryForm(), actual.GetSecurityDescriptorBinaryForm());
        }
示例#12
0
        public void Exists()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");
            try
            {
                Directory.CreateDirectory(path);

                ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);
                Assert.IsNotNull(edi);

                Assert.IsTrue(edi.Exists);
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }
        }
示例#13
0
        public void DirectoryOwner()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");
            Directory.CreateDirectory(path);

            DirectoryInfo di = new DirectoryInfo(path);
            DirectorySecurity ds = di.GetAccessControl(AccessControlSections.Owner);
            string expected = ds.GetOwner(typeof(NTAccount)).ToString();

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);
            Assert.IsNotNull(edi);
            string actual = edi.DirectoryOwner;

            Assert.AreEqual(expected, actual);
        }
示例#14
0
 public void Constructor1()
 {
     ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(Path.GetTempPath());
     Assert.IsNotNull(edi);
 }
示例#15
0
        public void MoveTo()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");
            Directory.CreateDirectory(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);
            Assert.IsNotNull(edi);

            string path2 = Path.Combine(Path.GetTempPath(), "CadruTestMoved");
            edi.MoveTo(path2);

            Assert.IsTrue(Directory.Exists(path2));

            Directory.Delete(path2);
        }
示例#16
0
        public void Create()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");

            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }

            Assert.IsFalse(Directory.Exists(path), "Unable to delete the test directory.");

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);
            Assert.IsNotNull(edi);

            edi.Create();
            Assert.IsTrue(Directory.Exists(path));
        }
示例#17
0
        public void CreateSubdirectory1()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");
            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }

            Assert.IsFalse(Directory.Exists(path), "Unable to delete the test directory.");

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);
            Assert.IsNotNull(edi);

            path = Path.Combine(path, "Subdir");

            DirectorySecurity directorySecurity = new DirectorySecurity();
            directorySecurity.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow));

            string path2 = edi.CreateSubdirectory("Subdir", directorySecurity).FullName;
            Assert.IsTrue(Directory.Exists(path2));

            DirectorySecurity actualDirectorySecurity = Directory.GetAccessControl(path2);
            AuthorizationRuleCollection rules = actualDirectorySecurity.GetAccessRules(true, true, typeof(NTAccount));
            foreach (AuthorizationRule rule in rules)
            {
                FileSystemAccessRule accessRule = (FileSystemAccessRule)rule;

                if (accessRule.IdentityReference.Value == "Everyone")
                {
                    Assert.IsTrue(accessRule.AccessControlType == AccessControlType.Allow);
                    Assert.IsTrue(accessRule.FileSystemRights == FileSystemRights.FullControl);
                }
            }
        }