22using Quartz ;
33using SharpIpp . Models ;
44using SharpIpp . Protocol . Models ;
5+ using System . IO . Abstractions ;
56
67namespace SharpIppNextServer . Services ;
78
89public class JobService (
910 PrinterService printerService ,
10- IWebHostEnvironment env ) : IJob
11+ IWebHostEnvironment env ,
12+ IFileSystem fileSystem ) : IJob
1113{
1214 private readonly FileExtensionContentTypeProvider _contentTypeProvider = new ( ) ;
1315
@@ -69,7 +71,7 @@ private async Task SaveAsync(string prefix, SendUriRequest request)
6971 if ( ! result . IsSuccessStatusCode )
7072 return ;
7173 using var stream = await result . Content . ReadAsStreamAsync ( ) ;
72- await SaveAsync ( stream , GetFileName ( prefix , request . DocumentAttributes , Path . GetFileNameWithoutExtension ( request . DocumentUri . LocalPath ) , Path . GetExtension ( request . DocumentUri . LocalPath ) ) ) ;
74+ await SaveAsync ( stream , GetFileName ( prefix , request . DocumentAttributes , fileSystem . Path . GetFileNameWithoutExtension ( request . DocumentUri . LocalPath ) , fileSystem . Path . GetExtension ( request . DocumentUri . LocalPath ) ) ) ;
7375 }
7476
7577 private string GetFileName ( string prefix , DocumentAttributes ? documentAttributes , string ? alternativeDocumentName = null , string ? alternativeExtension = null )
@@ -82,9 +84,9 @@ private string GetFileName(string prefix, DocumentAttributes? documentAttributes
8284
8385 private async Task SaveAsync ( Stream stream , string fileName )
8486 {
85- var path = Path . Combine ( env . ContentRootPath , "jobs" , fileName ) ;
86- Directory . CreateDirectory ( Path . Combine ( env . ContentRootPath , "jobs" ) ) ;
87- using var fileStream = new FileStream ( path , FileMode . OpenOrCreate ) ;
87+ var path = fileSystem . Path . Combine ( env . ContentRootPath , "jobs" , fileName ) ;
88+ fileSystem . Directory . CreateDirectory ( fileSystem . Path . Combine ( env . ContentRootPath , "jobs" ) ) ;
89+ using var fileStream = fileSystem . FileStream . New ( path , FileMode . OpenOrCreate ) ;
8890 await stream . CopyToAsync ( fileStream ) ;
8991 }
9092}
0 commit comments