A hefty refactor of the ScanLibrary code. There were significant fallouts due to duplicate entities getting created and SingleOrDefaults failing.
This commit is contained in:
parent
39fa750d96
commit
9461b89725
15 changed files with 1075 additions and 153 deletions
|
|
@ -1,7 +1,115 @@
|
|||
namespace API.Tests.Services
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using API.Entities;
|
||||
using API.Interfaces;
|
||||
using API.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace API.Tests.Services
|
||||
{
|
||||
public class ScannerService
|
||||
public class ScannerServiceTests
|
||||
{
|
||||
private readonly ScannerService _scannerService;
|
||||
private readonly ILogger<ScannerService> _logger = Substitute.For<ILogger<ScannerService>>();
|
||||
private readonly IUnitOfWork _unitOfWork = Substitute.For<IUnitOfWork>();
|
||||
private readonly IArchiveService _archiveService = Substitute.For<IArchiveService>();
|
||||
//private readonly IDirectoryService _directoryService = Substitute.For<DirectoryService>();
|
||||
private Library _libraryMock;
|
||||
|
||||
public ScannerServiceTests()
|
||||
{
|
||||
_scannerService = new ScannerService(_unitOfWork, _logger, _archiveService);
|
||||
_libraryMock = new Library()
|
||||
{
|
||||
Id = 1,
|
||||
Name = "Manga",
|
||||
Folders = new List<FolderPath>()
|
||||
{
|
||||
new FolderPath()
|
||||
{
|
||||
Id = 1,
|
||||
LastScanned = DateTime.Now,
|
||||
LibraryId = 1,
|
||||
Path = "E:/Manga"
|
||||
}
|
||||
},
|
||||
LastModified = DateTime.Now,
|
||||
Series = new List<Series>()
|
||||
{
|
||||
new Series()
|
||||
{
|
||||
Id = 0,
|
||||
Name = "Darker Than Black"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistingOrDefault_Should_BeFromLibrary()
|
||||
{
|
||||
var allSeries = new List<Series>()
|
||||
{
|
||||
new Series() {Id = 2, Name = "Darker Than Black"},
|
||||
new Series() {Id = 3, Name = "Darker Than Black - Some Extension"},
|
||||
new Series() {Id = 4, Name = "Akame Ga Kill"},
|
||||
};
|
||||
Assert.Equal(_libraryMock.Series.ElementAt(0).Id, ScannerService.ExistingOrDefault(_libraryMock, allSeries, "Darker Than Black").Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistingOrDefault_Should_BeFromAllSeries()
|
||||
{
|
||||
var allSeries = new List<Series>()
|
||||
{
|
||||
new Series() {Id = 2, Name = "Darker Than Black"},
|
||||
new Series() {Id = 3, Name = "Darker Than Black - Some Extension"},
|
||||
new Series() {Id = 4, Name = "Akame Ga Kill"},
|
||||
};
|
||||
Assert.Equal(3, ScannerService.ExistingOrDefault(_libraryMock, allSeries, "Darker Than Black - Some Extension").Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExistingOrDefault_Should_BeNull()
|
||||
{
|
||||
var allSeries = new List<Series>()
|
||||
{
|
||||
new Series() {Id = 2, Name = "Darker Than Black"},
|
||||
new Series() {Id = 3, Name = "Darker Than Black - Some Extension"},
|
||||
new Series() {Id = 4, Name = "Akame Ga Kill"},
|
||||
};
|
||||
Assert.Null(ScannerService.ExistingOrDefault(_libraryMock, allSeries, "Non existing series"));
|
||||
}
|
||||
|
||||
// [Fact]
|
||||
// public void ScanLibrary_Should_Skip()
|
||||
// {
|
||||
//
|
||||
Library lib = new Library()
|
||||
{
|
||||
Id = 1,
|
||||
Name = "Darker Than Black",
|
||||
Folders = new List<FolderPath>()
|
||||
{
|
||||
new FolderPath()
|
||||
{
|
||||
Id = 1,
|
||||
LastScanned = DateTime.Now,
|
||||
LibraryId = 1,
|
||||
Path = "E:/Manga"
|
||||
}
|
||||
},
|
||||
LastModified = DateTime.Now
|
||||
};
|
||||
//
|
||||
// _unitOfWork.LibraryRepository.GetLibraryForIdAsync(1).Returns(lib);
|
||||
//
|
||||
// _scannerService.ScanLibrary(1, false);
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0"?>
|
||||
<ComicInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<Title>v01</Title>
|
||||
<Series>BTOOOM!</Series>
|
||||
<Web>https://www.comixology.com/BTOOOM/digital-comic/450184</Web>
|
||||
<Summary>By all counts, Ryouta Sakamoto is a loser when he's not holed up in his room, bombing things into oblivion in his favorite online action RPG. But his very own uneventful life is blown to pieces when he's abducted and taken to an uninhabited island, where he soon learns the hard way that he's being pitted against others just like him in a explosives-riddled death match! How could this be happening? Who's putting them up to this? And why!? The name, not to mention the objective, of this very real survival game is eerily familiar to Ryouta, who has mastered its virtual counterpart-BTOOOM! Can Ryouta still come out on top when he's playing for his life!?</Summary>
|
||||
<Notes>Scraped metadata from Comixology [CMXDB450184]</Notes>
|
||||
<Publisher>Yen Press</Publisher>
|
||||
<Genre>Manga, Movies & TV</Genre>
|
||||
<PageCount>194</PageCount>
|
||||
<LanguageISO>en</LanguageISO>
|
||||
<ScanInformation></ScanInformation>
|
||||
</ComicInfo>
|
||||
Loading…
Add table
Add a link
Reference in a new issue