diff --git a/API.Tests/Services/ImageProviderTest.cs b/API.Tests/Services/ImageProviderTest.cs index 5636d39a4..485dc0a5e 100644 --- a/API.Tests/Services/ImageProviderTest.cs +++ b/API.Tests/Services/ImageProviderTest.cs @@ -3,18 +3,9 @@ using Xunit; namespace API.Tests.Services { + public class ImageProviderTest { - // [Theory] - // [InlineData("v10.cbz", "v10.expected.jpg")] - // [InlineData("v10 - with folder.cbz", "v10 - with folder.expected.jpg")] - // [InlineData("v10 - nested folder.cbz", "v10 - nested folder.expected.jpg")] - // public void GetCoverImageTest(string inputFile, string expectedOutputFile) - // { - // var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ImageProvider"); - // var expectedBytes = File.ReadAllBytes(Path.Join(testDirectory, expectedOutputFile)); - // // TODO: Implement this with ScannerService - // //Assert.Equal(expectedBytes, ImageProvider.GetCoverImage(Path.Join(testDirectory, inputFile))); - // } + } } \ No newline at end of file diff --git a/API.Tests/Services/ScannerServiceTests.cs b/API.Tests/Services/ScannerServiceTests.cs index 79b487a36..78591b212 100644 --- a/API.Tests/Services/ScannerServiceTests.cs +++ b/API.Tests/Services/ScannerServiceTests.cs @@ -1,7 +1,9 @@ -using API.Interfaces; +using System.IO; +using API.Interfaces; using API.Services; using Microsoft.Extensions.Logging; using NSubstitute; +using Xunit; namespace API.Tests.Services { @@ -15,6 +17,15 @@ namespace API.Tests.Services _scannerService = new ScannerService(_unitOfWork, _logger); } - // TODO: Start adding tests for how scanner works so we can ensure fallbacks, etc work + [Theory] + [InlineData("v10.cbz", "v10.expected.jpg")] + [InlineData("v10 - with folder.cbz", "v10 - with folder.expected.jpg")] + [InlineData("v10 - nested folder.cbz", "v10 - nested folder.expected.jpg")] + public void GetCoverImageTest(string inputFile, string expectedOutputFile) + { + var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ImageProvider"); + var expectedBytes = File.ReadAllBytes(Path.Join(testDirectory, expectedOutputFile)); + Assert.Equal(expectedBytes, _scannerService.GetCoverImage(Path.Join(testDirectory, inputFile))); + } } } \ No newline at end of file diff --git a/API/Controllers/FallbackController.cs b/API/Controllers/FallbackController.cs index 74ff82999..36b173745 100644 --- a/API/Controllers/FallbackController.cs +++ b/API/Controllers/FallbackController.cs @@ -1,5 +1,4 @@ using System.IO; -using API.Services; using Microsoft.AspNetCore.Mvc; namespace API.Controllers diff --git a/API/Controllers/SettingsController.cs b/API/Controllers/SettingsController.cs index 910b10f89..1b4cdd3af 100644 --- a/API/Controllers/SettingsController.cs +++ b/API/Controllers/SettingsController.cs @@ -3,12 +3,9 @@ using System.Linq; using System.Threading.Tasks; using API.Data; using API.DTOs; -using API.Entities; using API.Extensions; using API.Interfaces; -using API.Services; using AutoMapper; -using AutoMapper.QueryableExtensions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; diff --git a/API/Data/Seed.cs b/API/Data/Seed.cs index 9ad42b61c..5071b9fa5 100644 --- a/API/Data/Seed.cs +++ b/API/Data/Seed.cs @@ -1,11 +1,11 @@ using System.Collections.Generic; -using System.IO; using System.Linq; using System.Threading.Tasks; using API.Constants; using API.Entities; using API.Services; using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; namespace API.Data { @@ -31,20 +31,21 @@ namespace API.Data public static async Task SeedSettings(DataContext context) { - // NOTE: This needs to check if settings already exists before inserting. - // IList defaultSettings = new List() - // { - // new ServerSetting() {Key = "CacheDirectory", Value = CacheService.CacheDirectory} - // }; - // - // await context.ServerSetting.AddRangeAsync(defaultSettings); - // await context.SaveChangesAsync(); - // await context.ServerSetting.AddAsync(new ServerSetting - // { - // CacheDirectory = CacheService.CacheDirectory - // }); - // - // await context.SaveChangesAsync(); + IList defaultSettings = new List() + { + new() {Key = "CacheDirectory", Value = CacheService.CacheDirectory} + }; + var settings = await context.ServerSetting.Select(s => s).ToListAsync(); + foreach (var defaultSetting in defaultSettings) + { + var existing = settings.SingleOrDefault(s => s.Key == defaultSetting.Key); + if (existing == null) + { + settings.Add(defaultSetting); + } + } + + await context.SaveChangesAsync(); } } } \ No newline at end of file