diff --git a/plugins/Lumina.Plugins.OpenLibrary/Common/Models/Contracts/Responses/OpenLibraryEditionResponse.cs b/plugins/Lumina.Plugins.OpenLibrary/Common/Models/Contracts/Responses/OpenLibraryEditionResponse.cs index ea5fa21a..3ed0c1aa 100644 --- a/plugins/Lumina.Plugins.OpenLibrary/Common/Models/Contracts/Responses/OpenLibraryEditionResponse.cs +++ b/plugins/Lumina.Plugins.OpenLibrary/Common/Models/Contracts/Responses/OpenLibraryEditionResponse.cs @@ -48,10 +48,10 @@ internal sealed record OpenLibraryEditionResponse public List Publishers { get; init; } = []; /// - /// Gets the publication places of the edition. + /// Gets the MARC 21 country code of the publication place of the edition. /// - [JsonPropertyName("publish_places")] - public List PublishPlaces { get; init; } = []; + [JsonPropertyName("publish_country")] + public string? PublishCountry { get; init; } /// /// Gets the number of pages of the edition. diff --git a/plugins/Lumina.Plugins.OpenLibrary/Common/Models/Contracts/Responses/OpenLibrarySearchDocumentResponse.cs b/plugins/Lumina.Plugins.OpenLibrary/Common/Models/Contracts/Responses/OpenLibrarySearchDocumentResponse.cs index ad166095..f0c86b45 100644 --- a/plugins/Lumina.Plugins.OpenLibrary/Common/Models/Contracts/Responses/OpenLibrarySearchDocumentResponse.cs +++ b/plugins/Lumina.Plugins.OpenLibrary/Common/Models/Contracts/Responses/OpenLibrarySearchDocumentResponse.cs @@ -70,12 +70,6 @@ internal sealed record OpenLibrarySearchDocumentResponse [JsonPropertyName("subject")] public List Subjects { get; init; } = []; - /// - /// Gets the publication places of the search document. - /// - [JsonPropertyName("publish_place")] - public List PublishPlaces { get; init; } = []; - /// /// Gets the median number of pages of the search document. /// diff --git a/plugins/Lumina.Plugins.OpenLibrary/Core/Api/OpenLibraryHttpClient.cs b/plugins/Lumina.Plugins.OpenLibrary/Core/Api/OpenLibraryHttpClient.cs index e5a606a8..abba6c20 100644 --- a/plugins/Lumina.Plugins.OpenLibrary/Core/Api/OpenLibraryHttpClient.cs +++ b/plugins/Lumina.Plugins.OpenLibrary/Core/Api/OpenLibraryHttpClient.cs @@ -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"; diff --git a/plugins/Lumina.Plugins.OpenLibrary/Core/Mapping/OpenLibraryMapper.cs b/plugins/Lumina.Plugins.OpenLibrary/Core/Mapping/OpenLibraryMapper.cs index ac093c3b..9753f19b 100644 --- a/plugins/Lumina.Plugins.OpenLibrary/Core/Mapping/OpenLibraryMapper.cs +++ b/plugins/Lumina.Plugins.OpenLibrary/Core/Mapping/OpenLibraryMapper.cs @@ -50,6 +50,13 @@ internal static partial class OpenLibraryMapper "travel", "young adult" }; + /// + /// The release countries, keyed by their MARC 21 country code. The two code standards do not share their values (for example, MARC 21 uses + /// enk for England, gw for Germany, and xxu 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. + /// + private static readonly Dictionary s_releaseCountriesByMarcCode = BuildReleaseCountriesByMarcCode(); + /// /// Maps the edition, work, author, rating, and search data into a full book request. /// @@ -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 } /// - /// Maps a country string into a release country. + /// Maps a MARC 21 country code into a release country. /// - /// The country string to map. - /// The mapped release country, or when the string is empty or is not a known ISO 3166-1 alpha-2 code. - private static ReleaseCountry? MapReleaseCountry(string? rawCountry) + /// The MARC 21 country code to map. + /// + /// The mapped release country, or when the code is empty or is not a known MARC 21 country code. + /// + 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; + } + + /// + /// Builds the map of the release countries, keyed by their MARC 21 country code. + /// + /// The release countries, keyed by their MARC 21 country code. + private static Dictionary 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 + }; } /// diff --git a/tests/Common/Lumina.Plugins.OpenLibrary.Fixtures/Common/Models/Contracts/Responses/OpenLibraryEditionResponseFixture.cs b/tests/Common/Lumina.Plugins.OpenLibrary.Fixtures/Common/Models/Contracts/Responses/OpenLibraryEditionResponseFixture.cs index cf3b10eb..7f78b410 100644 --- a/tests/Common/Lumina.Plugins.OpenLibrary.Fixtures/Common/Models/Contracts/Responses/OpenLibraryEditionResponseFixture.cs +++ b/tests/Common/Lumina.Plugins.OpenLibrary.Fixtures/Common/Models/Contracts/Responses/OpenLibraryEditionResponseFixture.cs @@ -25,7 +25,7 @@ internal class OpenLibraryEditionResponseFixture /// Optional. The notes of the edition. /// Optional. The publication date of the edition. /// Optional. The publishers of the edition. - /// Optional. The publication places of the edition. + /// Optional. The MARC 21 country code of the publication place of the edition. /// Optional. The number of pages of the edition. /// Optional. The physical format of the edition. /// Optional. The name of the edition. @@ -49,7 +49,7 @@ internal class OpenLibraryEditionResponseFixture JsonElement? notes = null, string? publishDate = null, List? publishers = null, - List? 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, diff --git a/tests/Common/Lumina.Plugins.OpenLibrary.Fixtures/Common/Models/Contracts/Responses/OpenLibrarySearchDocumentResponseFixture.cs b/tests/Common/Lumina.Plugins.OpenLibrary.Fixtures/Common/Models/Contracts/Responses/OpenLibrarySearchDocumentResponseFixture.cs index 712e4d17..5f5f7eda 100644 --- a/tests/Common/Lumina.Plugins.OpenLibrary.Fixtures/Common/Models/Contracts/Responses/OpenLibrarySearchDocumentResponseFixture.cs +++ b/tests/Common/Lumina.Plugins.OpenLibrary.Fixtures/Common/Models/Contracts/Responses/OpenLibrarySearchDocumentResponseFixture.cs @@ -28,7 +28,6 @@ internal class OpenLibrarySearchDocumentResponseFixture /// Optional. The languages of the search document. /// Optional. The publishers of the search document. /// Optional. The subjects of the search document. - /// Optional. The publication places of the search document. /// Optional. The median number of pages of the search document. /// Optional. The average rating of the search document. /// Optional. The number of ratings of the search document. @@ -50,7 +49,6 @@ internal class OpenLibrarySearchDocumentResponseFixture List? languages = null, List? publishers = null, List? subjects = null, - List? 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, diff --git a/tests/UnitTests/Lumina.Plugins.OpenLibrary.UnitTests/Core/Mapping/OpenLibraryMapperTests.cs b/tests/UnitTests/Lumina.Plugins.OpenLibrary.UnitTests/Core/Mapping/OpenLibraryMapperTests.cs index 978e5950..9584f72b 100644 --- a/tests/UnitTests/Lumina.Plugins.OpenLibrary.UnitTests/Core/Mapping/OpenLibraryMapperTests.cs +++ b/tests/UnitTests/Lumina.Plugins.OpenLibrary.UnitTests/Core/Mapping/OpenLibraryMapperTests.cs @@ -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() {