From a031fe9d9850f3d941c8b4f05a0e1f14f3f8bcfc Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 13 Nov 2011 13:44:19 -0800 Subject: [PATCH] Added config.xml to .gitignore. Added tests for NewznabProvider. --- .gitignore | 3 +- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 1 + .../ProviderTests/NewznabProviderTest.cs | 211 ++++++++++++++++++ 3 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 NzbDrone.Core.Test/ProviderTests/NewznabProviderTest.cs diff --git a/.gitignore b/.gitignore index 11bfc37d5..31ea5068e 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,5 @@ NzbDrone.Web/NzbDrone.Web.Publish.xml *.orig _rawPackage/ NzbDrone.zip -NzbDrone.sln.DotSettings.user* \ No newline at end of file +NzbDrone.sln.DotSettings.user* +config.xml \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 8df497f7e..3d735ff29 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -84,6 +84,7 @@ + diff --git a/NzbDrone.Core.Test/ProviderTests/NewznabProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/NewznabProviderTest.cs new file mode 100644 index 000000000..5cc3d10bc --- /dev/null +++ b/NzbDrone.Core.Test/ProviderTests/NewznabProviderTest.cs @@ -0,0 +1,211 @@ +using System; +using System.Linq; +using AutoMoq; +using FizzWare.NBuilder; +using FluentAssertions; +using Moq; +using NUnit.Framework; +using NzbDrone.Core.Providers; +using NzbDrone.Core.Repository; +using NzbDrone.Core.Repository.Quality; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.ProviderTests +{ + [TestFixture] + // ReSharper disable InconsistentNaming + public class NewznabProviderTest : CoreTest + { + [Test] + public void Save_should_clean_url_before_inserting() + { + //Setup + var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world" }; + var expectedUrl = "http://www.nzbdrone.com"; + + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + //Act + var result = mocker.Resolve().Save(newznab); + + //Assert + db.Single(result).Url.Should().Be(expectedUrl); + } + + [Test] + public void Save_should_clean_url_before_updating() + { + //Setup + var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "http://www.nzbdrone.com" }; + var expectedUrl = "http://www.nzbdrone.com"; + var newUrl = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world"; + + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + newznab.Id = Convert.ToInt32(db.Insert(newznab)); + newznab.Url = newUrl; + + //Act + var result = mocker.Resolve().Save(newznab); + + //Assert + db.Single(result).Url.Should().Be(expectedUrl); + } + + [Test] + public void SaveAll_should_clean_urls_before_updating() + { + //Setup + var definitions = Builder.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"; + + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + db.InsertMany(definitions); + + definitions.ToList().ForEach(d => d.Url = newUrl); + + //Act + mocker.Resolve().SaveAll(definitions); + + //Assert + db.Fetch().Where(d => d.Url == expectedUrl).Should().HaveCount(5); + } + + [Test] + public void Enabled_should_return_all_enabled_newznab_providers() + { + //Setup + var definitions = Builder.CreateListOfSize(5) + .TheFirst(2) + .With(d => d.Enable = false) + .TheLast(3) + .With(d => d.Enable = true) + .Build(); + + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + db.InsertMany(definitions); + + //Act + var result = mocker.Resolve().Enabled(); + + //Assert + result.Should().HaveCount(3); + result.All(d => d.Enable).Should().BeTrue(); + } + + [Test] + public void All_should_return_all_newznab_providers() + { + //Setup + var definitions = Builder.CreateListOfSize(5) + .TheFirst(2) + .With(d => d.Enable = false) + .TheLast(3) + .With(d => d.Enable = true) + .Build(); + + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + db.InsertMany(definitions); + + //Act + var result = mocker.Resolve().All(); + + //Assert + result.Should().HaveCount(5); + } + + [Test] + public void Delete_should_delete_newznab_provider() + { + //Setup + var definitions = Builder.CreateListOfSize(5) + .TheFirst(2) + .With(d => d.Enable = false) + .TheLast(3) + .With(d => d.Enable = true) + .Build(); + + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + db.InsertMany(definitions); + + //Act + mocker.Resolve().Delete(1); + + //Assert + var result = db.Fetch(); + result.Should().HaveCount(4); + result.Any(d => d.Id == 1).Should().BeFalse(); + } + + [Test] + public void InitializeNewznabIndexers_should_initialize_new_indexers() + { + //Setup + var definitions = Builder.CreateListOfSize(5) + .All() + .With(d => d.Url = "http://www.nzbdrone.com") + .Build(); + + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + //Act + mocker.Resolve().InitializeNewznabIndexers(definitions); + + //Assert + var result = db.Fetch(); + result.Should().HaveCount(5); + } + + [Test] + public void InitializeNewznabIndexers_should_initialize_new_indexers_only() + { + //Setup + var definitions = Builder.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(); + + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + db.Insert(definitions[0]); + db.Insert(definitions[1]); + + //Act + mocker.Resolve().InitializeNewznabIndexers(definitions); + + //Assert + var result = db.Fetch(); + result.Should().HaveCount(5); + result.Where(d => d.Url == "http://www.nzbdrone.com").Should().HaveCount(3); + result.Where(d => d.Url == "http://www.nzbdrone2.com").Should().HaveCount(2); + } + } +} \ No newline at end of file