Ejemplo n.º 1
0
        public async Task ListScannedFilePathsAsync_ReturnsManyFilePaths()
        {
            // 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 = 0; i < 3; i++)
                {
                    scannedFiles.Add(new ScannedFile()
                    {
                        Path = "testing"
                    });
                }
                return(scannedFiles.AsQueryable());
            });

            // ACT
            List <string> results = await service.ListScannedFilePathsAsync(null);

            // ASSERT
            Assert.AreEqual(3, results.Count);
            Assert.AreEqual("testing", results[2]);
        }
Ejemplo n.º 2
0
        public async Task PurgeScannedLocations_PurgesCorrectScannedFiles()
        {
            // ARRANGE
            List <ScannedLocation> locationData = new List <ScannedLocation>()
            {
                new ScannedLocation()
                {
                    Path = "C:\\Foo"
                }
            };
            List <ScannedFile> fileData = new List <ScannedFile>()
            {
                new ScannedFile()
                {
                    Name = "Foobar",
                    Path = "C:\\Foo\\Foobar",
                    Hash = new byte[32]
                },
                new ScannedFile()
                {
                    Name = "Foobar",
                    Path = "C:\\Bar\\Foobar",
                    Hash = new byte[32]
                },
                new ScannedFile()
                {
                    Name = "Foobar",
                    Path = "C:\\Foo\\Bar\\Foobar",
                    Hash = new byte[32]
                },
                new ScannedFile()
                {
                    Name = "Foobar",
                    Path = "C:\\Foobar\\Foobar",
                    Hash = new byte[32]
                },
                new ScannedFile()
                {
                    Name = "Foobar",
                    Path = "C:\\Foobar",
                    Hash = new byte[32]
                }
            };
            var             files     = new DataCache <ScannedFile>(fileData);
            var             locations = new DataCache <ScannedLocation>(locationData);
            FileHashService service   = new FileHashService(files, locations);


            // ACT
            await service.PurgeScannedLocationsAsync(locationData.Select(t => t.Path).ToList());

            // ASSERT
            List <string> results = await service.ListScannedFilePathsAsync(null);

            Assert.AreEqual(3, results.Count);
            Assert.AreEqual("C:\\Bar\\Foobar", results[0]);
            Assert.AreEqual("C:\\Foobar\\Foobar", results[1]);
            Assert.AreEqual("C:\\Foobar", results[2]);
        }
Ejemplo n.º 3
0
        public async Task ListScannedFilePathsAsync_FiltersFiles()
        {
            // 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>()
                {
                    new ScannedFile()
                    {
                        Name = "Foobar",
                        Path = "C:\\Foo\\Foobar"
                    },
                    new ScannedFile()
                    {
                        Name = "Foobar",
                        Path = "C:\\Bar\\Foobar"
                    },
                    new ScannedFile()
                    {
                        Name = "Foobar",
                        Path = "C:\\Foo\\Bar\\Foobar"
                    },
                    new ScannedFile()
                    {
                        Name = "Foobar",
                        Path = "C:\\Foobar\\Foobar"
                    },
                    new ScannedFile()
                    {
                        Name = "Foobar",
                        Path = "C:\\Foobar"
                    }
                };
                return(scannedFiles.AsQueryable());
            });

            // ACT
            var results = await service.ListScannedFilePathsAsync(new List <string>()
            {
                "C:\\Foo"
            });


            // ASSERT
            Assert.AreEqual(2, results.Count);
            Assert.IsTrue(
                results[0].Equals("C:\\Foo\\Foobar", StringComparison.InvariantCultureIgnoreCase),
                "The wrong path was returned.");
            Assert.IsTrue(
                results[1].Equals("C:\\Foo\\Bar\\Foobar", StringComparison.InvariantCultureIgnoreCase),
                "The wrong path was returned.");
        }