Lots of work for chapters. This code will be refactored in a chapter rewrite.

This commit is contained in:
Joseph Milazzo 2021-01-27 14:14:16 -06:00
parent f430595d11
commit a42e54a078
11 changed files with 99 additions and 13 deletions

View file

@ -0,0 +1,19 @@
using System.Linq;
using API.Comparators;
using Xunit;
namespace API.Tests
{
public class ChapterSortComparerTest
{
[Theory]
[InlineData(new[] {1, 2, 0}, new[] {1, 2, 0})]
[InlineData(new[] {3, 1, 2}, new[] {1, 2, 3})]
[InlineData(new[] {1, 0, 0}, new[] {1, 0, 0})]
public void ChapterSortTest(int[] input, int[] expected)
{
Assert.Equal(expected, input.OrderBy(f => f, new ChapterSortComparer()).ToArray());
}
}
}

View file

@ -1,4 +1,6 @@
using API.Interfaces;
using System.Collections.Generic;
using API.Entities;
using API.Interfaces;
using API.Services;
using Microsoft.Extensions.Logging;
using NSubstitute;
@ -8,7 +10,7 @@ namespace API.Tests.Services
{
public class CacheServiceTests
{
private readonly ICacheService _cacheService;
private readonly CacheService _cacheService;
private readonly ILogger<CacheService> _logger = Substitute.For<ILogger<CacheService>>();
private readonly IUnitOfWork _unitOfWork = Substitute.For<IUnitOfWork>();
private readonly IArchiveService _archiveService = Substitute.For<IArchiveService>();
@ -56,6 +58,42 @@ namespace API.Tests.Services
// Assert.Equal(expected, _cacheService.GetCachedPagePath(volume, pageNum));
Assert.True(true);
}
[Fact]
public void GetOrderedChaptersTest()
{
var files = new List<MangaFile>()
{
new()
{
Chapter = 1
},
new()
{
Chapter = 2
},
new()
{
Chapter = 0
},
};
var expected = new List<MangaFile>()
{
new()
{
Chapter = 1
},
new()
{
Chapter = 2
},
new()
{
Chapter = 0
},
};
Assert.NotStrictEqual(expected, _cacheService.GetOrderedChapters(files));
}
}

View file

@ -11,7 +11,6 @@ namespace API.Tests.Services
new[] {"x1.jpg", "x10.jpg", "x3.jpg", "x4.jpg", "x11.jpg"},
new[] {"x1.jpg", "x3.jpg", "x4.jpg", "x10.jpg", "x11.jpg"}
)]
public void TestLogicalComparer(string[] input, string[] expected)
{
NumericComparer nc = new NumericComparer();