mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
Fixed: Catch NullRef On HDBits request if IMDB empty
This commit is contained in:
parent
89fec7841c
commit
2eff7b95dd
@ -0,0 +1,85 @@
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Indexers.HDBits;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.IndexerTests.HDBitsTests
|
||||
{
|
||||
public class HDBitsRequestGeneratorFixture : CoreTest<HDBitsRequestGenerator>
|
||||
{
|
||||
private MovieSearchCriteria _movieSearchCriteria;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Subject.Settings = new HDBitsSettings()
|
||||
{
|
||||
BaseUrl = "http://127.0.0.1:1234/",
|
||||
Categories = new[] { 1, 2 },
|
||||
ApiKey = "abcd",
|
||||
Username = "somename"
|
||||
};
|
||||
|
||||
_movieSearchCriteria = new MovieSearchCriteria
|
||||
{
|
||||
Movie = new Movies.Movie { ImdbId = "tt0076759", Title = "Star Wars", Year = 1977 }
|
||||
};
|
||||
}
|
||||
|
||||
private void MovieWithoutIMDB()
|
||||
{
|
||||
_movieSearchCriteria.Movie.ImdbId = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_use_all_categories_for_feed()
|
||||
{
|
||||
var results = Subject.GetRecentRequests();
|
||||
|
||||
results.GetAllTiers().Should().HaveCount(1);
|
||||
|
||||
var page = results.GetAllTiers().First().First();
|
||||
|
||||
var encoding = HttpHeader.GetEncodingFromContentType(page.HttpRequest.Headers.ContentType);
|
||||
|
||||
var body = encoding.GetString(page.HttpRequest.ContentData);
|
||||
var query = JsonConvert.DeserializeObject<TorrentQuery>(body);
|
||||
|
||||
query.Category.Should().HaveCount(2);
|
||||
query.Username.Should().Be(Subject.Settings.Username);
|
||||
query.Passkey.Should().Be(Subject.Settings.ApiKey);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_search_by_imdbid_if_supported()
|
||||
{
|
||||
var results = Subject.GetSearchRequests(_movieSearchCriteria);
|
||||
var imdbQuery = int.Parse(_movieSearchCriteria.Movie.ImdbId.Substring(2));
|
||||
|
||||
results.GetAllTiers().Should().HaveCount(1);
|
||||
|
||||
var page = results.GetAllTiers().First().First();
|
||||
|
||||
var encoding = HttpHeader.GetEncodingFromContentType(page.HttpRequest.Headers.ContentType);
|
||||
|
||||
var body = encoding.GetString(page.HttpRequest.ContentData);
|
||||
var query = JsonConvert.DeserializeObject<TorrentQuery>(body);
|
||||
|
||||
query.Category.Should().HaveCount(2);
|
||||
query.ImdbInfo.Id.Should().Be(imdbQuery);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_no_results_if_no_imdb()
|
||||
{
|
||||
MovieWithoutIMDB();
|
||||
|
||||
var results = Subject.GetSearchRequests(_movieSearchCriteria);
|
||||
results.GetTier(0).Should().HaveCount(0);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
@ -21,12 +22,10 @@ public virtual IndexerPageableRequestChain GetRecentRequests()
|
||||
public virtual IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria searchCriteria)
|
||||
{
|
||||
var pageableRequests = new IndexerPageableRequestChain();
|
||||
var queryBase = new TorrentQuery();
|
||||
var query = new TorrentQuery();
|
||||
|
||||
if (TryAddSearchParameters(queryBase, searchCriteria))
|
||||
if (TryAddSearchParameters(query, searchCriteria))
|
||||
{
|
||||
var query = queryBase.Clone();
|
||||
query.ImdbInfo.Id = int.Parse(searchCriteria.Movie.ImdbId.Substring(2));
|
||||
pageableRequests.Add(GetRequest(query));
|
||||
}
|
||||
|
||||
@ -35,6 +34,11 @@ public virtual IndexerPageableRequestChain GetSearchRequests(MovieSearchCriteria
|
||||
|
||||
private bool TryAddSearchParameters(TorrentQuery query, SearchCriteriaBase searchCriteria)
|
||||
{
|
||||
if (searchCriteria.Movie.ImdbId.IsNullOrWhiteSpace())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var imdbId = int.Parse(searchCriteria.Movie.ImdbId.Substring(2));
|
||||
|
||||
if (imdbId != 0)
|
||||
|
Loading…
Reference in New Issue
Block a user