Scrobbling Polish and Some Scanner fixes (#3638)
Co-authored-by: Fesaa <77553571+Fesaa@users.noreply.github.com>
This commit is contained in:
parent
82e8f7fade
commit
f281a63934
19 changed files with 658 additions and 102 deletions
|
@ -55,6 +55,28 @@ public class ScannerServiceTests : AbstractDbTest
|
|||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
||||
protected async Task SetAllSeriesLastScannedInThePast(Library library, TimeSpan? duration = null)
|
||||
{
|
||||
foreach (var series in library.Series)
|
||||
{
|
||||
await SetLastScannedInThePast(series, duration, false);
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
protected async Task SetLastScannedInThePast(Series series, TimeSpan? duration = null, bool save = true)
|
||||
{
|
||||
duration ??= TimeSpan.FromMinutes(2);
|
||||
series.LastFolderScanned = DateTime.Now.Subtract(duration.Value);
|
||||
_context.Series.Update(series);
|
||||
|
||||
if (save)
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ScanLibrary_ComicVine_PublisherFolder()
|
||||
{
|
||||
|
@ -611,9 +633,7 @@ public class ScannerServiceTests : AbstractDbTest
|
|||
File.Copy(Path.Join(root1PlushFolder, "Plush v02.cbz"), Path.Join(root1PlushFolder, "Plush v03.cbz"));
|
||||
|
||||
// Emulate time passage by updating lastFolderScan to be a min in the past
|
||||
s.LastFolderScanned = DateTime.Now.Subtract(TimeSpan.FromMinutes(1));
|
||||
_context.Series.Update(s);
|
||||
await _context.SaveChangesAsync();
|
||||
await SetLastScannedInThePast(s);
|
||||
|
||||
// Rescan to ensure nothing changes yet again
|
||||
await scanner.ScanLibrary(library.Id, false);
|
||||
|
@ -702,12 +722,7 @@ public class ScannerServiceTests : AbstractDbTest
|
|||
Assert.Contains(postLib.Series, s => s.Name == "Plush");
|
||||
|
||||
// Emulate time passage by updating lastFolderScan to be a min in the past
|
||||
foreach (var s in postLib.Series)
|
||||
{
|
||||
s.LastFolderScanned = DateTime.Now.Subtract(TimeSpan.FromMinutes(1));
|
||||
_context.Series.Update(s);
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
await SetAllSeriesLastScannedInThePast(postLib);
|
||||
|
||||
// Fourth Scan: Run again to check stability (should not remove Accel)
|
||||
await scanner.ScanLibrary(library.Id);
|
||||
|
@ -794,7 +809,7 @@ public class ScannerServiceTests : AbstractDbTest
|
|||
Assert.Equal(2, executionerAndHerWayOfLife.Volumes.Count);
|
||||
Assert.Equal(2, executionerAndHerWayOfLife.Volumes.Sum(v => v.Chapters.Count));
|
||||
|
||||
Thread.Sleep(1100); // Ensure at least one second has passed since library scan
|
||||
await SetAllSeriesLastScannedInThePast(postLib);
|
||||
|
||||
// Add a new chapter to a volume of the series, and scan. Validate that no chapters were lost, and the new
|
||||
// chapter was added
|
||||
|
@ -822,4 +837,94 @@ public class ScannerServiceTests : AbstractDbTest
|
|||
Assert.Equal(2, executionerAndHerWayOfLife.Volumes.Count);
|
||||
Assert.Equal(3, executionerAndHerWayOfLife.Volumes.Sum(v => v.Chapters.Count)); // Incremented by 1
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RemovalPickedUp_NoOtherChanges()
|
||||
{
|
||||
const string testcase = "Series removed when no other changes are made - Manga.json";
|
||||
var infos = new Dictionary<string, ComicInfo>();
|
||||
var library = await _scannerHelper.GenerateScannerData(testcase, infos);
|
||||
var testDirectoryPath = library.Folders.First().Path;
|
||||
|
||||
_unitOfWork.LibraryRepository.Update(library);
|
||||
await _unitOfWork.CommitAsync();
|
||||
|
||||
var scanner = _scannerHelper.CreateServices();
|
||||
await scanner.ScanLibrary(library.Id);
|
||||
|
||||
var postLib = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(library.Id, LibraryIncludes.Series);
|
||||
Assert.NotNull(postLib);
|
||||
Assert.Equal(2, postLib.Series.Count);
|
||||
|
||||
var executionerCopyDir = Path.Join(testDirectoryPath, "The Executioner and Her Way of Life");
|
||||
Directory.Delete(executionerCopyDir, true);
|
||||
|
||||
await scanner.ScanLibrary(library.Id);
|
||||
await _unitOfWork.CommitAsync();
|
||||
|
||||
postLib = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(library.Id, LibraryIncludes.Series);
|
||||
Assert.NotNull(postLib);
|
||||
Assert.Single(postLib.Series);
|
||||
Assert.Single(postLib.Series, s => s.Name == "Spice and Wolf");
|
||||
Assert.Equal(2, postLib.Series.First().Volumes.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SubFoldersNoSubFolders_CorrectPickupAfterAdd()
|
||||
{
|
||||
// This test case is used in multiple tests and can result in conflict if not separated
|
||||
const string testcase = "Subfolders and files at root (2) - Manga.json";
|
||||
var infos = new Dictionary<string, ComicInfo>();
|
||||
var library = await _scannerHelper.GenerateScannerData(testcase, infos);
|
||||
var testDirectoryPath = library.Folders.First().Path;
|
||||
|
||||
_unitOfWork.LibraryRepository.Update(library);
|
||||
await _unitOfWork.CommitAsync();
|
||||
|
||||
var scanner = _scannerHelper.CreateServices();
|
||||
await scanner.ScanLibrary(library.Id);
|
||||
|
||||
var postLib = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(library.Id, LibraryIncludes.Series);
|
||||
Assert.NotNull(postLib);
|
||||
Assert.Single(postLib.Series);
|
||||
|
||||
var spiceAndWolf = postLib.Series.First(x => x.Name == "Spice and Wolf");
|
||||
Assert.Equal(3, spiceAndWolf.Volumes.Count);
|
||||
Assert.Equal(4, spiceAndWolf.Volumes.Sum(v => v.Chapters.Count));
|
||||
|
||||
await SetLastScannedInThePast(spiceAndWolf);
|
||||
|
||||
// Add volume to Spice and Wolf series directory
|
||||
var spiceAndWolfDir = Path.Join(testDirectoryPath, "Spice and Wolf");
|
||||
File.Copy(Path.Join(spiceAndWolfDir, "Spice and Wolf Vol. 1.cbz"),
|
||||
Path.Join(spiceAndWolfDir, "Spice and Wolf Vol. 4.cbz"));
|
||||
|
||||
await scanner.ScanLibrary(library.Id);
|
||||
|
||||
postLib = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(library.Id, LibraryIncludes.Series);
|
||||
Assert.NotNull(postLib);
|
||||
Assert.Single(postLib.Series);
|
||||
|
||||
spiceAndWolf = postLib.Series.First(x => x.Name == "Spice and Wolf");
|
||||
Assert.Equal(4, spiceAndWolf.Volumes.Count);
|
||||
Assert.Equal(5, spiceAndWolf.Volumes.Sum(v => v.Chapters.Count));
|
||||
|
||||
await SetLastScannedInThePast(spiceAndWolf);
|
||||
|
||||
// Add file in subfolder
|
||||
spiceAndWolfDir = Path.Join(spiceAndWolfDir, "Spice and Wolf Vol. 3");
|
||||
File.Copy(Path.Join(spiceAndWolfDir, "Spice and Wolf Vol. 3 Ch. 0012.cbz"),
|
||||
Path.Join(spiceAndWolfDir, "Spice and Wolf Vol. 3 Ch. 0013.cbz"));
|
||||
|
||||
await scanner.ScanLibrary(library.Id);
|
||||
|
||||
postLib = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(library.Id, LibraryIncludes.Series);
|
||||
Assert.NotNull(postLib);
|
||||
Assert.Single(postLib.Series);
|
||||
|
||||
spiceAndWolf = postLib.Series.First(x => x.Name == "Spice and Wolf");
|
||||
Assert.Equal(4, spiceAndWolf.Volumes.Count);
|
||||
Assert.Equal(6, spiceAndWolf.Volumes.Sum(v => v.Chapters.Count));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue