public void CheckNullAreEqual() { var fic = new DirectoryInfoComparer(); Assert.IsTrue( fic.Equals(null, null)); }
public void CheckNonNullAreEqual() { var fic = new DirectoryInfoComparer(); Assert.IsFalse( fic.Equals(null, new DirectoryInfo("c:\\dir"))); }
public void CheckAreEqual(string lhs, string rhs) { var fic = new DirectoryInfoComparer(); Assert.IsTrue( fic.Equals(new DirectoryInfo(lhs), new DirectoryInfo(rhs))); }
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()))); }
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))); }
/// <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); }
/// <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(); }
public void FullNameIsProperlyChanged(string lhs, string rhs) { Assert.AreEqual( DirectoryInfoComparer.FullName(new DirectoryInfo(lhs)), rhs); }
public void FullNameCaseAreKept(string given, string expected) { Assert.AreEqual(expected, DirectoryInfoComparer.FullName(new DirectoryInfo(given))); }
public void FulleNameCannotBeNull() { Assert.Throws <ArgumentNullException>(() => DirectoryInfoComparer.FullName(null)); }