Implemented download log files (not in service). Refactored backupservice to handle log file splitting. Improved a few interfaces and added some unit tests around them.
This commit is contained in:
parent
30352403cf
commit
bbb4240e20
22 changed files with 292 additions and 46 deletions
46
API.Tests/Services/BackupServiceTests.cs
Normal file
46
API.Tests/Services/BackupServiceTests.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using API.Interfaces;
|
||||
using API.Services;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
|
||||
namespace API.Tests.Services
|
||||
{
|
||||
public class BackupServiceTests
|
||||
{
|
||||
private readonly DirectoryService _directoryService;
|
||||
private readonly BackupService _backupService;
|
||||
private readonly IUnitOfWork _unitOfWork = Substitute.For<IUnitOfWork>();
|
||||
private readonly ILogger<DirectoryService> _directoryLogger = Substitute.For<ILogger<DirectoryService>>();
|
||||
private readonly ILogger<BackupService> _logger = Substitute.For<ILogger<BackupService>>();
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
// public BackupServiceTests()
|
||||
// {
|
||||
// var inMemorySettings = new Dictionary<string, string> {
|
||||
// {"Logging:File:MaxRollingFiles", "0"},
|
||||
// {"Logging:File:Path", "file.log"},
|
||||
// };
|
||||
//
|
||||
// _config = new ConfigurationBuilder()
|
||||
// .AddInMemoryCollection(inMemorySettings)
|
||||
// .Build();
|
||||
//
|
||||
// //_config.GetMaxRollingFiles().Returns(0);
|
||||
// //_config.GetLoggingFileName().Returns("file.log");
|
||||
// //var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/BackupService/");
|
||||
// //Directory.GetCurrentDirectory().Returns(testDirectory);
|
||||
//
|
||||
// _directoryService = new DirectoryService(_directoryLogger);
|
||||
// _backupService = new BackupService(_unitOfWork, _logger, _directoryService, _config);
|
||||
// }
|
||||
//
|
||||
// [Fact]
|
||||
// public void Test()
|
||||
// {
|
||||
// _backupService.BackupDatabase();
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -48,7 +48,7 @@ namespace API.Tests.Services
|
|||
// var cacheService = Substitute.ForPartsOf<CacheService>();
|
||||
// cacheService.Configure().CacheDirectoryIsAccessible().Returns(true);
|
||||
// cacheService.Configure().GetVolumeCachePath(1, volume.Files.ElementAt(0)).Returns("cache/1/");
|
||||
// _directoryService.Configure().GetFiles("cache/1/").Returns(new string[] {"pexels-photo-6551949.jpg"});
|
||||
// _directoryService.Configure().GetFilesWithExtension("cache/1/").Returns(new string[] {"pexels-photo-6551949.jpg"});
|
||||
// Assert.Equal(expected, _cacheService.GetCachedPagePath(volume, pageNum));
|
||||
Assert.True(true);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using API.Services;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using API.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
@ -17,15 +19,60 @@ namespace API.Tests.Services
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void GetFiles_Test()
|
||||
public void GetFiles_WithCustomRegex_ShouldPass_Test()
|
||||
{
|
||||
//_directoryService.GetFiles()
|
||||
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/DirectoryService/regex");
|
||||
var files = _directoryService.GetFiles(testDirectory, @"file\d*.txt");
|
||||
Assert.Equal(2, files.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetFiles_TopLevel_ShouldBeEmpty_Test()
|
||||
{
|
||||
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/DirectoryService");
|
||||
var files = _directoryService.GetFiles(testDirectory);
|
||||
Assert.Empty(files);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetFilesWithExtensions_ShouldBeEmpty_Test()
|
||||
{
|
||||
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/DirectoryService/extensions");
|
||||
var files = _directoryService.GetFiles(testDirectory, "*.txt");
|
||||
Assert.Empty(files);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetFilesWithExtensions_Test()
|
||||
{
|
||||
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/DirectoryService/extension");
|
||||
var files = _directoryService.GetFiles(testDirectory, ".cbz|.rar");
|
||||
Assert.Equal(3, files.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetFilesWithExtensions_BadDirectory_ShouldBeEmpty_Test()
|
||||
{
|
||||
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/DirectoryService/doesntexist");
|
||||
var files = _directoryService.GetFiles(testDirectory, ".cbz|.rar");
|
||||
Assert.Empty(files);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ListDirectory_Test()
|
||||
public void ListDirectory_SubDirectory_Test()
|
||||
{
|
||||
|
||||
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/DirectoryService/");
|
||||
var dirs = _directoryService.ListDirectory(testDirectory);
|
||||
Assert.Contains(dirs, s => s.Contains("regex"));
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ListDirectory_NoSubDirectory_Test()
|
||||
{
|
||||
var dirs = _directoryService.ListDirectory("");
|
||||
Assert.DoesNotContain(dirs, s => s.Contains("regex"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue