Exemple #1
0
        public void CheckNullAreEqual()
        {
            var fic = new DirectoryInfoComparer();

            Assert.IsTrue(
                fic.Equals(null, null));
        }
Exemple #2
0
        public void CheckNonNullAreEqual()
        {
            var fic = new DirectoryInfoComparer();

            Assert.IsFalse(
                fic.Equals(null, new DirectoryInfo("c:\\dir")));
        }
Exemple #3
0
        public void CheckAreEqual(string lhs, string rhs)
        {
            var fic = new DirectoryInfoComparer();

            Assert.IsTrue(
                fic.Equals(new DirectoryInfo(lhs), new DirectoryInfo(rhs)));
        }
Exemple #4
0
        public void HashCodeCaseInsensitive()
        {
            const string name     = "c:\\hello\\world\\blah\\";
            var          dic      = new DirectoryInfoComparer();
            var          expected = dic.GetHashCode(new DirectoryInfo(name));

            Assert.AreEqual(expected, dic.GetHashCode(new DirectoryInfo(name.ToUpper())));
        }
Exemple #5
0
        public void DictionaryKeys()
        {
            const string name = "c:\\test";

            var dic  = new DirectoryInfoComparer();
            var dict = new Dictionary <DirectoryInfo, object>(dic);
            var info = new DirectoryInfo(name);

            dict[info] = null;
            Assert.IsTrue(dict.ContainsKey(info));
            Assert.IsTrue(dict.ContainsKey(new DirectoryInfo(name)));
        }
Exemple #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        public FolderComparer(string source, string destination)
        {
            if ( !(Directory.Exists (source) && Directory.Exists (destination))) throw new DirectoryNotFoundException();
            this.source = source;
            this.destination = destination;

            this.sourceDirectoryInfos = GetDirectoryInfos(this.source);
            this.destinationDirectoryInfos = GetDirectoryInfos(this.destination);

            this.sourceFileInfos = GetFileInfos(this.source);
            this.destinationFileInfos = GetFileInfos(this.destination);

            this.fileInfoComparer = new FileInfoComparer(source, destination);
            this.directoryInforComparer = new DirectoryInfoComparer(source, destination);
        }
Exemple #7
0
        /// <summary>
        /// Check if a directory is a child of the parent
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="child"></param>
        /// <returns></returns>
        public static bool IsSubDirectory(DirectoryInfo parent, DirectoryInfo child)
        {
            #region Sanity Check
            if (null == parent)
            {
                throw new ArgumentNullException(nameof(parent));
            }
            if (null == child)
            {
                throw new ArgumentNullException(nameof(child));
            }
            #endregion

            #region Fast Checks
            // "c:\foo\bar" is a child of "c:\foo"
            var pFullName = DirectoryInfoComparer.FullName(parent);
            var cFullName = DirectoryInfoComparer.FullName(child);

            // if the parent is longer than the child
            // then it cannot posibly be a child.
            if (pFullName.Length > cFullName.Length)
            {
                return(false);
            }

            // are they equal?
            if (pFullName.Length == cFullName.Length)
            {
                return(Equals(parent, child));
            }

            // if the root paths are not the same... then don't do it.
            if (string.Compare(Path.GetPathRoot(pFullName), Path.GetPathRoot(cFullName), StringComparison.OrdinalIgnoreCase) != 0)
            {
                return(false);
            }
            #endregion

            //  is the child a substring of the parent...
            return(cFullName.ToUpper().Contains(pFullName.ToUpper()));
        }
        private void CompareFiles(IEnumerable<System.IO.FileInfo> files)
        {
            FileInfoComparer fileCompare = new FileInfoComparer();

            var trList = files.GroupBy(x => x, fileCompare)
            .Select(x => new FileTreeInfo()
            {
                DuplicateCount = x.Count(),
                ChildFiles = x.Select(y => y).ToList(),
                FileInfo = x.Key,
            })
            .Where(x => x.DuplicateCount > 1);

            // Flatten the list so the view can diplay it however it wants.
            var trListA = trList
                        .SelectMany(x => x.ChildFiles)
                        .Select(y => y);

            DirectoryInfoComparer dirCompare = new DirectoryInfoComparer();

            this.treeList = trListA.ToList();
        }
Exemple #9
0
 public void FullNameIsProperlyChanged(string lhs, string rhs)
 {
     Assert.AreEqual(
         DirectoryInfoComparer.FullName(new DirectoryInfo(lhs)), rhs);
 }
Exemple #10
0
 public void FullNameCaseAreKept(string given, string expected)
 {
     Assert.AreEqual(expected, DirectoryInfoComparer.FullName(new DirectoryInfo(given)));
 }
Exemple #11
0
 public void FulleNameCannotBeNull()
 {
     Assert.Throws <ArgumentNullException>(() => DirectoryInfoComparer.FullName(null));
 }