/// <summary>
        /// Scan a file to the storage backend and update the progress
        /// </summary>
        /// <param name="filePath">The location to add to the storage backend</param>
        /// <param name="progress">The IProgress to update the progress on.
        /// Progress is updated with the following formula: index * 100 / totalCount</param>
        internal async Task ScanFile(string filePath, IProgress <int> progress, int index, int totalCount)
        {
            if (_fileSystem.File.Exists(filePath))
            {
                FileHash    fileHash    = new FileHash(_fileSystem);
                ScannedFile scannedFile = new ScannedFile();
                scannedFile.Name = _fileSystem.Path.GetFileName(filePath);
                scannedFile.Path = _fileSystem.Path.GetFullPath(filePath);
                scannedFile.Hash = await fileHash.ComputeFileHashAsync(filePath);

                await _service.InsertScannedFileAsync(scannedFile);
            }
            if (progress != null)
            {
                progress.Report(index * 100 / totalCount);
            }
        }
Ejemplo n.º 2
0
        public async Task FileHash_ComputeFileHashAsync_ReturnsHash()
        {
            // ARRANGE
            MockFileData mockFileData = new MockFileData("This is a test file.");
            Dictionary <string, MockFileData> dictionaryMockFileData = new Dictionary <string, MockFileData>();

            string key = "foobar";

            dictionaryMockFileData.Add(key, mockFileData);
            MockFileSystem fileSystem = new MockFileSystem(dictionaryMockFileData);

            FileHash filehash = new FileHash(fileSystem);

            // ACT
            byte[] result = await filehash.ComputeFileHashAsync(key);

            // ASSERT
            Assert.AreEqual(result.Length, 32, "The result did not match what was expected.");
            Assert.IsTrue(result[0] > 0, "The result did not match what was expected.");
        }