예제 #1
0
        public void Equals_OnlyFirstFourBytesEqual_IsNotEqual()
        {
            // ARRANGE
            ScannedFileHashComparer comparer = new ScannedFileHashComparer();

            byte[] fileHashOne = new byte[32];
            byte[] fileHashTwo = new byte[32];
            for (int i = 0; i < 32; i++)
            {
                fileHashOne[i] = 0xFF;
                fileHashTwo[i] = 0xFE;
            }
            fileHashOne[0] = 0x01;
            fileHashOne[1] = 0x02;
            fileHashOne[2] = 0x03;
            fileHashOne[3] = 0x04;
            fileHashTwo[0] = 0x01;
            fileHashTwo[1] = 0x02;
            fileHashTwo[2] = 0x03;
            fileHashTwo[3] = 0x04;

            // ACT
            bool result = comparer.Equals(fileHashOne, fileHashTwo);

            // ASSERT
            Assert.IsFalse(result);
        }
        /// <summary>
        /// Takes the scanned files and adds them to the <see cref="Duplicates"/> collection.
        /// The ScannedFiles will be sorted by Hash before being added to the ViewModel.
        /// Internally exposed for unit testing.
        /// It is assumed that <paramref name="scannedFiles"/> is sorted by Hash before calling.
        /// </summary>
        /// <param name="scannedFiles">The scanned files to add</param>
        internal void AddScannedFiles(List <ScannedFile> scannedFiles)
        {
            byte[]                  previousHash = null;
            BackgroundColor         color        = BackgroundColor.Transparent;
            ScannedFileHashComparer comparer     = new ScannedFileHashComparer();

            foreach (ScannedFile scannedFile in scannedFiles)
            {
                // If the hash is not same as the previous hash flip the same color
                if (previousHash != null && !comparer.Equals(previousHash, scannedFile.Hash))
                {
                    // If there are ever more than two BackgroundColor types, this flipping logic
                    // will need to be revisited.
                    color = 1 - color;
                }
                ScanResult scanResult = new ScanResult()
                {
                    FilePath   = scannedFile.Path,
                    Hash       = scannedFile.Hash,
                    Background = color.ToString(),
                    IsSelected = false
                };
                Duplicates.Add(scanResult);
                previousHash = scannedFile.Hash;
            }
        }
예제 #3
0
        public void Equals_BothNull_IsEqual()
        {
            // ARRANGE
            ScannedFileHashComparer comparer = new ScannedFileHashComparer();

            // ACT
            bool result = comparer.Equals(null, null);

            // ASSERT
            Assert.IsTrue(result);
        }
예제 #4
0
        public override bool Equals(object obj)
        {
            ScannedFileHashComparer comparer         = new ScannedFileHashComparer();
            ScannedFile             otherScannedFile = obj as ScannedFile;

            bool isEqual = this.Name.Equals(otherScannedFile.Name) &&
                           this.Path.Equals(otherScannedFile.Path) &&
                           this.Length.Equals(otherScannedFile.Length) &&
                           comparer.Equals(this.Hash, otherScannedFile.Hash);

            return(isEqual);
        }
예제 #5
0
        public void GetHashCode_ArrayLessThanFourBytes_ReturnsInt()
        {
            // ARRANGE
            ScannedFileHashComparer comparer = new ScannedFileHashComparer();

            byte[] fileHash = new byte[2];
            fileHash[0] = 0x01;
            fileHash[1] = 0x02;

            // ACT
            int hashOne = comparer.GetHashCode(fileHash);

            // ASSERT (if no exception the test passes)
        }
예제 #6
0
        public void Equals_DifferentLength_IsNotEqual()
        {
            // ARRANGE
            ScannedFileHashComparer comparer = new ScannedFileHashComparer();

            byte[] fileHashOne = new byte[32];
            byte[] fileHashTwo = new byte[16];

            // ACT
            bool result = comparer.Equals(fileHashOne, fileHashTwo);

            // ASSERT
            Assert.IsFalse(result);
        }
예제 #7
0
        public void Equals_SameReference_IsEqual()
        {
            // ARRANGE
            ScannedFileHashComparer comparer = new ScannedFileHashComparer();

            byte[] fileHashOne = new byte[32];
            for (int i = 0; i < 32; i++)
            {
                fileHashOne[i] = 0xFF;
            }

            // ACT
            bool result = comparer.Equals(fileHashOne, fileHashOne);

            // ASSERT
            Assert.IsTrue(result);
        }
예제 #8
0
        public void Equals_OnlyOneNull_IsNotEqual()
        {
            // ARRANGE
            ScannedFileHashComparer comparer = new ScannedFileHashComparer();

            byte[] fileHashOne = new byte[32];
            for (int i = 0; i < 32; i++)
            {
                fileHashOne[i] = 0xFF;
            }

            // ACT
            bool result = comparer.Equals(fileHashOne, null);

            // ASSERT
            Assert.IsFalse(result);
        }
예제 #9
0
        public void GetHashCode_ReturnsUniqueHash()
        {
            // ARRANGE
            ScannedFileHashComparer comparer = new ScannedFileHashComparer();

            byte[] fileHashOne = new byte[32];
            byte[] fileHashTwo = new byte[32];
            fileHashOne[0] = 0x01;
            fileHashOne[1] = 0x02;
            fileHashOne[2] = 0x03;
            fileHashOne[3] = 0x04;
            fileHashTwo[0] = 0x04;
            fileHashTwo[1] = 0x03;
            fileHashTwo[2] = 0x02;
            fileHashTwo[3] = 0x01;

            // ACT
            int hashOne = comparer.GetHashCode(fileHashOne);
            int hashTwo = comparer.GetHashCode(fileHashTwo);

            // ASSERT
            Assert.AreNotEqual(hashOne, hashTwo, "The two hash codes were equal when expected to be different");
        }