protected void InitRootWithDirDirFileWithDir() { InitRootWithDir(); var dirEntry2 = new DirEntry(true) { Path = @"Test2" }; var dirEntry3 = new DirEntry(true) { Path = @"Test3", Size = 12312, Modified = new DateTime(2009, 10, 03, 19, 17, 13, DateTimeKind.Unspecified), }; var dirEntry4 = new DirEntry { Path = @"Test4", Size = 32312, Modified = new DateTime(2008, 10, 04, 20, 18, 14, DateTimeKind.Unspecified), }; _dirEntry.Children.Add(dirEntry2); _rootEntry.Children.Add(dirEntry3); _rootEntry.Children.Add(dirEntry4); _rootEntry.SetInMemoryFields(); _pairDirEntry = new PairDirEntry(_rootEntry, _dirEntry); _rootList.Add(_rootEntry); }
protected void InitRootWithFile() { var nowUtc = new DateTime(2011, 12, 01, 17, 15, 13, DateTimeKind.Utc); _rootEntry = new RootEntry { Path = @"T:\", VolumeName = "TestVolume", DirEntryCount = 1, FileEntryCount = 0, DriveLetterHint = @"Z", AvailSpace = 754321, TotalSpace = 654321, ScanStartUTC = nowUtc, ScanEndUTC = nowUtc.AddMilliseconds(34), DefaultFileName = "TestRootEntry.cde", ActualFileName = @".\TestRootEntry.cde", Description = "Test Root Entry Description", }; _dirEntry = new DirEntry { Path = @"Test", Size = 531, Modified = new DateTime(2010, 11, 02, 18, 16, 12, DateTimeKind.Unspecified), }; _rootEntry.Children.Add(_dirEntry); _rootEntry.SetInMemoryFields(); _pairDirEntry = new PairDirEntry(_rootEntry, _dirEntry); _rootList.Add(_rootEntry); }
public void SetFullPath_OnRootDirectory_SetsAllFullPaths() { var re = new RootEntry { Path = @"C:\" }; var fe1 = new DirEntry { Path = "fe1" }; var de2 = new DirEntry(true) { Path = "de2" }; var fe3 = new DirEntry { Path = "fe3" }; re.Children.Add(fe1); re.Children.Add(de2); de2.Children.Add(fe3); re.SetInMemoryFields(); Assert.That(re.FullPath, Is.EqualTo(@"C:\")); Assert.That(fe1.FullPath, Is.Null); // Is.EqualTo(@"C:\fe1")); FullPath only set on directories to save memory. Assert.That(de2.FullPath, Is.EqualTo(@"C:\de2")); Assert.That(fe3.FullPath, Is.Null); //Is.EqualTo(@"C:\de2\fe3")); }
protected void InitRootWithDir() { _rootEntry = new RootEntry { Path = @"T:\" }; _dirEntry = new DirEntry(true) { Path = @"Test1" }; _rootEntry.Children.Add(_dirEntry); _rootEntry.SetInMemoryFields(); _pairDirEntry = new PairDirEntry(_rootEntry, _dirEntry); _rootList.Add(_rootEntry); }
protected void RebuildTestRoot() { _re1 = new RootEntry { Path = @"C:\" }; De1 = new DirEntry(true) { Path = @"de1" }; Fe2 = new DirEntry { Path = @"fe2" }; De1.Children.Add(Fe2); _re1.Children.Add(De1); _re1.SetInMemoryFields(); RootEntries = new List <RootEntry> { _re1 }; }
public void FindFunc_Spec_for_limit() { describe["given test entry tree"] = () => { // ReSharper disable TooWideLocalVariableScope DirEntry de2a; DirEntry de2b; DirEntry de2c; DirEntry de3a = null; DirEntry de4a = null; // ReSharper restore TooWideLocalVariableScope RootEntry re = null; FindOptions findOptions = null; Func <CommonEntry, DirEntry, bool> matcherAll = null; before = () => { // NOTE: test tree entry entry is de2c,de2a,de2b,de3a,de4a re = RootEntryTestBase.NewTestRootEntry(out de2a, out de2b, out de2c, out de3a, out de4a); re.SetInMemoryFields(); matcherAll = Substitute.For <Func <CommonEntry, DirEntry, bool> >(); matcherAll(null, null).ReturnsForAnyArgs(true); findOptions = new FindOptions(); }; describe["with FindOptions matching all entries"] = () => { TraverseFunc visitorFunc = null; before = () => { visitorFunc = Substitute.For <TraverseFunc>(); visitorFunc(null, null).ReturnsForAnyArgs(x => true); findOptions.Pattern = string.Empty; findOptions.PatternMatcher = matcherAll; findOptions.VisitorFunc = visitorFunc; }; describe["given find limit 2"] = () => { before = () => { findOptions.LimitResultCount = 2; findOptions.Find(new[] { re }); }; specify = () => visitorFunc.ReceivedWithAnyArgs(2).Invoke(null, null); specify = () => findOptions.ProgressCount.should_be(2); }; describe["given find limit 4"] = () => { before = () => { findOptions.LimitResultCount = 4; findOptions.Find(new[] { re }); }; specify = () => visitorFunc.ReceivedWithAnyArgs(4).Invoke(null, null); specify = () => findOptions.ProgressCount.should_be(4); }; describe["given large limit"] = () => { before = () => { findOptions.LimitResultCount = int.MaxValue; }; describe["will find all"] = () => { before = () => findOptions.Find(new[] { re }); specify = () => visitorFunc.ReceivedWithAnyArgs(5).Invoke(null, null); specify = () => findOptions.ProgressCount.should_be(5); }; describe["and given SkipCount 5"] = () => { before = () => { findOptions.SkipCount = 5; findOptions.Find(new[] { re }); }; specify = () => visitorFunc.ReceivedWithAnyArgs(0).Invoke(null, null); specify = () => findOptions.ProgressCount.should_be(5); }; describe["and given SkipCount 6"] = () => { before = () => { findOptions.SkipCount = 6; findOptions.Find(new[] { re }); }; specify = () => visitorFunc.ReceivedWithAnyArgs(0).Invoke(null, null); specify = () => findOptions.ProgressCount.should_be(5); }; }; describe["When find limit 2, pattern 'a'"] = () => { before = () => { findOptions.Pattern = "a"; findOptions.LimitResultCount = 2; findOptions.Find(new[] { re }); }; specify = () => visitorFunc.ReceivedWithAnyArgs(2).Invoke(null, null); specify = () => findOptions.ProgressCount.should_be(4); }; describe["When find limit 2, pattern 'a' with Skip count 2"] = () => { before = () => { findOptions.LimitResultCount = 2; findOptions.SkipCount = 2; findOptions.Pattern = "a"; findOptions.Find(new[] { re }); }; specify = () => visitorFunc.ReceivedWithAnyArgs(2).Invoke(null, null); specify = () => findOptions.ProgressCount.Is(5); it["found received in expected order"] = () => Received.InOrder(() => { visitorFunc.Received().Invoke(Arg.Any <CommonEntry>(), de3a); visitorFunc.Received().Invoke(Arg.Any <CommonEntry>(), de4a); }); }; }; }; // TODO - capture SkipCount and interface and pass it back later ? [ProgressCount from findOptions] // maybe this involves holding onto FindOptions on serverside in Web ? // TODO - if SkipCount >= Limit then dont do any work return empty. }
public void GetSizePairs_HashIrrelevant_NullIsNotAHashValue_PartialNotAUniqueHashForSize_OK() { var re1 = new RootEntry { Path = @"C:\" }; var de1 = new DirEntry { Path = "de1", Size = 10, IsPartialHash = false }; de1.SetHash(10); var de2 = new DirEntry { Path = "de2", Size = 10, IsPartialHash = false }; de2.SetHash(11); var de3 = new DirEntry { Path = "de3", Size = 11, IsPartialHash = false }; de3.SetHash(10); var de4 = new DirEntry { Path = "de4", Size = 11, IsPartialHash = false }; de4.SetHash(11); var de5 = new DirEntry { Path = "de5", Size = 11, IsPartialHash = false }; de5.SetHash(11); var de6 = new DirEntry { Path = "de6", Size = 11, IsPartialHash = false }; de6.SetHash(12); var de7 = new DirEntry { Path = "de7", Size = 11, IsPartialHash = true }; de7.SetHash(12); var de8 = new DirEntry { Path = "de8", Size = 11, IsPartialHash = false }; de8.SetHash(12); var de9 = new DirEntry { Path = "de9", Size = 11, IsPartialHash = false }; var de10 = new DirEntry { Path = "de10", Size = 11, IsPartialHash = true }; de10.SetHash(13); re1.Children.Add(de1); re1.Children.Add(de2); re1.Children.Add(de3); re1.Children.Add(de4); re1.Children.Add(de5); re1.Children.Add(de6); re1.Children.Add(de7); re1.Children.Add(de8); re1.Children.Add(de9); re1.Children.Add(de10); var roots = new List <RootEntry> { re1 }; re1.SetInMemoryFields(); var d = new Duplication(_logger, _configuration, _applicationDiagnostics); var sizePairDictionary = d.GetSizePairs(roots); Console.WriteLine($"Number of Size Pairs {sizePairDictionary.Count}"); Assert.That(sizePairDictionary.Count, Is.EqualTo(2)); var sumOfUniqueHashesForEachSize = GetSumOfUniqueHashesForEachSize_ExcludePartialHash(sizePairDictionary); Console.WriteLine($"Sum of total unique hashes (split on filesize to) {sumOfUniqueHashesForEachSize}"); Assert.That(sumOfUniqueHashesForEachSize, Is.EqualTo(5)); }