Kavita/API.Tests/Entities/ComicInfoTests.cs
Joe Milazzo 6ea9f2c73e
Scan Loop Fortification (#1573)
* Cleanup some messaging in the scan loop to be more context bearing

* Added Response Caching to Series Detail for 1 min, due to the heavy nature of the call.

* Refactored code to make it so that processing of series runs sync correctly.

Added a log to inform the user of corrupted volume from buggy code in v0.5.6.

* Moved folder watching out of experimental

* Fixed an issue where empty folders could break the scan loop

* Another fix for when dates aren't valid, the scanner wouldn't get the proper min and would throw an exception (develop)

* Implemented the ability to edit release year from the UI for a series.

* Added a unit test for some new logic

* Code smells

* Rewrote the handler for suspending watching to be more resilient and ensure no two threads have a race condition.

* More error handling for when a ScanFolder is invoked but multiple series belong to that folder, log it to the user and default to a library scan.

* ScanSeries now will check for kavitaignores higher than it's own folder and respect library level.

* Fixed an issue where image series with a folder name containing the word "folder" could get ignored as it thought the image was a cover image.

When a series folder is moved or deleted, skip parent ignore finding.

* Removed some old files, added in scanFolder a check if the series found for a folder is in a book library and if so to always do a library scan (as books are often nested into one folder with  multiple series). Added some unit tests

* Refactored some scan loop logic into ComicInfo, wrote tests and updated some documentation to make the fields more clear.

* Added a test for GetLastWriteTime based on recent bug

* Cleaned up some redundant code

* Fixed a bad merge

* Code smells

* Removed a package that's no longer used.

* Ensure we check against ScanQueue on ScanFolder enqueuing

* Documentation and more bullet proofing to ensure Hangfire checks work more as expected
2022-10-09 09:23:41 -07:00

97 lines
2.3 KiB
C#

using API.Data.Metadata;
using API.Entities.Enums;
using Xunit;
namespace API.Tests.Entities;
public class ComicInfoTests
{
#region ConvertAgeRatingToEnum
[Theory]
[InlineData("G", AgeRating.G)]
[InlineData("Everyone", AgeRating.Everyone)]
[InlineData("Teen", AgeRating.Teen)]
[InlineData("Adults Only 18+", AgeRating.AdultsOnly)]
[InlineData("Early Childhood", AgeRating.EarlyChildhood)]
[InlineData("Everyone 10+", AgeRating.Everyone10Plus)]
[InlineData("M", AgeRating.Mature)]
[InlineData("MA15+", AgeRating.Mature15Plus)]
[InlineData("Mature 17+", AgeRating.Mature17Plus)]
[InlineData("Rating Pending", AgeRating.RatingPending)]
[InlineData("X18+", AgeRating.X18Plus)]
[InlineData("Kids to Adults", AgeRating.KidsToAdults)]
[InlineData("NotValid", AgeRating.Unknown)]
[InlineData("PG", AgeRating.PG)]
[InlineData("R18+", AgeRating.R18Plus)]
public void ConvertAgeRatingToEnum_ShouldConvertCorrectly(string input, AgeRating expected)
{
Assert.Equal(expected, ComicInfo.ConvertAgeRatingToEnum(input));
}
[Fact]
public void ConvertAgeRatingToEnum_ShouldCompareCaseInsensitive()
{
Assert.Equal(AgeRating.RatingPending, ComicInfo.ConvertAgeRatingToEnum("rating pending"));
}
#endregion
#region CalculatedCount
[Fact]
public void CalculatedCount_ReturnsVolumeCount()
{
var ci = new ComicInfo()
{
Number = "5",
Volume = "10",
Count = 10
};
Assert.Equal(5, ci.CalculatedCount());
}
[Fact]
public void CalculatedCount_ReturnsNoCountWhenCountNotSet()
{
var ci = new ComicInfo()
{
Number = "5",
Volume = "10",
Count = 0
};
Assert.Equal(5, ci.CalculatedCount());
}
[Fact]
public void CalculatedCount_ReturnsNumberCount()
{
var ci = new ComicInfo()
{
Number = "5",
Volume = "",
Count = 10
};
Assert.Equal(5, ci.CalculatedCount());
}
[Fact]
public void CalculatedCount_ReturnsNumberCount_OnlyWholeNumber()
{
var ci = new ComicInfo()
{
Number = "5.7",
Volume = "",
Count = 10
};
Assert.Equal(5, ci.CalculatedCount());
}
#endregion
}