mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-05 22:54:13 -04:00
* Made the unread badges slightly smaller and rounded on top right. * A bit more tweaks on the not read badges. Looking really nice now. * In order to start the work on managing collections from ScanLoop, I needed to refactor collection apis into the service layer and add unit tests. Removed ToUpper Normalization for new tags. * Hooked up ability to auto generate collections from SeriesGroup metadata tag.
77 lines
2.2 KiB
C#
77 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using API.Data;
|
|
using API.Entities;
|
|
using API.Entities.Enums;
|
|
using API.Entities.Metadata;
|
|
|
|
namespace API.Tests.Helpers;
|
|
|
|
/// <summary>
|
|
/// Used to help quickly create DB entities for Unit Testing
|
|
/// </summary>
|
|
public static class EntityFactory
|
|
{
|
|
public static Series CreateSeries(string name)
|
|
{
|
|
return new Series()
|
|
{
|
|
Name = name,
|
|
SortName = name,
|
|
LocalizedName = name,
|
|
NormalizedName = API.Services.Tasks.Scanner.Parser.Parser.Normalize(name),
|
|
Volumes = new List<Volume>(),
|
|
Metadata = new SeriesMetadata()
|
|
};
|
|
}
|
|
|
|
public static Volume CreateVolume(string volumeNumber, List<Chapter> chapters = null)
|
|
{
|
|
var chaps = chapters ?? new List<Chapter>();
|
|
var pages = chaps.Count > 0 ? chaps.Max(c => c.Pages) : 0;
|
|
return new Volume()
|
|
{
|
|
Name = volumeNumber,
|
|
Number = (int) API.Services.Tasks.Scanner.Parser.Parser.MinNumberFromRange(volumeNumber),
|
|
Pages = pages,
|
|
Chapters = chaps
|
|
};
|
|
}
|
|
|
|
public static Chapter CreateChapter(string range, bool isSpecial, List<MangaFile> files = null, int pageCount = 0)
|
|
{
|
|
return new Chapter()
|
|
{
|
|
IsSpecial = isSpecial,
|
|
Range = range,
|
|
Number = API.Services.Tasks.Scanner.Parser.Parser.MinNumberFromRange(range) + string.Empty,
|
|
Files = files ?? new List<MangaFile>(),
|
|
Pages = pageCount,
|
|
|
|
};
|
|
}
|
|
|
|
public static MangaFile CreateMangaFile(string filename, MangaFormat format, int pages)
|
|
{
|
|
return new MangaFile()
|
|
{
|
|
FilePath = filename,
|
|
Format = format,
|
|
Pages = pages
|
|
};
|
|
}
|
|
|
|
public static SeriesMetadata CreateSeriesMetadata(ICollection<CollectionTag> collectionTags)
|
|
{
|
|
return new SeriesMetadata()
|
|
{
|
|
CollectionTags = collectionTags
|
|
};
|
|
}
|
|
|
|
public static CollectionTag CreateCollectionTag(int id, string title, string summary, bool promoted)
|
|
{
|
|
return DbFactory.CollectionTag(id, title, summary, promoted);
|
|
}
|
|
}
|