2011-11-13 21:44:19 +00:00
|
|
|
|
using System;
|
2012-05-04 15:30:30 +00:00
|
|
|
|
using System.Collections.Generic;
|
2011-11-13 21:44:19 +00:00
|
|
|
|
using System.Linq;
|
2012-12-16 09:08:02 +00:00
|
|
|
|
using System.Net.Sockets;
|
2011-11-13 21:44:19 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2012-05-11 17:26:56 +00:00
|
|
|
|
using NzbDrone.Test.Common;
|
2011-11-13 21:44:19 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-02 20:54:03 +00:00
|
|
|
|
public class NewznabProviderTest : SqlCeTest<NewznabProvider>
|
2011-11-13 21:44:19 +00:00
|
|
|
|
{
|
2013-01-19 18:19:29 +00:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp()
|
|
|
|
|
{
|
|
|
|
|
WithRealDb();
|
|
|
|
|
InitiateSubject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-11-13 21:44:19 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void Save_should_clean_url_before_inserting()
|
|
|
|
|
{
|
2013-01-19 18:19:29 +00:00
|
|
|
|
|
2011-11-13 21:44:19 +00:00
|
|
|
|
var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world" };
|
2013-01-19 18:19:29 +00:00
|
|
|
|
const string expectedUrl = "http://www.nzbdrone.com";
|
2011-11-13 21:44:19 +00:00
|
|
|
|
|
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
var result = Subject.Save(newznab);
|
2011-11-13 21:44:19 +00:00
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
Db.Single<NewznabDefinition>(result).Url.Should().Be(expectedUrl);
|
2011-11-13 21:44:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Save_should_clean_url_before_updating()
|
|
|
|
|
{
|
2013-01-19 18:19:29 +00:00
|
|
|
|
var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world" };
|
2011-12-15 04:15:53 +00:00
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
var result = Subject.Save(newznab);
|
2011-11-15 23:11:17 +00:00
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
Subject.All().Single(c => c.Id == result).Url.Should().Be("http://www.nzbdrone.com");
|
2011-11-15 23:11:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Save_should_clean_url_before_inserting_when_url_is_not_empty()
|
|
|
|
|
{
|
|
|
|
|
var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "" };
|
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
var result = Subject.Save(newznab);
|
2011-11-15 23:11:17 +00:00
|
|
|
|
|
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
Subject.All().Single(c => c.Id == result).Url.Should().Be("");
|
2011-11-15 23:11:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Save_should_clean_url_before_updating_when_url_is_not_empty()
|
|
|
|
|
{
|
2013-01-19 18:19:29 +00:00
|
|
|
|
var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "" };
|
|
|
|
|
var result = Subject.Save(newznab);
|
2011-12-15 04:15:53 +00:00
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
Db.Single<NewznabDefinition>(result).Url.Should().Be("");
|
2011-11-13 21:44:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-12-26 22:33:42 +00:00
|
|
|
|
[Ignore("No longer clean newznab URLs")]
|
2011-11-13 21:44:19 +00:00
|
|
|
|
public void SaveAll_should_clean_urls_before_updating()
|
|
|
|
|
{
|
2013-01-19 18:19:29 +00:00
|
|
|
|
|
2011-11-13 21:44:19 +00:00
|
|
|
|
var definitions = Builder<NewznabDefinition>.CreateListOfSize(5)
|
|
|
|
|
.All()
|
|
|
|
|
.With(d => d.Url = "http://www.nzbdrone.com")
|
|
|
|
|
.Build();
|
|
|
|
|
var expectedUrl = "http://www.nzbdrone.com";
|
|
|
|
|
var newUrl = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world";
|
|
|
|
|
|
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
Db.InsertMany(definitions);
|
2011-11-13 21:44:19 +00:00
|
|
|
|
|
|
|
|
|
definitions.ToList().ForEach(d => d.Url = newUrl);
|
|
|
|
|
|
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
Subject.SaveAll(definitions);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Db.Fetch<NewznabDefinition>().Where(d => d.Url == expectedUrl).Should().HaveCount(5);
|
2011-11-13 21:44:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Enabled_should_return_all_enabled_newznab_providers()
|
|
|
|
|
{
|
2013-01-19 18:19:29 +00:00
|
|
|
|
|
2011-11-13 21:44:19 +00:00
|
|
|
|
var definitions = Builder<NewznabDefinition>.CreateListOfSize(5)
|
|
|
|
|
.TheFirst(2)
|
|
|
|
|
.With(d => d.Enable = false)
|
|
|
|
|
.TheLast(3)
|
|
|
|
|
.With(d => d.Enable = true)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
Db.InsertMany(definitions);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var result = Subject.Enabled();
|
2011-11-13 21:44:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.Should().HaveCount(3);
|
|
|
|
|
result.All(d => d.Enable).Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void All_should_return_all_newznab_providers()
|
|
|
|
|
{
|
2013-01-19 18:19:29 +00:00
|
|
|
|
|
|
|
|
|
var userIndexers = Builder<NewznabDefinition>.CreateListOfSize(5)
|
|
|
|
|
.All().With(c => c.Url = "http://www.host.com/12")
|
2011-11-13 21:44:19 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
Db.InsertMany(userIndexers);
|
2011-11-13 21:44:19 +00:00
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
var result = Subject.All();
|
2011-11-13 21:44:19 +00:00
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
result.Should().HaveCount(8);
|
2011-11-13 21:44:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
|
2011-11-13 21:44:19 +00:00
|
|
|
|
[Test]
|
2013-01-19 18:19:29 +00:00
|
|
|
|
public void All_should_return_empty_list_when_no_indexers_exist()
|
2011-11-13 21:44:19 +00:00
|
|
|
|
{
|
2013-01-19 18:19:29 +00:00
|
|
|
|
Db.Delete<NewznabDefinition>("");
|
2011-11-13 21:44:19 +00:00
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
Subject.All().Should().NotBeNull();
|
|
|
|
|
Subject.All().Should().BeEmpty();
|
2011-11-13 21:44:19 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-01-19 18:19:29 +00:00
|
|
|
|
public void Delete_should_delete_newznab_provider()
|
2011-11-13 21:44:19 +00:00
|
|
|
|
{
|
2013-01-19 18:19:29 +00:00
|
|
|
|
var toBeDelete = Subject.All()[2];
|
2011-11-13 21:44:19 +00:00
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
Subject.Delete(toBeDelete.Id);
|
2011-11-13 21:44:19 +00:00
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
Subject.All().Should().NotBeEmpty();
|
|
|
|
|
Subject.All().Should().NotContain(c => c.Id == toBeDelete.Id);
|
|
|
|
|
}
|
2013-01-19 05:14:12 +00:00
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void InitializeNewznabIndexers_should_initialize_build_in_indexers()
|
|
|
|
|
{
|
|
|
|
|
var indexers = Subject.All();
|
2011-11-13 21:44:19 +00:00
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
indexers.Should().NotBeEmpty();
|
|
|
|
|
indexers.Should().OnlyContain(i => i.BuiltIn);
|
2011-11-13 21:44:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void InitializeNewznabIndexers_should_initialize_new_indexers_only()
|
|
|
|
|
{
|
2013-01-19 18:19:29 +00:00
|
|
|
|
|
2011-11-13 21:44:19 +00:00
|
|
|
|
var definitions = Builder<NewznabDefinition>.CreateListOfSize(5)
|
|
|
|
|
.All()
|
|
|
|
|
.With(d => d.Id = 0)
|
|
|
|
|
.TheFirst(2)
|
|
|
|
|
.With(d => d.Url = "http://www.nzbdrone2.com")
|
|
|
|
|
.TheLast(3)
|
|
|
|
|
.With(d => d.Url = "http://www.nzbdrone.com")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
Db.Insert(definitions[0]);
|
|
|
|
|
Db.Insert(definitions[2]);
|
2011-11-13 21:44:19 +00:00
|
|
|
|
|
2013-01-19 05:14:12 +00:00
|
|
|
|
Mocker.SetConstant<IEnumerable<NewznabDefinition>>(definitions);
|
|
|
|
|
|
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
var result = Db.Fetch<NewznabDefinition>();
|
2012-05-04 15:30:30 +00:00
|
|
|
|
result.Where(d => d.Url == "http://www.nzbdrone.com").Should().HaveCount(1);
|
|
|
|
|
result.Where(d => d.Url == "http://www.nzbdrone2.com").Should().HaveCount(1);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-04 16:26:25 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void InitializeNewznabIndexers_should_not_blow_up_if_more_than_one_indexer_with_the_same_url_is_found()
|
|
|
|
|
{
|
|
|
|
|
var definition = Builder<NewznabDefinition>.CreateNew()
|
|
|
|
|
.With(d => d.Url = "http://www.nzbdrone2.com")
|
|
|
|
|
.With(d => d.BuiltIn = false)
|
|
|
|
|
.Build();
|
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
Db.Insert(definition);
|
|
|
|
|
Db.Insert(definition);
|
2012-05-04 16:26:25 +00:00
|
|
|
|
|
2013-01-19 05:14:12 +00:00
|
|
|
|
|
|
|
|
|
Mocker.SetConstant<IEnumerable<NewznabDefinition>>(new List<NewznabDefinition> { definition });
|
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
var result = Db.Fetch<NewznabDefinition>().Where(c => c.BuiltIn == false);
|
2012-05-04 16:26:25 +00:00
|
|
|
|
result.Should().HaveCount(2);
|
|
|
|
|
}
|
2012-05-11 17:26:56 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void CheckHostname_should_do_nothing_if_hostname_is_valid()
|
|
|
|
|
{
|
2013-01-19 18:19:29 +00:00
|
|
|
|
Subject.CheckHostname("http://www.google.com");
|
2012-05-11 17:26:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void CheckHostname_should_log_error_and_throw_exception_if_dnsHostname_is_invalid()
|
|
|
|
|
{
|
2013-01-19 18:19:29 +00:00
|
|
|
|
Assert.Throws<SocketException>(() => Subject.CheckHostname("http://BadName"));
|
2012-12-16 09:08:02 +00:00
|
|
|
|
|
2012-05-11 17:26:56 +00:00
|
|
|
|
ExceptionVerification.ExpectedErrors(1);
|
|
|
|
|
}
|
2011-11-13 21:44:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|