public async Task PurgeScannedLocations_RemovesScannedLocations() { // 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(() => { return(new List <ScannedFile>() { new ScannedFile() { Name = "Foobar", Path = "C:\\Foo", Hash = new byte[32] }, new ScannedFile() { Name = "Foobar", Path = "C:\\Foobar", Hash = new byte[32] }, new ScannedFile() { Name = "Foobar", Path = "C:\\Foo\\Bar", Hash = new byte[32] } }.AsQueryable()); }); locations.Setup(t => t.ListData()).Returns(() => { return(new List <ScannedLocation>() { new ScannedLocation() { Path = "C:\\Foo" }, new ScannedLocation() { Path = "C:\\Foobar" }, new ScannedLocation() { Path = "C:\\Foo\\Bar" } }.AsQueryable()); }); // ACT await service.PurgeScannedLocationsAsync(new List <string>() { "C:\\Foo" }); // ASSERT locations.Verify(t => t.PurgeData(It.IsAny <IQueryable <ScannedLocation> >()), Times.Once); // ToDo: Assert right collection of ScannedLocations }
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]); }
public async Task PurgeScannedLocations_RemovesAllScannedFileAndLocationEntities() { // ARRANGE var files = new Mock <IDataCache <ScannedFile> >(); var locations = new Mock <IDataCache <ScannedLocation> >(); FileHashService service = new FileHashService(files.Object, locations.Object); // ACT await service.PurgeScannedLocationsAsync(null); // ASSERT files.Verify(t => t.PurgeData(It.IsAny <IQueryable <ScannedFile> >()), Times.Once(), "The complete range of entities was not removed from the entity set."); locations.Verify(t => t.PurgeData(It.IsAny <IQueryable <ScannedLocation> >()), Times.Once(), "The complete range of entities was not removed from the entity set."); }