示例#1
0
        public void TraverseTreesCopyHash_OneEntrySourceHasPartialMD5_DestHasPartialMD5_NotCopied()
        {
            deSource.SetHash(12312);
            deDest.SetHash(12313);

            rootSource.TraverseTreesCopyHash(rootDest);

            Assert.That(deDest.Hash, Is.EqualTo(new Hash16(12313)));
            Assert.That(deDest.IsPartialHash, Is.EqualTo(true));
        }
示例#2
0
        public void TestHashingWorks()
        {
            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 ah5 = Hash16.EqualityComparer.StaticGetHashCode(de5.Hash);
            var ah6 = Hash16.EqualityComparer.StaticGetHashCode(de6.Hash);
            var ah7 = Hash16.EqualityComparer.StaticGetHashCode(de7.Hash);
            var ah8 = Hash16.EqualityComparer.StaticGetHashCode(de8.Hash);

            Console.WriteLine($"de5.Hash {ah5}  de6.Hash {ah6} de7.Hash {ah7} de8.Hash {ah8}");

            var a5 = DirEntry.EqualityComparer.StaticGetHashCode(de5);
            var a6 = DirEntry.EqualityComparer.StaticGetHashCode(de6);
            var a7 = DirEntry.EqualityComparer.StaticGetHashCode(de7);
            var a8 = DirEntry.EqualityComparer.StaticGetHashCode(de8);

            Console.WriteLine($"de5 {a5}  de6 {a6} de7 {a7} de8 {a8}");
        }
示例#3
0
        public void TraverseTreesCopyHash_DontCopyHashIfDestHasFullHash()
        {
            RecreateTestTree();
            _dde1.SetHash(99); // _dde1.Hash = new byte[] { 99 };
            _dde1.IsPartialHash = false;

            _reSource.TraverseTreesCopyHash(_reDest);

            // Assert.That(_dde1.Hash, Is.Not.Null); Assert.That(_dde1.Hash[0], Is.EqualTo(99));
        }
示例#4
0
        private static DirEntry GetNewTestF1()
        {
            var de = new DirEntry
            {
                Path          = "f1",
                Modified      = new DateTime(2011, 05, 01, 12, 11, 10),
                Size          = 10,
                IsPartialHash = true,
            };

            de.SetHash(12312);
            return(de);
        }
示例#5
0
        private void SetupRootDestTest1()
        {
            rootSource = new RootEntry {
                Path = @"C:\"
            };
            deSource = GetNewTestF1();
            rootSource.Children.Add(deSource);

            rootDest = new RootEntry {
                Path = @"C:\"
            };
            deDest = GetNewTestF1();
            deDest.SetHash(0);  // clear it just in case.
            deDest.IsHashDone    = false;
            deDest.IsPartialHash = true;
            rootDest.Children.Add(deDest);
        }
示例#6
0
        public void GetDupePairs_DupeHashDoesNotMatchDiffSizeFilesOrPartialHash_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
            };

            var d   = new Duplication(_logger, _configuration, _applicationDiagnostics);
            var dp  = d.GetDupePairs(roots);
            var dp1 = dp.First();

            // ReSharper disable PossibleNullReferenceException
            var f1 = dp1.Value.FirstOrDefault(x => x.ChildDE == de4).ChildDE;

            Assert.That(f1, Is.EqualTo(de4));
            var f2 = dp1.Value.FirstOrDefault(x => x.ChildDE == de5).ChildDE;

            Assert.That(f2, Is.EqualTo(de5));
            // ReSharper restore PossibleNullReferenceException
        }
示例#7
0
        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));
        }
示例#8
0
        private void RecreateTestTree()
        {
            _reSource = new RootEntry {
                Path = @"C:\"
            };
            _sde1 = new DirEntry(false)
            {
                Path = "de1", Size = 10, IsPartialHash = false, Modified = new DateTime(2011, 02, 01)
            }; _sde1.SetHash(09);
            _sde2 = new DirEntry(false)
            {
                Path = "de2", Size = 10, IsPartialHash = false, Modified = new DateTime(2011, 02, 02)
            }; _sde2.SetHash(10);
            _sde3 = new DirEntry(false)
            {
                Path = "de3", Size = 10, IsPartialHash = false, Modified = new DateTime(2011, 02, 03)
            }; _sde3.SetHash(11);
            _sfe4 = new DirEntry(true)
            {
                Path = "fe4", Modified = new DateTime(2011, 02, 04)
            };
            _sde5 = new DirEntry(false)
            {
                Path = "de5", Size = 11, IsPartialHash = false, Modified = new DateTime(2011, 02, 05)
            }; _sde5.SetHash(12);
            _sde6 = new DirEntry(false)
            {
                Path = "de6", Size = 11, IsPartialHash = false, Modified = new DateTime(2011, 02, 06)
            }; _sde6.SetHash(13);
            _sde7 = new DirEntry(false)
            {
                Path = "de7", Size = 11, IsPartialHash = false, Modified = new DateTime(2011, 02, 07)
            }; _sde7.SetHash(14);
            _reSource.Children.Add(_sde1);
            _reSource.Children.Add(_sde2);
            _reSource.Children.Add(_sde3);
            _reSource.Children.Add(_sfe4);
            _sfe4.Children.Add(_sde5);
            _sfe4.Children.Add(_sde6);
            _sfe4.Children.Add(_sde7);

            _reDest = new RootEntry {
                Path = @"C:\"
            };
            _dde1 = new DirEntry(false)
            {
                Path = "de1", Size = 10, IsPartialHash = false, Modified = new DateTime(2011, 02, 01)
            };
            _dde2 = new DirEntry(false)
            {
                Path = "de2", Size = 10, IsPartialHash = false, Modified = new DateTime(2011, 02, 02)
            };
            _dde3 = new DirEntry(false)
            {
                Path = "de3", Size = 10, IsPartialHash = false, Modified = new DateTime(2011, 02, 03)
            };
            _dfe4 = new DirEntry(true)
            {
                Path = "fe4", Modified = new DateTime(2011, 02, 04)
            };
            _dde5 = new DirEntry(false)
            {
                Path = "de5", Size = 11, IsPartialHash = false, Modified = new DateTime(2011, 02, 05)
            };
            _dde6 = new DirEntry(false)
            {
                Path = "de6", Size = 11, IsPartialHash = false, Modified = new DateTime(2011, 02, 06)
            };
            _dde7 = new DirEntry(false)
            {
                Path = "de7", Size = 11, IsPartialHash = false, Modified = new DateTime(2011, 02, 07)
            };
            _reDest.Children.Add(_dde1);
            _reDest.Children.Add(_dde2);
            _reDest.Children.Add(_dde3);
            _reDest.Children.Add(_dfe4);
            _dfe4.Children.Add(_dde5);
            _dfe4.Children.Add(_dde6);
            _dfe4.Children.Add(_dde7);
        }