Cleanup and moved a test to proper place

This commit is contained in:
Joseph Milazzo 2021-01-25 18:22:27 -06:00
parent 165757d338
commit c57b77f092
5 changed files with 31 additions and 32 deletions

View file

@ -3,18 +3,9 @@ using Xunit;
namespace API.Tests.Services namespace API.Tests.Services
{ {
public class ImageProviderTest 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)));
// }
} }
} }

View file

@ -1,7 +1,9 @@
using API.Interfaces; using System.IO;
using API.Interfaces;
using API.Services; using API.Services;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NSubstitute; using NSubstitute;
using Xunit;
namespace API.Tests.Services namespace API.Tests.Services
{ {
@ -15,6 +17,15 @@ namespace API.Tests.Services
_scannerService = new ScannerService(_unitOfWork, _logger); _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)));
}
} }
} }

View file

@ -1,5 +1,4 @@
using System.IO; using System.IO;
using API.Services;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace API.Controllers namespace API.Controllers

View file

@ -3,12 +3,9 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using API.Data; using API.Data;
using API.DTOs; using API.DTOs;
using API.Entities;
using API.Extensions; using API.Extensions;
using API.Interfaces; using API.Interfaces;
using API.Services;
using AutoMapper; using AutoMapper;
using AutoMapper.QueryableExtensions;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;

View file

@ -1,11 +1,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using API.Constants; using API.Constants;
using API.Entities; using API.Entities;
using API.Services; using API.Services;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
namespace API.Data namespace API.Data
{ {
@ -31,20 +31,21 @@ namespace API.Data
public static async Task SeedSettings(DataContext context) public static async Task SeedSettings(DataContext context)
{ {
// NOTE: This needs to check if settings already exists before inserting. IList<ServerSetting> defaultSettings = new List<ServerSetting>()
// IList<ServerSetting> defaultSettings = new List<ServerSetting>() {
// { new() {Key = "CacheDirectory", Value = CacheService.CacheDirectory}
// new ServerSetting() {Key = "CacheDirectory", Value = CacheService.CacheDirectory} };
// }; var settings = await context.ServerSetting.Select(s => s).ToListAsync();
// foreach (var defaultSetting in defaultSettings)
// await context.ServerSetting.AddRangeAsync(defaultSettings); {
// await context.SaveChangesAsync(); var existing = settings.SingleOrDefault(s => s.Key == defaultSetting.Key);
// await context.ServerSetting.AddAsync(new ServerSetting if (existing == null)
// { {
// CacheDirectory = CacheService.CacheDirectory settings.Add(defaultSetting);
// }); }
// }
// await context.SaveChangesAsync();
await context.SaveChangesAsync();
} }
} }
} }