You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
3.9 KiB
127 lines
3.9 KiB
7 years ago
|
using System;
|
||
10 years ago
|
using System.Collections.Generic;
|
||
4 years ago
|
using System.Linq;
|
||
10 years ago
|
using FluentAssertions;
|
||
5 years ago
|
using Moq;
|
||
10 years ago
|
using NUnit.Framework;
|
||
4 years ago
|
using NzbDrone.Core.Books;
|
||
9 years ago
|
using NzbDrone.Core.Exceptions;
|
||
3 years ago
|
using NzbDrone.Core.MetadataSource.BookInfo;
|
||
7 years ago
|
using NzbDrone.Core.Profiles.Metadata;
|
||
5 years ago
|
using NzbDrone.Core.Test.Framework;
|
||
10 years ago
|
|
||
4 years ago
|
namespace NzbDrone.Core.Test.MetadataSource.Goodreads
|
||
10 years ago
|
{
|
||
|
[TestFixture]
|
||
3 years ago
|
public class BookInfoProxyFixture : CoreTest<BookInfoProxy>
|
||
10 years ago
|
{
|
||
5 years ago
|
private MetadataProfile _metadataProfile;
|
||
|
|
||
10 years ago
|
[SetUp]
|
||
|
public void Setup()
|
||
|
{
|
||
|
UseRealHttp();
|
||
7 years ago
|
|
||
4 years ago
|
_metadataProfile = new MetadataProfile();
|
||
7 years ago
|
|
||
|
Mocker.GetMock<IMetadataProfileService>()
|
||
|
.Setup(s => s.Get(It.IsAny<int>()))
|
||
|
.Returns(_metadataProfile);
|
||
7 years ago
|
|
||
|
Mocker.GetMock<IMetadataProfileService>()
|
||
|
.Setup(s => s.Exists(It.IsAny<int>()))
|
||
|
.Returns(true);
|
||
10 years ago
|
}
|
||
5 years ago
|
|
||
4 years ago
|
[TestCase("1654", "Terry Pratchett")]
|
||
|
[TestCase("575", "Robert Harris")]
|
||
4 years ago
|
public void should_be_able_to_get_author_detail(string mbId, string name)
|
||
10 years ago
|
{
|
||
4 years ago
|
var details = Subject.GetAuthorInfo(mbId);
|
||
10 years ago
|
|
||
4 years ago
|
ValidateAuthor(details);
|
||
10 years ago
|
|
||
6 years ago
|
details.Name.Should().Be(name);
|
||
10 years ago
|
}
|
||
5 years ago
|
|
||
3 years ago
|
[TestCase("1128601", "Guards! Guards!")]
|
||
|
[TestCase("3293141", "Ιλιάς")]
|
||
4 years ago
|
public void should_be_able_to_get_book_detail(string mbId, string name)
|
||
7 years ago
|
{
|
||
4 years ago
|
var details = Subject.GetBookInfo(mbId);
|
||
7 years ago
|
|
||
4 years ago
|
ValidateBooks(new List<Book> { details.Item2 });
|
||
7 years ago
|
|
||
6 years ago
|
details.Item2.Title.Should().Be(name);
|
||
7 years ago
|
}
|
||
10 years ago
|
|
||
3 years ago
|
[TestCase("14190696", "The Book of Dust", "1")]
|
||
|
[TestCase("48427681", "October Daye Chronological Order", "7.1")]
|
||
4 years ago
|
public void should_parse_series_from_title(string id, string series, string position)
|
||
|
{
|
||
|
var result = Subject.GetBookInfo(id);
|
||
|
|
||
3 years ago
|
var link = result.Item2.SeriesLinks.Value.OrderBy(x => x.SeriesPosition).First();
|
||
4 years ago
|
link.Series.Value.Title.Should().Be(series);
|
||
|
link.Position.Should().Be(position);
|
||
|
}
|
||
|
|
||
10 years ago
|
[Test]
|
||
4 years ago
|
public void getting_details_of_invalid_author()
|
||
10 years ago
|
{
|
||
3 years ago
|
Assert.Throws<AuthorNotFoundException>(() => Subject.GetAuthorInfo("1"));
|
||
7 years ago
|
}
|
||
|
|
||
|
[Test]
|
||
4 years ago
|
public void getting_details_of_invalid_book()
|
||
7 years ago
|
{
|
||
3 years ago
|
Assert.Throws<BookNotFoundException>(() => Subject.GetBookInfo("99999999"));
|
||
10 years ago
|
}
|
||
|
|
||
4 years ago
|
private void ValidateAuthor(Author author)
|
||
10 years ago
|
{
|
||
4 years ago
|
author.Should().NotBeNull();
|
||
|
author.Name.Should().NotBeNullOrWhiteSpace();
|
||
4 years ago
|
author.CleanName.Should().Be(Parser.Parser.CleanAuthorName(author.Name));
|
||
4 years ago
|
author.Metadata.Value.TitleSlug.Should().NotBeNullOrWhiteSpace();
|
||
|
author.Metadata.Value.Overview.Should().NotBeNullOrWhiteSpace();
|
||
|
author.Metadata.Value.Images.Should().NotBeEmpty();
|
||
|
author.ForeignAuthorId.Should().NotBeNullOrWhiteSpace();
|
||
10 years ago
|
}
|
||
|
|
||
4 years ago
|
private void ValidateBooks(List<Book> books, bool idOnly = false)
|
||
10 years ago
|
{
|
||
4 years ago
|
books.Should().NotBeEmpty();
|
||
10 years ago
|
|
||
4 years ago
|
foreach (var book in books)
|
||
10 years ago
|
{
|
||
4 years ago
|
book.ForeignBookId.Should().NotBeNullOrWhiteSpace();
|
||
5 years ago
|
if (!idOnly)
|
||
|
{
|
||
4 years ago
|
ValidateBook(book);
|
||
5 years ago
|
}
|
||
|
}
|
||
5 years ago
|
|
||
4 years ago
|
//if atleast one book has title it means parse it working.
|
||
5 years ago
|
if (!idOnly)
|
||
|
{
|
||
4 years ago
|
books.Should().Contain(c => !string.IsNullOrWhiteSpace(c.Title));
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
private void ValidateBook(Book book)
|
||
10 years ago
|
{
|
||
4 years ago
|
book.Should().NotBeNull();
|
||
5 years ago
|
|
||
4 years ago
|
book.Title.Should().NotBeNullOrWhiteSpace();
|
||
10 years ago
|
|
||
4 years ago
|
book.Should().NotBeNull();
|
||
10 years ago
|
|
||
4 years ago
|
if (book.ReleaseDate.HasValue)
|
||
10 years ago
|
{
|
||
4 years ago
|
book.ReleaseDate.Value.Kind.Should().Be(DateTimeKind.Utc);
|
||
10 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|