44using Moq ;
55using NSubstitute ;
66using OpenMediaServer . Interfaces . Services ;
7+ using OpenMediaServer . Interfaces . Services . Metadata ;
78using OpenMediaServer . Models ;
89using OpenMediaServer . Services ;
910using OpenMediaServer . Services . Discovery ;
11+ using OpenMediaServer . Services . Metadata ;
1012using OpenMediaServer . Test . Mocks ;
1113using Shouldly ;
1214
@@ -15,20 +17,26 @@ namespace OpenMediaServer.Test.Services;
1517public class DiscoveryAudiobookServiceShould
1618{
1719 private readonly ILogger < DiscoveryAudiobookService > _logger ;
18- private readonly FileSystemRepoMock _storageRepository ;
20+ private readonly DataRepoMock _storageRepository ;
1921 private readonly IFileInfoService _fileInfoService ;
2022 private readonly DiscoveryAudiobookService _inventoryBookService ;
2123 private readonly IInventoryService _inventoryService ;
24+ private readonly IVersionService _versionService ;
25+ private readonly IPartService _partService ;
26+ private readonly IAudioBookMetadataService _audioBookMetadataService ;
2227
2328 public DiscoveryAudiobookServiceShould ( )
2429 {
2530 Setup . Configure ( ) ;
2631
2732 _logger = Substitute . For < ILogger < DiscoveryAudiobookService > > ( ) ;
28- _storageRepository = new FileSystemRepoMock ( ) ;
33+ _storageRepository = new DataRepoMock ( ) ;
2934 _fileInfoService = Substitute . For < IFileInfoService > ( ) ;
35+ _partService = Substitute . For < IPartService > ( ) ;
36+ _audioBookMetadataService = Substitute . For < IAudioBookMetadataService > ( ) ;
37+ _versionService = new VersionServiceMock ( ) ;
3038 _inventoryService = new InventoryService ( Substitute . For < ILogger < InventoryService > > ( ) , _storageRepository , Mock . Of < IImageService > ( ) ) ;
31- _inventoryBookService = new DiscoveryAudiobookService ( _logger , _fileInfoService , _inventoryService , Substitute . For < IMetadataService > ( ) ) ;
39+ _inventoryBookService = new DiscoveryAudiobookService ( _logger , _fileInfoService , _inventoryService , Substitute . For < IMetadataService > ( ) , _versionService , _partService , _audioBookMetadataService ) ;
3240 }
3341
3442 [ Theory ]
@@ -45,18 +53,18 @@ public async Task Create_FirstItemBook(string path, string title, string? folder
4553 // Act
4654 await _inventoryBookService . CreateAudiobook ( path ) ;
4755 var resultJson = _storageRepository . WrittenObjects . First ( ) ;
48- var result = JsonSerializer . Deserialize < IEnumerable < Audiobook > > ( resultJson ) ;
56+ var resultItem = JsonSerializer . Deserialize < InventoryItem > ( resultJson , Globals . JsonOptions ) ;
57+ var versions = await _versionService . List ( ) ;
4958
5059 // Assert
51- var resultItem = result . First ( ) ;
5260 resultItem . Id . ShouldNotBe ( Guid . Empty ) ;
5361 resultItem . Title . ShouldBe ( title ) ;
5462 resultItem . Category . ShouldBe ( "Audiobook" ) ;
5563 resultItem . MetadataId . ShouldNotBe ( Guid . Empty ) ;
56- resultItem . Versions . ShouldNotBeNull ( ) ;
57- resultItem . Versions . Count ( ) . ShouldBe ( 1 ) ;
58- resultItem . Versions . First ( ) . Id . ShouldNotBe ( Guid . Empty ) ;
59- resultItem . Versions . First ( ) . Path . ShouldBe ( path ) ;
64+ versions . ShouldNotBeNull ( ) ;
65+ versions . Count ( ) . ShouldBe ( 1 ) ;
66+ versions . First ( ) . Id . ShouldNotBe ( Guid . Empty ) ;
67+ versions . First ( ) . Path . ShouldBe ( path ) ;
6068 resultItem . FolderPath . ShouldBe ( folderPath ) ;
6169 }
6270}
0 commit comments