mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Merge pull request #279 from BinaryAlley/feature/map-openlibrary-publish-country
Maps OpenLibrary MARC publish_country to ReleaseCountry
This commit is contained in:
7 files changed
+365
-27
No files matched your search
+3
-3
@@ -48,10 +48,10 @@ internal sealed record OpenLibraryEditionResponse
|
||||
public List<string> Publishers { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the publication places of the edition.
|
||||
/// Gets the MARC 21 country code of the publication place of the edition.
|
||||
/// </summary>
|
||||
[JsonPropertyName("publish_places")]
|
||||
public List<string> PublishPlaces { get; init; } = [];
|
||||
[JsonPropertyName("publish_country")]
|
||||
public string? PublishCountry { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of pages of the edition.
|
||||
|
||||
-6
@@ -70,12 +70,6 @@ internal sealed record OpenLibrarySearchDocumentResponse
|
||||
[JsonPropertyName("subject")]
|
||||
public List<string> Subjects { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the publication places of the search document.
|
||||
/// </summary>
|
||||
[JsonPropertyName("publish_place")]
|
||||
public List<string> PublishPlaces { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the median number of pages of the search document.
|
||||
/// </summary>
|
||||
|
||||
@@ -37,7 +37,7 @@ internal sealed class OpenLibraryHttpClient
|
||||
|
||||
private const string SEARCH_FIELDS =
|
||||
"key,title,author_name,author_key,first_publish_year,edition_key,isbn," +
|
||||
"language,publisher,subject,publish_place,number_of_pages_median," +
|
||||
"language,publisher,subject,number_of_pages_median," +
|
||||
"ratings_average,ratings_count,id_amazon,id_goodreads,id_google," +
|
||||
"id_librarything,lccn,oclc";
|
||||
|
||||
|
||||
@@ -50,6 +50,13 @@ internal static partial class OpenLibraryMapper
|
||||
"travel", "young adult"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The release countries, keyed by their MARC 21 country code. The two code standards do not share their values (for example, MARC 21 uses
|
||||
/// <c>enk</c> for England, <c>gw</c> for Germany, and <c>xxu</c> for the United States), so they are translated through an explicit table.
|
||||
/// The table also holds the discontinued codes that still appear in catalogued records, mapped to the country that succeeded them.
|
||||
/// </summary>
|
||||
private static readonly Dictionary<string, ReleaseCountry> s_releaseCountriesByMarcCode = BuildReleaseCountriesByMarcCode();
|
||||
|
||||
/// <summary>
|
||||
/// Maps the edition, work, author, rating, and search data into a full book request.
|
||||
/// </summary>
|
||||
@@ -96,7 +103,7 @@ internal static partial class OpenLibraryMapper
|
||||
|
||||
string? title = FirstNotEmpty(edition?.Title, work?.Title, fallback?.Title);
|
||||
string? description = ReadText(work?.Description ?? default) ?? ReadText(edition?.Notes ?? default);
|
||||
string? releaseCountry = edition?.PublishPlaces.FirstOrDefault() ?? fallback?.PublishPlaces.FirstOrDefault();
|
||||
string? releaseCountry = edition?.PublishCountry;
|
||||
string? releaseVersion = edition?.EditionName;
|
||||
|
||||
return new BookMetadataDto(
|
||||
@@ -332,16 +339,330 @@ internal static partial class OpenLibraryMapper
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps a country string into a release country.
|
||||
/// Maps a MARC 21 country code into a release country.
|
||||
/// </summary>
|
||||
/// <param name="rawCountry">The country string to map.</param>
|
||||
/// <returns>The mapped release country, or <see langword="null"/> when the string is empty or is not a known ISO 3166-1 alpha-2 code.</returns>
|
||||
private static ReleaseCountry? MapReleaseCountry(string? rawCountry)
|
||||
/// <param name="marcCountryCode">The MARC 21 country code to map.</param>
|
||||
/// <returns>
|
||||
/// The mapped release country, or <see langword="null"/> when the code is empty or is not a known MARC 21 country code.
|
||||
/// </returns>
|
||||
private static ReleaseCountry? MapReleaseCountry(string? marcCountryCode)
|
||||
{
|
||||
string? value = NullIfWhiteSpace(rawCountry);
|
||||
if (value is null)
|
||||
if (string.IsNullOrWhiteSpace(marcCountryCode))
|
||||
return null;
|
||||
return Enum.TryParse(value, ignoreCase: true, out ReleaseCountry releaseCountry) ? releaseCountry : null;
|
||||
return s_releaseCountriesByMarcCode.TryGetValue(marcCountryCode.Trim(), out ReleaseCountry releaseCountry) ? releaseCountry : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the map of the release countries, keyed by their MARC 21 country code.
|
||||
/// </summary>
|
||||
/// <returns>The release countries, keyed by their MARC 21 country code.</returns>
|
||||
private static Dictionary<string, ReleaseCountry> BuildReleaseCountriesByMarcCode()
|
||||
{
|
||||
return new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["aa"] = ReleaseCountry.AL,
|
||||
["abc"] = ReleaseCountry.CA,
|
||||
["aca"] = ReleaseCountry.AU,
|
||||
["ae"] = ReleaseCountry.DZ,
|
||||
["af"] = ReleaseCountry.AF,
|
||||
["ag"] = ReleaseCountry.AR,
|
||||
["ai"] = ReleaseCountry.AM,
|
||||
["aj"] = ReleaseCountry.AZ,
|
||||
["aku"] = ReleaseCountry.US,
|
||||
["alu"] = ReleaseCountry.US,
|
||||
["an"] = ReleaseCountry.AD,
|
||||
["ao"] = ReleaseCountry.AO,
|
||||
["aq"] = ReleaseCountry.AG,
|
||||
["aru"] = ReleaseCountry.US,
|
||||
["at"] = ReleaseCountry.AU,
|
||||
["au"] = ReleaseCountry.AT,
|
||||
["azu"] = ReleaseCountry.US,
|
||||
["ba"] = ReleaseCountry.BH,
|
||||
["bb"] = ReleaseCountry.BB,
|
||||
["bcc"] = ReleaseCountry.CA,
|
||||
["bd"] = ReleaseCountry.BI,
|
||||
["be"] = ReleaseCountry.BE,
|
||||
["bf"] = ReleaseCountry.BS,
|
||||
["bg"] = ReleaseCountry.BD,
|
||||
["bh"] = ReleaseCountry.BZ,
|
||||
["bl"] = ReleaseCountry.BR,
|
||||
["bn"] = ReleaseCountry.BA,
|
||||
["bo"] = ReleaseCountry.BO,
|
||||
["bp"] = ReleaseCountry.SB,
|
||||
["br"] = ReleaseCountry.MM,
|
||||
["bs"] = ReleaseCountry.BW,
|
||||
["bt"] = ReleaseCountry.BT,
|
||||
["bu"] = ReleaseCountry.BG,
|
||||
["bw"] = ReleaseCountry.BY,
|
||||
["bx"] = ReleaseCountry.BN,
|
||||
["cau"] = ReleaseCountry.US,
|
||||
["cb"] = ReleaseCountry.KH,
|
||||
["cc"] = ReleaseCountry.CN,
|
||||
["cd"] = ReleaseCountry.TD,
|
||||
["ce"] = ReleaseCountry.LK,
|
||||
["cf"] = ReleaseCountry.CG,
|
||||
["cg"] = ReleaseCountry.CD,
|
||||
["ch"] = ReleaseCountry.TW,
|
||||
["ci"] = ReleaseCountry.HR,
|
||||
["ck"] = ReleaseCountry.CO,
|
||||
["cl"] = ReleaseCountry.CL,
|
||||
["cm"] = ReleaseCountry.CM,
|
||||
["cn"] = ReleaseCountry.CA,
|
||||
["cou"] = ReleaseCountry.US,
|
||||
["cq"] = ReleaseCountry.KM,
|
||||
["cr"] = ReleaseCountry.CR,
|
||||
["cs"] = ReleaseCountry.CZ,
|
||||
["ctu"] = ReleaseCountry.US,
|
||||
["cu"] = ReleaseCountry.CU,
|
||||
["cv"] = ReleaseCountry.CV,
|
||||
["cx"] = ReleaseCountry.CF,
|
||||
["cy"] = ReleaseCountry.CY,
|
||||
["dcu"] = ReleaseCountry.US,
|
||||
["deu"] = ReleaseCountry.US,
|
||||
["dk"] = ReleaseCountry.DK,
|
||||
["dm"] = ReleaseCountry.BJ,
|
||||
["dq"] = ReleaseCountry.DM,
|
||||
["dr"] = ReleaseCountry.DO,
|
||||
["ea"] = ReleaseCountry.ER,
|
||||
["ec"] = ReleaseCountry.EC,
|
||||
["eg"] = ReleaseCountry.GQ,
|
||||
["em"] = ReleaseCountry.TL,
|
||||
["enk"] = ReleaseCountry.GB,
|
||||
["er"] = ReleaseCountry.EE,
|
||||
["err"] = ReleaseCountry.EE,
|
||||
["es"] = ReleaseCountry.SV,
|
||||
["et"] = ReleaseCountry.ET,
|
||||
["fi"] = ReleaseCountry.FI,
|
||||
["fj"] = ReleaseCountry.FJ,
|
||||
["flu"] = ReleaseCountry.US,
|
||||
["fm"] = ReleaseCountry.FM,
|
||||
["fr"] = ReleaseCountry.FR,
|
||||
["ft"] = ReleaseCountry.DJ,
|
||||
["gau"] = ReleaseCountry.US,
|
||||
["gb"] = ReleaseCountry.KI,
|
||||
["gd"] = ReleaseCountry.GD,
|
||||
["ge"] = ReleaseCountry.DE,
|
||||
["gh"] = ReleaseCountry.GH,
|
||||
["gm"] = ReleaseCountry.GM,
|
||||
["go"] = ReleaseCountry.GA,
|
||||
["gr"] = ReleaseCountry.GR,
|
||||
["gs"] = ReleaseCountry.GE,
|
||||
["gsr"] = ReleaseCountry.GE,
|
||||
["gt"] = ReleaseCountry.GT,
|
||||
["gv"] = ReleaseCountry.GN,
|
||||
["gw"] = ReleaseCountry.DE,
|
||||
["gy"] = ReleaseCountry.GY,
|
||||
["gz"] = ReleaseCountry.PS,
|
||||
["hiu"] = ReleaseCountry.US,
|
||||
["ho"] = ReleaseCountry.HN,
|
||||
["ht"] = ReleaseCountry.HT,
|
||||
["hu"] = ReleaseCountry.HU,
|
||||
["iau"] = ReleaseCountry.US,
|
||||
["ic"] = ReleaseCountry.IS,
|
||||
["idu"] = ReleaseCountry.US,
|
||||
["ie"] = ReleaseCountry.IE,
|
||||
["ii"] = ReleaseCountry.IN,
|
||||
["ilu"] = ReleaseCountry.US,
|
||||
["inu"] = ReleaseCountry.US,
|
||||
["io"] = ReleaseCountry.ID,
|
||||
["iq"] = ReleaseCountry.IQ,
|
||||
["ir"] = ReleaseCountry.IR,
|
||||
["is"] = ReleaseCountry.IL,
|
||||
["it"] = ReleaseCountry.IT,
|
||||
["iv"] = ReleaseCountry.CI,
|
||||
["ja"] = ReleaseCountry.JP,
|
||||
["jm"] = ReleaseCountry.JM,
|
||||
["jo"] = ReleaseCountry.JO,
|
||||
["ke"] = ReleaseCountry.KE,
|
||||
["kg"] = ReleaseCountry.KG,
|
||||
["kgr"] = ReleaseCountry.KG,
|
||||
["kn"] = ReleaseCountry.KP,
|
||||
["ko"] = ReleaseCountry.KR,
|
||||
["ksu"] = ReleaseCountry.US,
|
||||
["ku"] = ReleaseCountry.KW,
|
||||
["kyu"] = ReleaseCountry.US,
|
||||
["kz"] = ReleaseCountry.KZ,
|
||||
["kzr"] = ReleaseCountry.KZ,
|
||||
["lau"] = ReleaseCountry.US,
|
||||
["lb"] = ReleaseCountry.LR,
|
||||
["le"] = ReleaseCountry.LB,
|
||||
["lh"] = ReleaseCountry.LI,
|
||||
["li"] = ReleaseCountry.LT,
|
||||
["lir"] = ReleaseCountry.LT,
|
||||
["lo"] = ReleaseCountry.LS,
|
||||
["ls"] = ReleaseCountry.LA,
|
||||
["lu"] = ReleaseCountry.LU,
|
||||
["lv"] = ReleaseCountry.LV,
|
||||
["lvr"] = ReleaseCountry.LV,
|
||||
["ly"] = ReleaseCountry.LY,
|
||||
["mau"] = ReleaseCountry.US,
|
||||
["mbc"] = ReleaseCountry.CA,
|
||||
["mc"] = ReleaseCountry.MC,
|
||||
["mdu"] = ReleaseCountry.US,
|
||||
["meu"] = ReleaseCountry.US,
|
||||
["mf"] = ReleaseCountry.MU,
|
||||
["mg"] = ReleaseCountry.MG,
|
||||
["miu"] = ReleaseCountry.US,
|
||||
["mk"] = ReleaseCountry.OM,
|
||||
["ml"] = ReleaseCountry.ML,
|
||||
["mm"] = ReleaseCountry.MT,
|
||||
["mnu"] = ReleaseCountry.US,
|
||||
["mo"] = ReleaseCountry.ME,
|
||||
["mou"] = ReleaseCountry.US,
|
||||
["mp"] = ReleaseCountry.MN,
|
||||
["mr"] = ReleaseCountry.MA,
|
||||
["msu"] = ReleaseCountry.US,
|
||||
["mtu"] = ReleaseCountry.US,
|
||||
["mu"] = ReleaseCountry.MR,
|
||||
["mv"] = ReleaseCountry.MD,
|
||||
["mvr"] = ReleaseCountry.MD,
|
||||
["mw"] = ReleaseCountry.MW,
|
||||
["mx"] = ReleaseCountry.MX,
|
||||
["my"] = ReleaseCountry.MY,
|
||||
["mz"] = ReleaseCountry.MZ,
|
||||
["na"] = ReleaseCountry.AN,
|
||||
["nbu"] = ReleaseCountry.US,
|
||||
["ncu"] = ReleaseCountry.US,
|
||||
["ndu"] = ReleaseCountry.US,
|
||||
["ne"] = ReleaseCountry.NL,
|
||||
["nfc"] = ReleaseCountry.CA,
|
||||
["ng"] = ReleaseCountry.NE,
|
||||
["nhu"] = ReleaseCountry.US,
|
||||
["nik"] = ReleaseCountry.GB,
|
||||
["nju"] = ReleaseCountry.US,
|
||||
["nkc"] = ReleaseCountry.CA,
|
||||
["nmu"] = ReleaseCountry.US,
|
||||
["nn"] = ReleaseCountry.VU,
|
||||
["no"] = ReleaseCountry.NO,
|
||||
["np"] = ReleaseCountry.NP,
|
||||
["nq"] = ReleaseCountry.NI,
|
||||
["nr"] = ReleaseCountry.NG,
|
||||
["nsc"] = ReleaseCountry.CA,
|
||||
["ntc"] = ReleaseCountry.CA,
|
||||
["nu"] = ReleaseCountry.NR,
|
||||
["nuc"] = ReleaseCountry.CA,
|
||||
["nvu"] = ReleaseCountry.US,
|
||||
["nyu"] = ReleaseCountry.US,
|
||||
["nz"] = ReleaseCountry.NZ,
|
||||
["ohu"] = ReleaseCountry.US,
|
||||
["oku"] = ReleaseCountry.US,
|
||||
["onc"] = ReleaseCountry.CA,
|
||||
["oru"] = ReleaseCountry.US,
|
||||
["pau"] = ReleaseCountry.US,
|
||||
["pe"] = ReleaseCountry.PE,
|
||||
["pg"] = ReleaseCountry.GW,
|
||||
["ph"] = ReleaseCountry.PH,
|
||||
["pic"] = ReleaseCountry.CA,
|
||||
["pk"] = ReleaseCountry.PK,
|
||||
["pl"] = ReleaseCountry.PL,
|
||||
["pn"] = ReleaseCountry.PA,
|
||||
["po"] = ReleaseCountry.PT,
|
||||
["pp"] = ReleaseCountry.PG,
|
||||
["pt"] = ReleaseCountry.TL,
|
||||
["pw"] = ReleaseCountry.PW,
|
||||
["py"] = ReleaseCountry.PY,
|
||||
["qa"] = ReleaseCountry.QA,
|
||||
["qea"] = ReleaseCountry.AU,
|
||||
["quc"] = ReleaseCountry.CA,
|
||||
["rb"] = ReleaseCountry.RS,
|
||||
["rh"] = ReleaseCountry.ZW,
|
||||
["riu"] = ReleaseCountry.US,
|
||||
["rm"] = ReleaseCountry.RO,
|
||||
["ru"] = ReleaseCountry.RU,
|
||||
["rur"] = ReleaseCountry.RU,
|
||||
["rw"] = ReleaseCountry.RW,
|
||||
["ry"] = ReleaseCountry.JP,
|
||||
["sa"] = ReleaseCountry.ZA,
|
||||
["sb"] = ReleaseCountry.NO,
|
||||
["scu"] = ReleaseCountry.US,
|
||||
["sd"] = ReleaseCountry.SS,
|
||||
["sdu"] = ReleaseCountry.US,
|
||||
["se"] = ReleaseCountry.SC,
|
||||
["sf"] = ReleaseCountry.ST,
|
||||
["sg"] = ReleaseCountry.SN,
|
||||
["si"] = ReleaseCountry.SG,
|
||||
["sj"] = ReleaseCountry.SD,
|
||||
["sk"] = ReleaseCountry.IN,
|
||||
["sl"] = ReleaseCountry.SL,
|
||||
["sm"] = ReleaseCountry.SM,
|
||||
["snc"] = ReleaseCountry.CA,
|
||||
["so"] = ReleaseCountry.SO,
|
||||
["sp"] = ReleaseCountry.ES,
|
||||
["sq"] = ReleaseCountry.SZ,
|
||||
["sr"] = ReleaseCountry.SR,
|
||||
["stk"] = ReleaseCountry.GB,
|
||||
["su"] = ReleaseCountry.SA,
|
||||
["sw"] = ReleaseCountry.SE,
|
||||
["sx"] = ReleaseCountry.NA,
|
||||
["sy"] = ReleaseCountry.SY,
|
||||
["sz"] = ReleaseCountry.CH,
|
||||
["ta"] = ReleaseCountry.TJ,
|
||||
["tar"] = ReleaseCountry.TJ,
|
||||
["tg"] = ReleaseCountry.TG,
|
||||
["th"] = ReleaseCountry.TH,
|
||||
["ti"] = ReleaseCountry.TN,
|
||||
["tk"] = ReleaseCountry.TM,
|
||||
["tkr"] = ReleaseCountry.TM,
|
||||
["tma"] = ReleaseCountry.AU,
|
||||
["tnu"] = ReleaseCountry.US,
|
||||
["to"] = ReleaseCountry.TO,
|
||||
["tr"] = ReleaseCountry.TT,
|
||||
["ts"] = ReleaseCountry.AE,
|
||||
["tu"] = ReleaseCountry.TR,
|
||||
["tv"] = ReleaseCountry.TV,
|
||||
["txu"] = ReleaseCountry.US,
|
||||
["tz"] = ReleaseCountry.TZ,
|
||||
["ua"] = ReleaseCountry.EG,
|
||||
["ug"] = ReleaseCountry.UG,
|
||||
["uk"] = ReleaseCountry.GB,
|
||||
["un"] = ReleaseCountry.UA,
|
||||
["unr"] = ReleaseCountry.UA,
|
||||
["ur"] = ReleaseCountry.RU,
|
||||
["us"] = ReleaseCountry.US,
|
||||
["utu"] = ReleaseCountry.US,
|
||||
["uv"] = ReleaseCountry.BF,
|
||||
["uy"] = ReleaseCountry.UY,
|
||||
["uz"] = ReleaseCountry.UZ,
|
||||
["uzr"] = ReleaseCountry.UZ,
|
||||
["vau"] = ReleaseCountry.US,
|
||||
["vc"] = ReleaseCountry.VA,
|
||||
["ve"] = ReleaseCountry.VE,
|
||||
["vm"] = ReleaseCountry.VN,
|
||||
["vn"] = ReleaseCountry.VN,
|
||||
["vra"] = ReleaseCountry.AU,
|
||||
["vs"] = ReleaseCountry.VN,
|
||||
["vtu"] = ReleaseCountry.US,
|
||||
["wau"] = ReleaseCountry.US,
|
||||
["wb"] = ReleaseCountry.DE,
|
||||
["wea"] = ReleaseCountry.AU,
|
||||
["wiu"] = ReleaseCountry.US,
|
||||
["wj"] = ReleaseCountry.PS,
|
||||
["wlk"] = ReleaseCountry.GB,
|
||||
["ws"] = ReleaseCountry.WS,
|
||||
["wvu"] = ReleaseCountry.US,
|
||||
["wyu"] = ReleaseCountry.US,
|
||||
["xc"] = ReleaseCountry.MV,
|
||||
["xd"] = ReleaseCountry.KN,
|
||||
["xe"] = ReleaseCountry.MH,
|
||||
["xga"] = ReleaseCountry.AU,
|
||||
["xk"] = ReleaseCountry.LC,
|
||||
["xm"] = ReleaseCountry.VC,
|
||||
["xn"] = ReleaseCountry.MK,
|
||||
["xna"] = ReleaseCountry.AU,
|
||||
["xo"] = ReleaseCountry.SK,
|
||||
["xoa"] = ReleaseCountry.AU,
|
||||
["xr"] = ReleaseCountry.CZ,
|
||||
["xra"] = ReleaseCountry.AU,
|
||||
["xv"] = ReleaseCountry.SI,
|
||||
["xxc"] = ReleaseCountry.CA,
|
||||
["xxk"] = ReleaseCountry.GB,
|
||||
["xxr"] = ReleaseCountry.RU,
|
||||
["xxu"] = ReleaseCountry.US,
|
||||
["ye"] = ReleaseCountry.YE,
|
||||
["ykc"] = ReleaseCountry.CA,
|
||||
["ys"] = ReleaseCountry.YE,
|
||||
["za"] = ReleaseCountry.ZM
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+3
-3
@@ -25,7 +25,7 @@ internal class OpenLibraryEditionResponseFixture
|
||||
/// <param name="notes">Optional. The notes of the edition.</param>
|
||||
/// <param name="publishDate">Optional. The publication date of the edition.</param>
|
||||
/// <param name="publishers">Optional. The publishers of the edition.</param>
|
||||
/// <param name="publishPlaces">Optional. The publication places of the edition.</param>
|
||||
/// <param name="publishCountry">Optional. The MARC 21 country code of the publication place of the edition.</param>
|
||||
/// <param name="numberOfPages">Optional. The number of pages of the edition.</param>
|
||||
/// <param name="physicalFormat">Optional. The physical format of the edition.</param>
|
||||
/// <param name="editionName">Optional. The name of the edition.</param>
|
||||
@@ -49,7 +49,7 @@ internal class OpenLibraryEditionResponseFixture
|
||||
JsonElement? notes = null,
|
||||
string? publishDate = null,
|
||||
List<string>? publishers = null,
|
||||
List<string>? publishPlaces = null,
|
||||
string? publishCountry = null,
|
||||
int? numberOfPages = null,
|
||||
string? physicalFormat = null,
|
||||
string? editionName = null,
|
||||
@@ -74,7 +74,7 @@ internal class OpenLibraryEditionResponseFixture
|
||||
Notes = notes ?? default,
|
||||
PublishDate = publishDate,
|
||||
Publishers = publishers ?? [],
|
||||
PublishPlaces = publishPlaces ?? [],
|
||||
PublishCountry = publishCountry,
|
||||
NumberOfPages = numberOfPages,
|
||||
PhysicalFormat = physicalFormat,
|
||||
EditionName = editionName,
|
||||
|
||||
-3
@@ -28,7 +28,6 @@ internal class OpenLibrarySearchDocumentResponseFixture
|
||||
/// <param name="languages">Optional. The languages of the search document.</param>
|
||||
/// <param name="publishers">Optional. The publishers of the search document.</param>
|
||||
/// <param name="subjects">Optional. The subjects of the search document.</param>
|
||||
/// <param name="publishPlaces">Optional. The publication places of the search document.</param>
|
||||
/// <param name="numberOfPagesMedian">Optional. The median number of pages of the search document.</param>
|
||||
/// <param name="ratingsAverage">Optional. The average rating of the search document.</param>
|
||||
/// <param name="ratingsCount">Optional. The number of ratings of the search document.</param>
|
||||
@@ -50,7 +49,6 @@ internal class OpenLibrarySearchDocumentResponseFixture
|
||||
List<string>? languages = null,
|
||||
List<string>? publishers = null,
|
||||
List<string>? subjects = null,
|
||||
List<string>? publishPlaces = null,
|
||||
int? numberOfPagesMedian = null,
|
||||
decimal? ratingsAverage = null,
|
||||
int? ratingsCount = null,
|
||||
@@ -73,7 +71,6 @@ internal class OpenLibrarySearchDocumentResponseFixture
|
||||
Languages = languages ?? [],
|
||||
Publishers = publishers ?? [],
|
||||
Subjects = subjects ?? [],
|
||||
PublishPlaces = publishPlaces ?? [],
|
||||
NumberOfPagesMedian = numberOfPagesMedian,
|
||||
RatingsAverage = ratingsAverage,
|
||||
RatingsCount = ratingsCount,
|
||||
|
||||
+29
-3
@@ -160,7 +160,6 @@ public class OpenLibraryMapperTests
|
||||
authorNames: ["Search Author"],
|
||||
firstPublishYear: 2003,
|
||||
publishers: ["Search Publisher"],
|
||||
publishPlaces: ["London"],
|
||||
subjects: ["Science fiction", "Space"],
|
||||
isbns: ["978-0-306-40615-7"],
|
||||
numberOfPagesMedian: 250,
|
||||
@@ -205,7 +204,7 @@ public class OpenLibraryMapperTests
|
||||
title: "Edition Title",
|
||||
publishDate: "2010-05-01",
|
||||
publishers: ["Publisher Co"],
|
||||
publishPlaces: ["New York"],
|
||||
publishCountry: "nyu",
|
||||
numberOfPages: 320,
|
||||
physicalFormat: "Hardcover",
|
||||
editionName: "First Edition",
|
||||
@@ -243,7 +242,7 @@ public class OpenLibraryMapperTests
|
||||
Assert.Equal(1987, result.ReleaseInfo.OriginalReleaseYear);
|
||||
Assert.Equal(new DateOnly(2010, 5, 1), result.ReleaseInfo.ReReleaseDate);
|
||||
Assert.Equal(2010, result.ReleaseInfo.ReReleaseYear);
|
||||
Assert.Null(result.ReleaseInfo.ReleaseCountry);
|
||||
Assert.Equal(ReleaseCountry.US, result.ReleaseInfo.ReleaseCountry);
|
||||
Assert.Equal("First Edition", result.ReleaseInfo.ReleaseVersion);
|
||||
GenreDto genre = Assert.Single(result.Genres!);
|
||||
Assert.Equal("Fantasy", genre.Name);
|
||||
@@ -282,6 +281,33 @@ public class OpenLibraryMapperTests
|
||||
Assert.Equal(100, mappedRating.VoteCount);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("nyu", ReleaseCountry.US)] // A MARC 21 state code that stands for the United States.
|
||||
[InlineData("xxu", ReleaseCountry.US)] // The MARC 21 country code of the United States.
|
||||
[InlineData("enk", ReleaseCountry.GB)] // The MARC 21 country code of England.
|
||||
[InlineData("ENK", ReleaseCountry.GB)] // The code differs only in casing.
|
||||
[InlineData("gw ", ReleaseCountry.DE)] // A two letter MARC 21 code, padded with a trailing space.
|
||||
[InlineData("fr", ReleaseCountry.FR)] // A two letter MARC 21 code without padding.
|
||||
[InlineData("abc", ReleaseCountry.CA)] // A MARC 21 province code that stands for Canada.
|
||||
[InlineData("aca", ReleaseCountry.AU)] // A MARC 21 territory code that stands for Australia.
|
||||
[InlineData("uk", ReleaseCountry.GB)] // A discontinued MARC 21 code that still appears in catalogued records.
|
||||
[InlineData("cs", ReleaseCountry.CZ)] // A discontinued MARC 21 code, mapped to the country that succeeded it.
|
||||
[InlineData("vp", null)] // A MARC 21 code that stands for various places, with no equivalent release country.
|
||||
[InlineData("zzz", null)] // An unknown MARC 21 code.
|
||||
[InlineData("", null)] // An empty MARC 21 code.
|
||||
public void MapDetailed_WhenEditionHasPublishCountry_ShouldMapTheMarcCountryCode(string? publishCountry, ReleaseCountry? expected)
|
||||
{
|
||||
// Arrange
|
||||
BookMetadataLookupDto lookup = _bookMetadataLookupDtoFixture.Create();
|
||||
OpenLibraryEditionResponse edition = _openLibraryEditionResponseFixture.Create(publishCountry: publishCountry);
|
||||
|
||||
// Act
|
||||
BookMetadataDto result = OpenLibraryMapper.MapDetailed(lookup, edition, null, [], null);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expected, result.ReleaseInfo!.ReleaseCountry);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MapDetailed_WhenWorkHasNoExplicitGenres_ShouldDeriveGenresFromTheGenreLikeSubjects()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user