mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-20 21:54:25 -04:00
Move all data fetching to BookInfo
This commit is contained in:
+9
-10
@@ -4,17 +4,16 @@ using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Books;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
using NzbDrone.Core.MetadataSource.Goodreads;
|
||||
using NzbDrone.Core.MetadataSource.BookInfo;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.MetadataSource.Goodreads
|
||||
{
|
||||
[TestFixture]
|
||||
public class GoodreadsProxyFixture : CoreTest<GoodreadsProxy>
|
||||
public class BookInfoProxyFixture : CoreTest<BookInfoProxy>
|
||||
{
|
||||
private MetadataProfile _metadataProfile;
|
||||
|
||||
@@ -45,8 +44,8 @@ namespace NzbDrone.Core.Test.MetadataSource.Goodreads
|
||||
details.Name.Should().Be(name);
|
||||
}
|
||||
|
||||
[TestCase("64216", "Guards! Guards!")]
|
||||
[TestCase("1371", "Ιλιάς")]
|
||||
[TestCase("1128601", "Guards! Guards!")]
|
||||
[TestCase("3293141", "Ιλιάς")]
|
||||
public void should_be_able_to_get_book_detail(string mbId, string name)
|
||||
{
|
||||
var details = Subject.GetBookInfo(mbId);
|
||||
@@ -56,13 +55,13 @@ namespace NzbDrone.Core.Test.MetadataSource.Goodreads
|
||||
details.Item2.Title.Should().Be(name);
|
||||
}
|
||||
|
||||
[TestCase("54837483", "The Book of Dust", "1")]
|
||||
[TestCase("28360360", "October Daye", "9.3")]
|
||||
[TestCase("14190696", "The Book of Dust", "1")]
|
||||
[TestCase("48427681", "October Daye Chronological Order", "7.1")]
|
||||
public void should_parse_series_from_title(string id, string series, string position)
|
||||
{
|
||||
var result = Subject.GetBookInfo(id);
|
||||
|
||||
var link = result.Item2.SeriesLinks.Value.First();
|
||||
var link = result.Item2.SeriesLinks.Value.OrderBy(x => x.SeriesPosition).First();
|
||||
link.Series.Value.Title.Should().Be(series);
|
||||
link.Position.Should().Be(position);
|
||||
}
|
||||
@@ -70,13 +69,13 @@ namespace NzbDrone.Core.Test.MetadataSource.Goodreads
|
||||
[Test]
|
||||
public void getting_details_of_invalid_author()
|
||||
{
|
||||
Assert.Throws<AuthorNotFoundException>(() => Subject.GetAuthorInfo("66c66aaa-6e2f-4930-8610-912e24c63ed1"));
|
||||
Assert.Throws<AuthorNotFoundException>(() => Subject.GetAuthorInfo("1"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void getting_details_of_invalid_book()
|
||||
{
|
||||
Assert.Throws<BookNotFoundException>(() => Subject.GetBookInfo("66c66aaa-6e2f-4930-8610-912e24c63ed1"));
|
||||
Assert.Throws<BookNotFoundException>(() => Subject.GetBookInfo("99999999"));
|
||||
}
|
||||
|
||||
private void ValidateAuthor(Author author)
|
||||
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Books;
|
||||
using NzbDrone.Core.Http;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
using NzbDrone.Core.MetadataSource.BookInfo;
|
||||
using NzbDrone.Core.MetadataSource.Goodreads;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MetadataSource.Goodreads
|
||||
{
|
||||
[TestFixture]
|
||||
public class BookInfoProxySearchFixture : CoreTest<BookInfoProxy>
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
UseRealHttp();
|
||||
|
||||
Mocker.SetConstant<IGoodreadsSearchProxy>(Mocker.Resolve<GoodreadsSearchProxy>());
|
||||
|
||||
var httpClient = Mocker.Resolve<IHttpClient>();
|
||||
Mocker.GetMock<ICachedHttpResponseService>()
|
||||
.Setup(x => x.Get<List<SearchJsonResource>>(It.IsAny<HttpRequest>(), It.IsAny<bool>(), It.IsAny<TimeSpan>()))
|
||||
.Returns((HttpRequest request, bool useCache, TimeSpan ttl) => httpClient.Get<List<SearchJsonResource>>(request));
|
||||
|
||||
var metadataProfile = new MetadataProfile();
|
||||
|
||||
Mocker.GetMock<IMetadataProfileService>()
|
||||
.Setup(s => s.All())
|
||||
.Returns(new List<MetadataProfile> { metadataProfile });
|
||||
|
||||
Mocker.GetMock<IMetadataProfileService>()
|
||||
.Setup(s => s.Get(It.IsAny<int>()))
|
||||
.Returns(metadataProfile);
|
||||
}
|
||||
|
||||
[TestCase("Robert Harris", "Robert Harris")]
|
||||
[TestCase("James Patterson", "James Patterson")]
|
||||
[TestCase("Antoine de Saint-Exupéry", "Antoine de Saint-Exupéry")]
|
||||
public void successful_author_search(string title, string expected)
|
||||
{
|
||||
var result = Subject.SearchForNewAuthor(title);
|
||||
|
||||
result.Should().NotBeEmpty();
|
||||
|
||||
result[0].Name.Should().Be(expected);
|
||||
|
||||
ExceptionVerification.IgnoreWarns();
|
||||
}
|
||||
|
||||
[TestCase("Harry Potter and the sorcerer's stone", null, "Harry Potter and the Sorcerer's Stone")]
|
||||
[TestCase("edition:3", null, "Harry Potter and the Sorcerer's Stone")]
|
||||
[TestCase("edition: 3", null, "Harry Potter and the Sorcerer's Stone")]
|
||||
[TestCase("asin:B0192CTMYG", null, "Harry Potter and the Sorcerer's Stone")]
|
||||
[TestCase("isbn:9780439554930", null, "Harry Potter and the Sorcerer's Stone")]
|
||||
public void successful_book_search(string title, string author, string expected)
|
||||
{
|
||||
var result = Subject.SearchForNewBook(title, author);
|
||||
|
||||
result.Should().NotBeEmpty();
|
||||
|
||||
result[0].Editions.Value[0].Title.Should().Be(expected);
|
||||
|
||||
ExceptionVerification.IgnoreWarns();
|
||||
}
|
||||
|
||||
[TestCase("edition:")]
|
||||
[TestCase("edition: 99999999999999999999")]
|
||||
[TestCase("edition: 0")]
|
||||
[TestCase("edition: -12")]
|
||||
[TestCase("edition: aaaa")]
|
||||
[TestCase("adjalkwdjkalwdjklawjdlKAJD")]
|
||||
public void no_author_search_result(string term)
|
||||
{
|
||||
var result = Subject.SearchForNewAuthor(term);
|
||||
result.Should().BeEmpty();
|
||||
|
||||
ExceptionVerification.IgnoreWarns();
|
||||
}
|
||||
|
||||
[TestCase("Philip Pullman", 0, typeof(Author), "Philip Pullman")]
|
||||
[TestCase("Philip Pullman", 1, typeof(Book), "Northern Lights")]
|
||||
public void successful_combined_search(string query, int position, Type resultType, string expected)
|
||||
{
|
||||
var result = Subject.SearchForNewEntity(query);
|
||||
result.Should().NotBeEmpty();
|
||||
result[position].GetType().Should().Be(resultType);
|
||||
|
||||
if (resultType == typeof(Author))
|
||||
{
|
||||
var cast = result[position] as Author;
|
||||
cast.Should().NotBeNull();
|
||||
cast.Name.Should().Be(expected);
|
||||
}
|
||||
else
|
||||
{
|
||||
var cast = result[position] as Book;
|
||||
cast.Should().NotBeNull();
|
||||
cast.Title.Should().Be(expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Books;
|
||||
using NzbDrone.Core.Http;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
using NzbDrone.Core.MetadataSource.Goodreads;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
@@ -23,52 +19,35 @@ namespace NzbDrone.Core.Test.MetadataSource.Goodreads
|
||||
{
|
||||
UseRealHttp();
|
||||
|
||||
Mocker.SetConstant<IProvideBookInfo>(Mocker.Resolve<GoodreadsProxy>());
|
||||
|
||||
var httpClient = Mocker.Resolve<IHttpClient>();
|
||||
Mocker.GetMock<ICachedHttpResponseService>()
|
||||
.Setup(x => x.Get<List<SearchJsonResource>>(It.IsAny<HttpRequest>(), It.IsAny<bool>(), It.IsAny<TimeSpan>()))
|
||||
.Returns((HttpRequest request, bool useCache, TimeSpan ttl) => httpClient.Get<List<SearchJsonResource>>(request));
|
||||
|
||||
var metadataProfile = new MetadataProfile();
|
||||
|
||||
Mocker.GetMock<IMetadataProfileService>()
|
||||
.Setup(s => s.All())
|
||||
.Returns(new List<MetadataProfile> { metadataProfile });
|
||||
|
||||
Mocker.GetMock<IMetadataProfileService>()
|
||||
.Setup(s => s.Get(It.IsAny<int>()))
|
||||
.Returns(metadataProfile);
|
||||
.Returns((HttpRequest request, bool useCache, TimeSpan ttl) => Mocker.Resolve<IHttpClient>().Get<List<SearchJsonResource>>(request));
|
||||
}
|
||||
|
||||
[TestCase("Robert Harris", "Robert Harris")]
|
||||
[TestCase("James Patterson", "James Patterson")]
|
||||
[TestCase("Antoine de Saint-Exupéry", "Antoine de Saint-Exupéry")]
|
||||
public void successful_author_search(string title, string expected)
|
||||
[TestCase("Robert Harris", 575)]
|
||||
[TestCase("James Patterson", 3780)]
|
||||
[TestCase("Antoine de Saint-Exupéry", 1020792)]
|
||||
public void successful_author_search(string title, int expected)
|
||||
{
|
||||
var result = Subject.SearchForNewAuthor(title);
|
||||
var result = Subject.Search(title);
|
||||
|
||||
result.Should().NotBeEmpty();
|
||||
|
||||
result[0].Name.Should().Be(expected);
|
||||
result[0].Author.Id.Should().Be(expected);
|
||||
|
||||
ExceptionVerification.IgnoreWarns();
|
||||
}
|
||||
|
||||
[TestCase("Harry Potter and the sorcerer's stone", null, "Harry Potter and the Sorcerer's Stone")]
|
||||
[TestCase("readarr:3", null, "Harry Potter and the Philosopher's Stone")]
|
||||
[TestCase("readarr: 3", null, "Harry Potter and the Philosopher's Stone")]
|
||||
[TestCase("readarrid:3", null, "Harry Potter and the Philosopher's Stone")]
|
||||
[TestCase("goodreads:3", null, "Harry Potter and the Philosopher's Stone")]
|
||||
[TestCase("asin:B0192CTMYG", null, "Harry Potter and the Sorcerer's Stone")]
|
||||
[TestCase("isbn:9780439554930", null, "Harry Potter and the Sorcerer's Stone")]
|
||||
public void successful_book_search(string title, string author, string expected)
|
||||
[TestCase("Harry Potter and the sorcerer's stone", 3)]
|
||||
[TestCase("B0192CTMYG", 42844155)]
|
||||
[TestCase("9780439554930", 48517161)]
|
||||
public void successful_book_search(string title, int expected)
|
||||
{
|
||||
var result = Subject.SearchForNewBook(title, author);
|
||||
var result = Subject.Search(title);
|
||||
|
||||
result.Should().NotBeEmpty();
|
||||
|
||||
result[0].Title.Should().Be(expected);
|
||||
result[0].BookId.Should().Be(expected);
|
||||
|
||||
ExceptionVerification.IgnoreWarns();
|
||||
}
|
||||
@@ -81,54 +60,10 @@ namespace NzbDrone.Core.Test.MetadataSource.Goodreads
|
||||
[TestCase("adjalkwdjkalwdjklawjdlKAJD")]
|
||||
public void no_author_search_result(string term)
|
||||
{
|
||||
var result = Subject.SearchForNewAuthor(term);
|
||||
var result = Subject.Search(term);
|
||||
result.Should().BeEmpty();
|
||||
|
||||
ExceptionVerification.IgnoreWarns();
|
||||
}
|
||||
|
||||
[TestCase("Philip Pullman", 0, typeof(Author), "Philip Pullman")]
|
||||
[TestCase("Philip Pullman", 1, typeof(Book), "The Golden Compass")]
|
||||
public void successful_combined_search(string query, int position, Type resultType, string expected)
|
||||
{
|
||||
var result = Subject.SearchForNewEntity(query);
|
||||
result.Should().NotBeEmpty();
|
||||
result[position].GetType().Should().Be(resultType);
|
||||
|
||||
if (resultType == typeof(Author))
|
||||
{
|
||||
var cast = result[position] as Author;
|
||||
cast.Should().NotBeNull();
|
||||
cast.Name.Should().Be(expected);
|
||||
}
|
||||
else
|
||||
{
|
||||
var cast = result[position] as Book;
|
||||
cast.Should().NotBeNull();
|
||||
cast.Title.Should().Be(expected);
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase("B01N390U59", "The Book of Dust", "1")]
|
||||
[TestCase("B0191WS1EE", "October Daye", "9.3")]
|
||||
public void should_parse_series_from_title(string query, string series, string position)
|
||||
{
|
||||
var result = Subject.SearchByField("field", query);
|
||||
|
||||
var link = result.First().SeriesLinks.Value.First();
|
||||
link.Series.Value.Title.Should().Be(series);
|
||||
link.Position.Should().Be(position);
|
||||
}
|
||||
|
||||
[TestCase("Imperium: A Novel of Ancient Rome (Cicero, #1)", "Imperium: A Novel of Ancient Rome", "Cicero", "1")]
|
||||
[TestCase("Sons of Valor (The Tier One Shared-World Series Book 1)", "Sons of Valor", "Tier One Shared-World", "1")]
|
||||
public void should_map_series_for_search(string title, string titleWithoutSeries, string series, string position)
|
||||
{
|
||||
var result = GoodreadsProxy.MapSearchSeries(title, titleWithoutSeries);
|
||||
|
||||
result.Should().HaveCount(1);
|
||||
result[0].Series.Value.Title.Should().Be(series);
|
||||
result[0].Position.Should().Be(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user