Beispiel #1
0
        public async Task ReturnDuplicatesAsync_NoDuplicateHashes_ReturnsEmptyList()
        {
            // ARRANGE
            var             files     = new Mock <IDataCache <ScannedFile> >();
            var             locations = new Mock <IDataCache <ScannedLocation> >();
            FileHashService service   = new FileHashService(files.Object, locations.Object);

            files.Setup(t => t.ListData())
            .Returns(() =>
            {
                List <ScannedFile> scannedFiles = new List <ScannedFile>();
                for (int i = 1; i <= 3; i++)
                {
                    byte[] updatedBytes = new byte[32];
                    updatedBytes[0]     = System.Convert.ToByte(i);
                    scannedFiles.Add(new ScannedFile()
                    {
                        Hash = updatedBytes
                    });
                }
                return(scannedFiles.AsQueryable());
            });

            // ACT
            List <ScannedFile> results = await service.ReturnDuplicatesAsync();

            // ASSERT
            Assert.AreEqual(0, results.Count, "The number of found scanned files does not match what was expected");
        }
Beispiel #2
0
        public async Task ReturnDuplicatesAsync_ManyDuplicateHash_ReturnsSortedList()
        {
            // ARRANGE
            var             files     = new Mock <IDataCache <ScannedFile> >();
            var             locations = new Mock <IDataCache <ScannedLocation> >();
            FileHashService service   = new FileHashService(files.Object, locations.Object);

            files.Setup(t => t.ListData())
            .Returns(() =>
            {
                byte[] uniqueBytesOne           = new byte[32];
                byte[] uniqueBytesTwo           = new byte[32];
                uniqueBytesOne[1]               = 0x01;
                uniqueBytesTwo[2]               = 0x02;
                List <ScannedFile> scannedFiles = new List <ScannedFile>();
                for (int i = 1; i <= 10; i++)
                {
                    ScannedFile file = new ScannedFile()
                    {
                        Hash = new byte[32]
                    };
                    switch (i)
                    {
                    case 1:
                        file.Name = "foo1";
                        Array.Copy(uniqueBytesOne, file.Hash, 32);
                        break;

                    case 2:
                        file.Name = "bar1";
                        Array.Copy(uniqueBytesTwo, file.Hash, 32);
                        break;

                    case 3:
                        file.Name = "bar2";
                        Array.Copy(uniqueBytesTwo, file.Hash, 32);
                        break;

                    case 4:
                        file.Name = "foo2";
                        Array.Copy(uniqueBytesOne, file.Hash, 32);
                        break;
                    }
                    scannedFiles.Add(file);
                }
                return(scannedFiles.AsQueryable());
            });

            // ACT
            List <ScannedFile> results = await service.ReturnDuplicatesAsync();

            // ASSERT
            Assert.AreEqual("foo2", results[1].Name, "The collection was not sorted as expected.");
        }
Beispiel #3
0
        public async Task ReturnDuplicatesAsync_ManyDuplicateHash_ReturnsManyScannedFiles()
        {
            // ARRANGE
            var             files     = new Mock <IDataCache <ScannedFile> >();
            var             locations = new Mock <IDataCache <ScannedLocation> >();
            FileHashService service   = new FileHashService(files.Object, locations.Object);

            files.Setup(t => t.ListData())
            .Returns(() =>
            {
                byte[] uniqueBytesOne           = new byte[32];
                byte[] uniqueBytesTwo           = new byte[32];
                uniqueBytesOne[1]               = 0x01;
                uniqueBytesTwo[2]               = 0x02;
                List <ScannedFile> scannedFiles = new List <ScannedFile>();
                for (int i = 1; i <= 10; i++)
                {
                    ScannedFile file = new ScannedFile()
                    {
                        Hash = new byte[32]
                    };
                    switch (i)
                    {
                    case 1:
                    case 2:
                        Array.Copy(uniqueBytesOne, file.Hash, 32);
                        break;

                    case 3:
                    case 4:
                        Array.Copy(uniqueBytesTwo, file.Hash, 32);
                        break;

                    default:
                        file.Hash[31] = (byte)i;
                        break;
                    }
                    scannedFiles.Add(file);
                }
                return(scannedFiles.AsQueryable());
            });

            // ACT
            List <ScannedFile> results = await service.ReturnDuplicatesAsync();

            // ASSERT
            Assert.AreEqual(4, results.Count, "The number of found scanned files does not match what was expected");
        }
Beispiel #4
0
        public async Task ReturnDuplicatesAsync_OneDuplicateHash_ReturnsTwoScannedFiles()
        {
            // ARRANGE
            var             files     = new Mock <IDataCache <ScannedFile> >();
            var             locations = new Mock <IDataCache <ScannedLocation> >();
            FileHashService service   = new FileHashService(files.Object, locations.Object);

            files.Setup(t => t.ListData())
            .Returns(() =>
            {
                byte[] uniqueBytesOne           = new byte[32];
                byte[] uniqueBytesTwo           = new byte[32];
                List <ScannedFile> scannedFiles = new List <ScannedFile>()
                {
                    new ScannedFile()
                    {
                        Hash = new byte[32]
                    },
                    new ScannedFile()
                    {
                        Hash = new byte[32]
                    },
                    new ScannedFile()
                    {
                        Hash = new byte[32]
                    }
                };
                uniqueBytesOne[0] = 0x11;
                uniqueBytesTwo[0] = 0xFF;
                Array.Copy(uniqueBytesOne, scannedFiles[0].Hash, 32);
                Array.Copy(uniqueBytesOne, scannedFiles[1].Hash, 32);
                Array.Copy(uniqueBytesTwo, scannedFiles[2].Hash, 32);
                return(scannedFiles.AsQueryable());
            });

            // ACT
            List <ScannedFile> results = await service.ReturnDuplicatesAsync();

            // ASSERT
            Assert.AreEqual(2, results.Count, "The number of found scanned files does not match what was expected");
        }