diff --git a/src/NzbDrone.Common.Test/PathExtensionFixture.cs b/src/NzbDrone.Common.Test/PathExtensionFixture.cs index 050c98296..b72a5cb78 100644 --- a/src/NzbDrone.Common.Test/PathExtensionFixture.cs +++ b/src/NzbDrone.Common.Test/PathExtensionFixture.cs @@ -206,7 +206,7 @@ namespace NzbDrone.Common.Test public void get_actual_casing_should_return_actual_casing_for_local_dir_in_windows() { WindowsOnly(); - var path = Directory.GetCurrentDirectory().Replace("c:\\","C:\\"); + var path = Directory.GetCurrentDirectory().Replace("c:\\","C:\\").Replace("system32", "System32"); path.ToUpper().GetActualCasing().Should().Be(path); path.ToLower().GetActualCasing().Should().Be(path); diff --git a/src/NzbDrone.Common/Http/Dispatchers/CurlHttpDispatcher.cs b/src/NzbDrone.Common/Http/Dispatchers/CurlHttpDispatcher.cs index 5dcb084a9..9ea8d1a80 100644 --- a/src/NzbDrone.Common/Http/Dispatchers/CurlHttpDispatcher.cs +++ b/src/NzbDrone.Common/Http/Dispatchers/CurlHttpDispatcher.cs @@ -12,6 +12,7 @@ using NLog; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Extensions; using NzbDrone.Common.Instrumentation; +using System.Reflection; namespace NzbDrone.Common.Http.Dispatchers { @@ -21,6 +22,21 @@ namespace NzbDrone.Common.Http.Dispatchers private static readonly Logger _logger = NzbDroneLogger.GetLogger(typeof(CurlHttpDispatcher)); + private const string _caBundleFileName = "curl-ca-bundle.crt"; + private static readonly string _caBundleFilePath; + + static CurlHttpDispatcher() + { + if (Assembly.GetExecutingAssembly().Location.IsNotNullOrWhiteSpace()) + { + _caBundleFilePath = Path.Combine(Assembly.GetExecutingAssembly().Location, "..", _caBundleFileName); + } + else + { + _caBundleFilePath = _caBundleFileName; + } + } + public static bool CheckAvailability() { try @@ -88,7 +104,7 @@ namespace NzbDrone.Common.Http.Dispatchers if (OsInfo.IsWindows) { - curlEasy.CaInfo = "curl-ca-bundle.crt"; + curlEasy.CaInfo = _caBundleFilePath; } if (cookies != null) diff --git a/src/NzbDrone.Core.Test/FluentTest.cs b/src/NzbDrone.Core.Test/FluentTest.cs index f9886700a..752dff23f 100644 --- a/src/NzbDrone.Core.Test/FluentTest.cs +++ b/src/NzbDrone.Core.Test/FluentTest.cs @@ -127,7 +127,7 @@ namespace NzbDrone.Core.Test public void Truncate_should_truncate_strings_to_max_specified_number_of_bytes() { - var str = ReadAllText("Files", "LongOverview.txt"); + var str = ReadAllText("Files/LongOverview.txt"); var resultString = str.Truncate(1000); diff --git a/src/NzbDrone.Core.Test/Framework/CoreTest.cs b/src/NzbDrone.Core.Test/Framework/CoreTest.cs index 67eddc9b8..89a3a02c1 100644 --- a/src/NzbDrone.Core.Test/Framework/CoreTest.cs +++ b/src/NzbDrone.Core.Test/Framework/CoreTest.cs @@ -10,11 +10,6 @@ namespace NzbDrone.Core.Test.Framework { public abstract class CoreTest : TestBase { - protected string ReadAllText(params string[] path) - { - return File.ReadAllText(Path.Combine(path)); - } - protected void UseRealHttp() { Mocker.SetConstant(new HttpProvider(TestLogger)); diff --git a/src/NzbDrone.Core.Test/HealthCheck/Checks/DeleteBadMediaCovers.cs b/src/NzbDrone.Core.Test/HealthCheck/Checks/DeleteBadMediaCovers.cs index 14624fdb1..8dfd295cf 100644 --- a/src/NzbDrone.Core.Test/HealthCheck/Checks/DeleteBadMediaCovers.cs +++ b/src/NzbDrone.Core.Test/HealthCheck/Checks/DeleteBadMediaCovers.cs @@ -108,7 +108,7 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks Mocker.GetMock() .Setup(c => c.OpenReadStream(imagePath)) - .Returns(new FileStream("Files\\html_image.jpg".AsOsAgnostic(), FileMode.Open, FileAccess.Read)); + .Returns(new FileStream(GetTestPath("Files/html_image.jpg"), FileMode.Open, FileAccess.Read)); Subject.Clean(); @@ -130,7 +130,7 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks Mocker.GetMock() .Setup(c => c.OpenReadStream(imagePath)) - .Returns(new FileStream("Files\\emptyfile.txt".AsOsAgnostic(), FileMode.Open, FileAccess.Read)); + .Returns(new FileStream(GetTestPath("Files/emptyfile.txt"), FileMode.Open, FileAccess.Read)); Subject.Clean(); @@ -150,7 +150,7 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks Mocker.GetMock() .Setup(c => c.OpenReadStream(imagePath)) - .Returns(new FileStream("Files\\Queue.txt".AsOsAgnostic(), FileMode.Open, FileAccess.Read)); + .Returns(new FileStream(GetTestPath("Files/Queue.txt"), FileMode.Open, FileAccess.Read)); Subject.Clean(); diff --git a/src/NzbDrone.Core.Test/IndexerTests/BasicRssParserFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/BasicRssParserFixture.cs index 99cfb82a6..b2819434d 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/BasicRssParserFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/BasicRssParserFixture.cs @@ -48,7 +48,7 @@ namespace NzbDrone.Core.Test.IndexerTests [Test] public void should_handle_relative_url() { - var xml = ReadAllText("Files", "Indexers", "relative_urls.xml"); + var xml = ReadAllText("Files/Indexers/relative_urls.xml"); var result = Subject.ParseResponse(CreateResponse("http://my.indexer.com/api?q=My+Favourite+Show", xml)); diff --git a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabCapabilitiesProviderFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabCapabilitiesProviderFixture.cs index 735fe7b03..b7956a212 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabCapabilitiesProviderFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabCapabilitiesProviderFixture.cs @@ -21,7 +21,7 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests Url = "http://indxer.local" }; - _caps = ReadAllText("Files", "Indexers", "Newznab", "newznab_caps.xml"); + _caps = ReadAllText("Files/Indexers/Newznab/newznab_caps.xml"); } private void GivenCapsResponse(string caps) diff --git a/src/NzbDrone.Core.Test/MediaCoverTests/ImageResizerFixture.cs b/src/NzbDrone.Core.Test/MediaCoverTests/ImageResizerFixture.cs index 38bc8681a..eb5644401 100644 --- a/src/NzbDrone.Core.Test/MediaCoverTests/ImageResizerFixture.cs +++ b/src/NzbDrone.Core.Test/MediaCoverTests/ImageResizerFixture.cs @@ -42,7 +42,7 @@ namespace NzbDrone.Core.Test.MediaCoverTests var mainFile = Path.Combine(TempFolder, "logo.png"); var resizedFile = Path.Combine(TempFolder, "logo-170.png"); - File.Copy(@"Files/1024.png", mainFile); + File.Copy(GetTestPath("Files/1024.png"), mainFile); Subject.Resize(mainFile, resizedFile, 170); diff --git a/src/NzbDrone.Core.Test/MediaFiles/MediaInfo/VideoFileInfoReaderFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/MediaInfo/VideoFileInfoReaderFixture.cs index 475c0b3c4..414dad707 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/MediaInfo/VideoFileInfoReaderFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/MediaInfo/VideoFileInfoReaderFixture.cs @@ -5,6 +5,7 @@ using NUnit.Framework; using NzbDrone.Common.Disk; using NzbDrone.Core.MediaFiles.MediaInfo; using NzbDrone.Core.Test.Framework; +using NzbDrone.Test.Common; using NzbDrone.Test.Common.Categories; namespace NzbDrone.Core.Test.MediaFiles.MediaInfo @@ -28,7 +29,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo [Test] public void get_runtime() { - var path = Path.Combine(Directory.GetCurrentDirectory(), "Files", "Media", "H264_sample.mp4"); + var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Files", "Media", "H264_sample.mp4"); Subject.GetRunTime(path).Seconds.Should().Be(10); @@ -38,7 +39,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo [Test] public void get_info() { - var path = Path.Combine(Directory.GetCurrentDirectory(), "Files", "Media", "H264_sample.mp4"); + var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Files", "Media", "H264_sample.mp4"); var info = Subject.GetMediaInfo(path); @@ -62,7 +63,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo [Test] public void get_info_unicode() { - var srcPath = Path.Combine(Directory.GetCurrentDirectory(), "Files", "Media", "H264_sample.mp4"); + var srcPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "Files", "Media", "H264_sample.mp4"); var tempPath = GetTempFilePath(); Directory.CreateDirectory(tempPath); @@ -92,7 +93,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaInfo [Test] public void should_dispose_file_after_scanning_mediainfo() { - var path = Path.Combine(Directory.GetCurrentDirectory(), "Files", "Media", "H264_sample.mp4"); + var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Files", "Media", "H264_sample.mp4"); var info = Subject.GetMediaInfo(path); diff --git a/src/NzbDrone.Core.Test/ProviderTests/DiskProviderTests/ArchiveProviderFixture.cs b/src/NzbDrone.Core.Test/ProviderTests/DiskProviderTests/ArchiveProviderFixture.cs index 6f4cacea5..5e9d6c6a8 100644 --- a/src/NzbDrone.Core.Test/ProviderTests/DiskProviderTests/ArchiveProviderFixture.cs +++ b/src/NzbDrone.Core.Test/ProviderTests/DiskProviderTests/ArchiveProviderFixture.cs @@ -16,7 +16,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskProviderTests var destinationFolder = new DirectoryInfo(GetTempFilePath()); var testArchive = OsInfo.IsWindows ? "TestArchive.zip" : "TestArchive.tar.gz"; - Subject.Extract(Path.Combine("Files", testArchive), destinationFolder.FullName); + Subject.Extract(GetTestPath("Files/" + testArchive), destinationFolder.FullName); destinationFolder.Exists.Should().BeTrue(); destinationFolder.GetDirectories().Should().HaveCount(1); diff --git a/src/NzbDrone.Integration.Test/ApiTests/BlacklistFixture.cs b/src/NzbDrone.Integration.Test/ApiTests/BlacklistFixture.cs new file mode 100644 index 000000000..4ed24725f --- /dev/null +++ b/src/NzbDrone.Integration.Test/ApiTests/BlacklistFixture.cs @@ -0,0 +1,52 @@ +using System; +using System.Threading; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Api.Series; +using System.Linq; +using NzbDrone.Test.Common; + +namespace NzbDrone.Integration.Test.ApiTests +{ + [TestFixture] + public class BlacklistFixture : IntegrationTest + { + private SeriesResource _series; + + [Test] + [Ignore("Adding to blacklist not supported")] + public void should_be_able_to_add_to_blacklist() + { + _series = EnsureSeries(266189, "The Blacklist"); + + Blacklist.Post(new Api.Blacklist.BlacklistResource + { + SeriesId = _series.Id, + SourceTitle = "Blacklist.S01E01.Brought.To.You.By-BoomBoxHD" + }); + } + + [Test] + [Ignore("Adding to blacklist not supported")] + public void should_be_able_to_get_all_blacklisted() + { + var result = Blacklist.GetPaged(0, 1000, "date", "desc"); + + result.Should().NotBeNull(); + result.TotalRecords.Should().Be(1); + result.Records.Should().NotBeNullOrEmpty(); + } + + [Test] + [Ignore("Adding to blacklist not supported")] + public void should_be_able_to_remove_from_blacklist() + { + Blacklist.Delete(1); + + var result = Blacklist.GetPaged(0, 1000, "date", "desc"); + + result.Should().NotBeNull(); + result.TotalRecords.Should().Be(0); + } + } +} diff --git a/src/NzbDrone.Integration.Test/ApiTests/CalendarFixture.cs b/src/NzbDrone.Integration.Test/ApiTests/CalendarFixture.cs new file mode 100644 index 000000000..7c3014629 --- /dev/null +++ b/src/NzbDrone.Integration.Test/ApiTests/CalendarFixture.cs @@ -0,0 +1,76 @@ +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Api.Series; +using NzbDrone.Api.Episodes; +using NzbDrone.Integration.Test.Client; +using System; +using System.Globalization; +using System.Collections.Generic; +using System.Linq; + +namespace NzbDrone.Integration.Test.ApiTests +{ + [TestFixture] + public class CalendarFixture : IntegrationTest + { + public ClientBase Calendar; + + private SeriesResource _series; + + protected override void InitRestClients() + { + base.InitRestClients(); + + Calendar = new ClientBase(RestClient, ApiKey, "calendar"); + } + + [Test] + public void should_be_able_to_get_episodes() + { + _series = EnsureSeries(266189, "The Blacklist", true); + + var request = Calendar.BuildRequest(); + request.AddParameter("start", new DateTime(2015, 10, 1).ToString("s") + "Z"); + request.AddParameter("end", new DateTime(2015, 10, 3).ToString("s") + "Z"); + var items = Calendar.Get>(request); + + items = items.Where(v => v.SeriesId == _series.Id).ToList(); + + items.Should().HaveCount(1); + items.First().Title.Should().Be("The Troll Farmer"); + } + + [Test] + public void should_not_be_able_to_get_unmonitored_episodes() + { + _series = EnsureSeries(266189, "The Blacklist", false); + + var request = Calendar.BuildRequest(); + request.AddParameter("start", new DateTime(2015, 10, 1).ToString("s") + "Z"); + request.AddParameter("end", new DateTime(2015, 10, 3).ToString("s") + "Z"); + request.AddParameter("unmonitored", "false"); + var items = Calendar.Get>(request); + + items = items.Where(v => v.SeriesId == _series.Id).ToList(); + + items.Should().BeEmpty(); + } + + [Test] + public void should_be_able_to_get_unmonitored_episodes() + { + _series = EnsureSeries(266189, "The Blacklist", false); + + var request = Calendar.BuildRequest(); + request.AddParameter("start", new DateTime(2015, 10, 1).ToString("s") + "Z"); + request.AddParameter("end", new DateTime(2015, 10, 3).ToString("s") + "Z"); + request.AddParameter("unmonitored", "true"); + var items = Calendar.Get>(request); + + items = items.Where(v => v.SeriesId == _series.Id).ToList(); + + items.Should().HaveCount(1); + items.First().Title.Should().Be("The Troll Farmer"); + } + } +} diff --git a/src/NzbDrone.Integration.Test/ApiTests/CommandFixture.cs b/src/NzbDrone.Integration.Test/ApiTests/CommandFixture.cs new file mode 100644 index 000000000..77f5c51b8 --- /dev/null +++ b/src/NzbDrone.Integration.Test/ApiTests/CommandFixture.cs @@ -0,0 +1,22 @@ +using System.Net; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Api.Commands; +using NzbDrone.Common.Serializer; +using RestSharp; + +namespace NzbDrone.Integration.Test.ApiTests +{ + [TestFixture] + [Ignore("Not ready to be used on this branch")] + public class CommandFixture : IntegrationTest + { + [Test] + public void should_be_able_to_run_rss_sync() + { + var response = Commands.Post(new CommandResource { Name = "rsssync" }); + + response.Id.Should().NotBe(0); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Integration.Test/ApiTests/DownloadClientFixture.cs b/src/NzbDrone.Integration.Test/ApiTests/DownloadClientFixture.cs new file mode 100644 index 000000000..57da20349 --- /dev/null +++ b/src/NzbDrone.Integration.Test/ApiTests/DownloadClientFixture.cs @@ -0,0 +1,44 @@ +using System.Linq; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Test.Common; + +namespace NzbDrone.Integration.Test.ApiTests +{ + [TestFixture] + public class DownloadClientFixture : IntegrationTest + { + [Test] + public void should_be_able_to_add() + { + var schema = DownloadClients.Schema().First(v => v.Implementation == "UsenetBlackhole"); + + schema.Enable = true; + schema.Name = "Test UsenetBlackhole"; + schema.Fields.First(v => v.Name == "WatchFolder").Value = GetTempDirectory("Download", "UsenetBlackhole", "Watch"); + schema.Fields.First(v => v.Name == "NzbFolder").Value = GetTempDirectory("Download", "UsenetBlackhole", "Nzb"); + + var result = DownloadClients.Post(schema); + + result.Enable.Should().BeTrue(); + } + + [Test] + public void should_be_able_to_get() + { + Assert.Ignore("TODO"); + } + + [Test] + public void should_be_able_to_get_by_id() + { + Assert.Ignore("TODO"); + } + + [Test] + public void should_be_enabled() + { + Assert.Ignore("TODO"); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Integration.Test/EpisodeIntegrationTests.cs b/src/NzbDrone.Integration.Test/ApiTests/EpisodeFixture.cs similarity index 79% rename from src/NzbDrone.Integration.Test/EpisodeIntegrationTests.cs rename to src/NzbDrone.Integration.Test/ApiTests/EpisodeFixture.cs index e909db6f3..a406c1605 100644 --- a/src/NzbDrone.Integration.Test/EpisodeIntegrationTests.cs +++ b/src/NzbDrone.Integration.Test/ApiTests/EpisodeFixture.cs @@ -6,10 +6,10 @@ using NzbDrone.Api.Series; using System.Linq; using NzbDrone.Test.Common; -namespace NzbDrone.Integration.Test +namespace NzbDrone.Integration.Test.ApiTests { [TestFixture] - public class EpisodeIntegrationTests : IntegrationTest + public class EpisodeFixture : IntegrationTest { private SeriesResource series; @@ -28,16 +28,9 @@ namespace NzbDrone.Integration.Test newSeries = Series.Post(newSeries); - while (true) - { - if (Episodes.GetEpisodesInSeries(newSeries.Id).Count > 0) - { - return newSeries; - } + WaitForCompletion(() => Episodes.GetEpisodesInSeries(newSeries.Id).Count > 0); - Console.WriteLine("Waiting for episodes to load."); - Thread.Sleep(1000); - } + return newSeries; } [Test] diff --git a/src/NzbDrone.Integration.Test/HistoryIntegrationTest.cs b/src/NzbDrone.Integration.Test/ApiTests/HistoryFixture.cs similarity index 81% rename from src/NzbDrone.Integration.Test/HistoryIntegrationTest.cs rename to src/NzbDrone.Integration.Test/ApiTests/HistoryFixture.cs index 8c5a6c1be..4b33e9c71 100644 --- a/src/NzbDrone.Integration.Test/HistoryIntegrationTest.cs +++ b/src/NzbDrone.Integration.Test/ApiTests/HistoryFixture.cs @@ -1,10 +1,10 @@ using FluentAssertions; using NUnit.Framework; -namespace NzbDrone.Integration.Test +namespace NzbDrone.Integration.Test.ApiTests { [TestFixture] - public class HistoryIntegrationTest : IntegrationTest + public class HistoryFixture : IntegrationTest { [Test] public void history_should_be_empty() diff --git a/src/NzbDrone.Integration.Test/IndexerIntegrationFixture.cs b/src/NzbDrone.Integration.Test/ApiTests/IndexerFixture.cs similarity index 83% rename from src/NzbDrone.Integration.Test/IndexerIntegrationFixture.cs rename to src/NzbDrone.Integration.Test/ApiTests/IndexerFixture.cs index 13ac0d897..2e38af936 100644 --- a/src/NzbDrone.Integration.Test/IndexerIntegrationFixture.cs +++ b/src/NzbDrone.Integration.Test/ApiTests/IndexerFixture.cs @@ -3,10 +3,10 @@ using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.ThingiProvider; -namespace NzbDrone.Integration.Test +namespace NzbDrone.Integration.Test.ApiTests { [TestFixture] - public class IndexerIntegrationFixture : IntegrationTest + public class IndexerFixture : IntegrationTest { [Test] public void should_have_built_in_indexer() diff --git a/src/NzbDrone.Integration.Test/NamingConfigTests.cs b/src/NzbDrone.Integration.Test/ApiTests/NamingConfigFixture.cs similarity index 97% rename from src/NzbDrone.Integration.Test/NamingConfigTests.cs rename to src/NzbDrone.Integration.Test/ApiTests/NamingConfigFixture.cs index de185cdf9..a431a218e 100644 --- a/src/NzbDrone.Integration.Test/NamingConfigTests.cs +++ b/src/NzbDrone.Integration.Test/ApiTests/NamingConfigFixture.cs @@ -1,10 +1,10 @@ using FluentAssertions; using NUnit.Framework; -namespace NzbDrone.Integration.Test +namespace NzbDrone.Integration.Test.ApiTests { [TestFixture] - public class NamingConfigTests : IntegrationTest + public class NamingConfigFixture : IntegrationTest { [Test] diff --git a/src/NzbDrone.Integration.Test/NotificationIntegrationFixture.cs b/src/NzbDrone.Integration.Test/ApiTests/NotificationFixture.cs similarity index 91% rename from src/NzbDrone.Integration.Test/NotificationIntegrationFixture.cs rename to src/NzbDrone.Integration.Test/ApiTests/NotificationFixture.cs index fcc85cd35..c5ebfa8ef 100644 --- a/src/NzbDrone.Integration.Test/NotificationIntegrationFixture.cs +++ b/src/NzbDrone.Integration.Test/ApiTests/NotificationFixture.cs @@ -4,10 +4,10 @@ using FluentAssertions; using NUnit.Framework; -namespace NzbDrone.Integration.Test +namespace NzbDrone.Integration.Test.ApiTests { [TestFixture] - public class NotificationIntegrationFixture : IntegrationTest + public class NotificationFixture : IntegrationTest { [Test] public void should_not_have_any_default_notifications() diff --git a/src/NzbDrone.Integration.Test/ReleaseIntegrationTest.cs b/src/NzbDrone.Integration.Test/ApiTests/ReleaseFixture.cs similarity index 95% rename from src/NzbDrone.Integration.Test/ReleaseIntegrationTest.cs rename to src/NzbDrone.Integration.Test/ApiTests/ReleaseFixture.cs index a0bdffd1a..924a61a2a 100644 --- a/src/NzbDrone.Integration.Test/ReleaseIntegrationTest.cs +++ b/src/NzbDrone.Integration.Test/ApiTests/ReleaseFixture.cs @@ -4,10 +4,10 @@ using NzbDrone.Api.Indexers; using System.Linq; using System.Net; -namespace NzbDrone.Integration.Test +namespace NzbDrone.Integration.Test.ApiTests { [TestFixture] - public class ReleaseIntegrationTest : IntegrationTest + public class ReleaseFixture : IntegrationTest { [Test] public void should_only_have_unknown_series_releases() diff --git a/src/NzbDrone.Integration.Test/RootFolderIntegrationTest.cs b/src/NzbDrone.Integration.Test/ApiTests/RootFolderFixture.cs similarity index 93% rename from src/NzbDrone.Integration.Test/RootFolderIntegrationTest.cs rename to src/NzbDrone.Integration.Test/ApiTests/RootFolderFixture.cs index b0470e9f8..6e8de795f 100644 --- a/src/NzbDrone.Integration.Test/RootFolderIntegrationTest.cs +++ b/src/NzbDrone.Integration.Test/ApiTests/RootFolderFixture.cs @@ -3,10 +3,10 @@ using FluentAssertions; using NUnit.Framework; using NzbDrone.Api.RootFolders; -namespace NzbDrone.Integration.Test +namespace NzbDrone.Integration.Test.ApiTests { [TestFixture] - public class RootFolderIntegrationTest : IntegrationTest + public class RootFolderFixture : IntegrationTest { [Test] public void should_have_no_root_folder_initially() diff --git a/src/NzbDrone.Integration.Test/SeriesEditorIntegrationTest.cs b/src/NzbDrone.Integration.Test/ApiTests/SeriesEditorFixture.cs similarity index 90% rename from src/NzbDrone.Integration.Test/SeriesEditorIntegrationTest.cs rename to src/NzbDrone.Integration.Test/ApiTests/SeriesEditorFixture.cs index de638452e..e5b77a872 100644 --- a/src/NzbDrone.Integration.Test/SeriesEditorIntegrationTest.cs +++ b/src/NzbDrone.Integration.Test/ApiTests/SeriesEditorFixture.cs @@ -4,10 +4,10 @@ using NUnit.Framework; using System.Linq; using NzbDrone.Test.Common; -namespace NzbDrone.Integration.Test +namespace NzbDrone.Integration.Test.ApiTests { [TestFixture] - public class SeriesEditorIntegrationTest : IntegrationTest + public class SeriesEditorFixture : IntegrationTest { private void GivenExistingSeries() { diff --git a/src/NzbDrone.Integration.Test/ApiTests/SeriesFixture.cs b/src/NzbDrone.Integration.Test/ApiTests/SeriesFixture.cs new file mode 100644 index 000000000..111af9318 --- /dev/null +++ b/src/NzbDrone.Integration.Test/ApiTests/SeriesFixture.cs @@ -0,0 +1,175 @@ +using System.Net; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Api.Series; +using System.Linq; +using NzbDrone.Test.Common; +using System.IO; +using System.Collections.Generic; + +namespace NzbDrone.Integration.Test.ApiTests +{ + [TestFixture] + public class SeriesFixture : IntegrationTest + { + [Test] + public void add_series() + { + EnsureNoSeries(266189, "The Blacklist"); + + var series = Series.Lookup("tvdb:266189").Single(); + + series.ProfileId = 1; + series.Path = Path.Combine(SeriesRootFolder, series.Title); + + var result = Series.Post(series); + + result.Should().NotBeNull(); + result.Id.Should().NotBe(0); + result.ProfileId.Should().Be(1); + result.Path.Should().Be(Path.Combine(SeriesRootFolder, series.Title)); + } + + [Test] + public void add_series_with_tags_should_store_them() + { + EnsureNoSeries(266189, "The Blacklist"); + var tag = EnsureTag("abc"); + + var series = Series.Lookup("tvdb:266189").Single(); + + series.ProfileId = 1; + series.Path = Path.Combine(SeriesRootFolder, series.Title); + series.Tags = new HashSet(); + series.Tags.Add(tag.Id); + + var result = Series.Post(series); + + result.Should().NotBeNull(); + result.Tags.Should().Equal(tag.Id); + } + + [Test] + public void add_series_without_profileid_should_return_badrequest() + { + EnsureNoSeries(266189, "The Blacklist"); + + var series = Series.Lookup("tvdb:266189").Single(); + + series.Path = Path.Combine(SeriesRootFolder, series.Title); + + Series.InvalidPost(series); + } + + [Test] + public void add_series_without_path_should_return_badrequest() + { + EnsureNoSeries(266189, "The Blacklist"); + + var series = Series.Lookup("tvdb:266189").Single(); + + series.ProfileId = 1; + + Series.InvalidPost(series); + } + + [Test] + public void get_all_series() + { + EnsureSeries(266189, "The Blacklist"); + EnsureSeries(73065, "Archer"); + + Series.All().Should().NotBeNullOrEmpty(); + Series.All().Should().Contain(v => v.TvdbId == 73065); + Series.All().Should().Contain(v => v.TvdbId == 266189); + } + + [Test] + public void get_series_by_id() + { + var series = EnsureSeries(266189, "The Blacklist"); + + var result = Series.Get(series.Id); + + result.TvdbId.Should().Be(266189); + } + + [Test] + public void get_series_by_unknown_id_should_return_404() + { + var result = Series.Get(1000000, HttpStatusCode.NotFound); + } + + [Test] + public void update_series_profile_id() + { + var series = EnsureSeries(266189, "The Blacklist"); + + var profileId = 1; + if (series.ProfileId == profileId) + { + profileId = 2; + } + + series.ProfileId = profileId; + + var result = Series.Put(series); + + Series.Get(series.Id).ProfileId.Should().Be(profileId); + } + + [Test] + public void update_series_monitored() + { + var series = EnsureSeries(266189, "The Blacklist", false); + + series.Monitored.Should().BeFalse(); + series.Seasons.First().Monitored.Should().BeFalse(); + + series.Monitored = true; + series.Seasons.ForEach(season => + { + season.Monitored = true; + }); + + var result = Series.Put(series); + + result.Monitored.Should().BeTrue(); + result.Seasons.First().Monitored.Should().BeTrue(); + } + + [Test] + public void update_series_tags() + { + var series = EnsureSeries(266189, "The Blacklist"); + var tag = EnsureTag("abc"); + + if (series.Tags.Contains(tag.Id)) + { + series.Tags.Remove(tag.Id); + + var result = Series.Put(series); + Series.Get(series.Id).Tags.Should().NotContain(tag.Id); + } + else + { + series.Tags.Add(tag.Id); + + var result = Series.Put(series); + Series.Get(series.Id).Tags.Should().Contain(tag.Id); + } + } + + [Test] + public void delete_series() + { + var series = EnsureSeries(266189, "The Blacklist"); + + Series.Get(series.Id).Should().NotBeNull(); + + Series.Delete(series.Id); + + Series.All().Should().NotContain(v => v.TvdbId == 266189); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Integration.Test/ApiTests/SeriesLookupFixture.cs b/src/NzbDrone.Integration.Test/ApiTests/SeriesLookupFixture.cs new file mode 100644 index 000000000..9da465f2b --- /dev/null +++ b/src/NzbDrone.Integration.Test/ApiTests/SeriesLookupFixture.cs @@ -0,0 +1,36 @@ +using FluentAssertions; +using NUnit.Framework; + +namespace NzbDrone.Integration.Test.ApiTests +{ + [TestFixture] + public class SeriesLookupFixture : IntegrationTest + { + [TestCase("archer", "Archer (2009)")] + [TestCase("90210", "90210")] + public void lookup_new_series_by_title(string term, string title) + { + var series = Series.Lookup(term); + + series.Should().NotBeEmpty(); + series.Should().Contain(c => c.Title == title); + } + + [Test] + public void lookup_new_series_by_tvdbid() + { + var series = Series.Lookup("tvdb:266189"); + + series.Should().NotBeEmpty(); + series.Should().Contain(c => c.Title == "The Blacklist"); + } + + [Test] + public void lookup_random_series_using_asterix() + { + var series = Series.Lookup("*"); + + series.Should().NotBeEmpty(); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Integration.Test/Client/CommandClient.cs b/src/NzbDrone.Integration.Test/Client/CommandClient.cs new file mode 100644 index 000000000..b83033fad --- /dev/null +++ b/src/NzbDrone.Integration.Test/Client/CommandClient.cs @@ -0,0 +1,13 @@ +using NzbDrone.Api.Commands; +using RestSharp; + +namespace NzbDrone.Integration.Test.Client +{ + public class CommandClient : ClientBase + { + public CommandClient(IRestClient restClient, string apiKey) + : base(restClient, apiKey) + { + } + } +} diff --git a/src/NzbDrone.Integration.Test/Client/DownloadClientClient.cs b/src/NzbDrone.Integration.Test/Client/DownloadClientClient.cs new file mode 100644 index 000000000..e31e38748 --- /dev/null +++ b/src/NzbDrone.Integration.Test/Client/DownloadClientClient.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using NzbDrone.Api.DownloadClient; +using RestSharp; + +namespace NzbDrone.Integration.Test.Client +{ + public class DownloadClientClient : ClientBase + { + public DownloadClientClient(IRestClient restClient, string apiKey) + : base(restClient, apiKey) + { + } + + public List Schema() + { + var request = BuildRequest("/schema"); + return Get>(request); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Integration.Test/CommandIntegerationTests.cs b/src/NzbDrone.Integration.Test/CommandIntegerationTests.cs deleted file mode 100644 index e7fdeda65..000000000 --- a/src/NzbDrone.Integration.Test/CommandIntegerationTests.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Net; -using FluentAssertions; -using NUnit.Framework; -using NzbDrone.Api.Commands; -using NzbDrone.Common.Serializer; -using RestSharp; - -namespace NzbDrone.Integration.Test -{ - [TestFixture] - [Ignore("Command integration tests are bad, maybe?")] - public class CommandIntegrationTest : IntegrationTest - { - [Test] - public void should_be_able_to_run_rss_sync() - { - var request = new RestRequest("command") - { - RequestFormat = DataFormat.Json, - Method = Method.POST - }; - - request.AddBody(new CommandResource { Name = "rsssync" }); - - var restClient = new RestClient("http://localhost:8989/api"); - var response = restClient.Execute(request); - - if (response.ErrorException != null) - { - throw response.ErrorException; - } - - response.ErrorMessage.Should().BeNullOrWhiteSpace(); - response.StatusCode.Should().Be(HttpStatusCode.Created); - - var trackedCommand = Json.Deserialize(response.Content); - trackedCommand.Id.Should().NotBe(0); - } - } -} \ No newline at end of file diff --git a/src/NzbDrone.Integration.Test/IndexHtmlIntegrationFixture.cs b/src/NzbDrone.Integration.Test/IndexHtmlFixture.cs similarity index 83% rename from src/NzbDrone.Integration.Test/IndexHtmlIntegrationFixture.cs rename to src/NzbDrone.Integration.Test/IndexHtmlFixture.cs index d90129afe..dc51501b8 100644 --- a/src/NzbDrone.Integration.Test/IndexHtmlIntegrationFixture.cs +++ b/src/NzbDrone.Integration.Test/IndexHtmlFixture.cs @@ -5,7 +5,7 @@ using NUnit.Framework; namespace NzbDrone.Integration.Test { [TestFixture] - public class IndexHtmlIntegrationFixture : IntegrationTest + public class IndexHtmlFixture : IntegrationTest { [Test] public void should_get_index_html() diff --git a/src/NzbDrone.Integration.Test/IntegrationTest.cs b/src/NzbDrone.Integration.Test/IntegrationTest.cs index 5035b4a36..a4e4c58c8 100644 --- a/src/NzbDrone.Integration.Test/IntegrationTest.cs +++ b/src/NzbDrone.Integration.Test/IntegrationTest.cs @@ -1,76 +1,41 @@ using System; using System.Collections.Generic; -using System.Threading; -using Microsoft.AspNet.SignalR.Client; -using Microsoft.AspNet.SignalR.Client.Transports; using NLog; -using NLog.Config; -using NLog.Targets; -using NUnit.Framework; -using NzbDrone.Api.Commands; -using NzbDrone.Api.Config; -using NzbDrone.Api.History; -using NzbDrone.Api.RootFolders; -using NzbDrone.Common.EnvironmentInfo; -using NzbDrone.Common.Serializer; -using NzbDrone.Integration.Test.Client; -using NzbDrone.SignalR; using NzbDrone.Test.Common; -using NzbDrone.Test.Common.Categories; -using RestSharp; +using NUnit.Framework; +using System.IO; namespace NzbDrone.Integration.Test { - [TestFixture] - [IntegrationTest] - public abstract class IntegrationTest + public abstract class IntegrationTest : IntegrationTestBase { - protected RestClient RestClient { get; private set; } - - protected SeriesClient Series; - protected ClientBase RootFolders; - protected ClientBase Commands; - protected ReleaseClient Releases; - protected ClientBase History; - protected IndexerClient Indexers; - protected EpisodeClient Episodes; - protected ClientBase NamingConfig; - protected NotificationClient Notifications; - private NzbDroneRunner _runner; - private List _signalRReceived; - private Connection _signalrConnection; - - protected static readonly string RootUrl = "http://localhost:8989/"; - - protected IEnumerable SignalRMessages + public override string SeriesRootFolder { - get - { - return _signalRReceived; - } + get { return GetTempDirectory("SeriesRootFolder") ; } } - public IntegrationTest() + protected override string RootUrl { - new StartupContext(); - - LogManager.Configuration = new LoggingConfiguration(); - var consoleTarget = new ConsoleTarget { Layout = "${level}: ${message} ${exception}" }; - LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget); - LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget)); + get { return "http://localhost:8989/"; } } - [TestFixtureSetUp] - public void SmokeTestSetup() + protected override string ApiKey + { + get { return _runner.ApiKey; } + } + + protected override void StartTestTarget() { _runner = new NzbDroneRunner(LogManager.GetCurrentClassLogger()); _runner.KillAll(); _runner.Start(); - InitRestClients(); + } + protected override void InitializeTestTarget() + { // Add Wombles var wombles = Indexers.Post(new Api.Indexers.IndexerResource { @@ -83,76 +48,9 @@ namespace NzbDrone.Integration.Test }); } - private void InitRestClients() - { - RestClient = new RestClient(RootUrl + "api/"); - RestClient.AddDefaultHeader("Authentication", _runner.ApiKey); - RestClient.AddDefaultHeader("X-Api-Key", _runner.ApiKey); - - Series = new SeriesClient(RestClient, _runner.ApiKey); - Releases = new ReleaseClient(RestClient, _runner.ApiKey); - RootFolders = new ClientBase(RestClient, _runner.ApiKey); - Commands = new ClientBase(RestClient, _runner.ApiKey); - History = new ClientBase(RestClient, _runner.ApiKey); - Indexers = new IndexerClient(RestClient, _runner.ApiKey); - Episodes = new EpisodeClient(RestClient, _runner.ApiKey); - NamingConfig = new ClientBase(RestClient, _runner.ApiKey, "config/naming"); - Notifications = new NotificationClient(RestClient, _runner.ApiKey); - } - - [TestFixtureTearDown] - public void SmokeTestTearDown() + protected override void StopTestTarget() { _runner.KillAll(); } - - [TearDown] - public void IntegrationSetup() - { - if (_signalrConnection != null) - { - switch (_signalrConnection.State) - { - case ConnectionState.Connected: - case ConnectionState.Connecting: - { - _signalrConnection.Stop(); - break; - } - } - - _signalrConnection = null; - _signalRReceived = new List(); - } - } - - protected void ConnectSignalR() - { - _signalRReceived = new List(); - _signalrConnection = new Connection("http://localhost:8989/signalr"); - _signalrConnection.Start(new LongPollingTransport()).ContinueWith(task => - { - if (task.IsFaulted) - { - Assert.Fail("SignalrConnection failed. {0}", task.Exception.GetBaseException()); - } - }); - - var retryCount = 0; - - while (_signalrConnection.State != ConnectionState.Connected) - { - if (retryCount > 25) - { - Assert.Fail("Couldn't establish signalr connection. State: {0}", _signalrConnection.State); - } - - retryCount++; - Console.WriteLine("Connecting to signalR" + _signalrConnection.State); - Thread.Sleep(200); - } - - _signalrConnection.Received += json => _signalRReceived.Add(Json.Deserialize(json)); ; - } } } diff --git a/src/NzbDrone.Integration.Test/IntegrationTestBase.cs b/src/NzbDrone.Integration.Test/IntegrationTestBase.cs new file mode 100644 index 000000000..424cc340b --- /dev/null +++ b/src/NzbDrone.Integration.Test/IntegrationTestBase.cs @@ -0,0 +1,267 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading; +using Microsoft.AspNet.SignalR.Client; +using Microsoft.AspNet.SignalR.Client.Transports; +using NLog; +using NLog.Config; +using NLog.Targets; +using NUnit.Framework; +using NzbDrone.Api.Blacklist; +using NzbDrone.Api.Commands; +using NzbDrone.Api.Config; +using NzbDrone.Api.Episodes; +using NzbDrone.Api.History; +using NzbDrone.Api.RootFolders; +using NzbDrone.Api.Series; +using NzbDrone.Api.Tags; +using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.Serializer; +using NzbDrone.Integration.Test.Client; +using NzbDrone.SignalR; +using NzbDrone.Test.Common; +using NzbDrone.Test.Common.Categories; +using RestSharp; + +namespace NzbDrone.Integration.Test +{ + [IntegrationTest] + public abstract class IntegrationTestBase + { + protected RestClient RestClient { get; private set; } + + public ClientBase Blacklist; + public ClientBase Commands; + public DownloadClientClient DownloadClients; + public EpisodeClient Episodes; + public ClientBase History; + public IndexerClient Indexers; + public ClientBase NamingConfig; + public NotificationClient Notifications; + public ReleaseClient Releases; + public ClientBase RootFolders; + public SeriesClient Series; + public ClientBase Tags; + + private List _signalRReceived; + private Connection _signalrConnection; + + protected IEnumerable SignalRMessages + { + get + { + return _signalRReceived; + } + } + + public IntegrationTestBase() + { + new StartupContext(); + + LogManager.Configuration = new LoggingConfiguration(); + var consoleTarget = new ConsoleTarget { Layout = "${level}: ${message} ${exception}" }; + LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget); + LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget)); + } + + public string TempDirectory { get; private set; } + + public abstract string SeriesRootFolder { get; } + + protected abstract string RootUrl { get; } + + protected abstract string ApiKey { get; } + + protected abstract void StartTestTarget(); + + protected abstract void InitializeTestTarget(); + + protected abstract void StopTestTarget(); + + [OneTimeSetUp] + public void SmokeTestSetup() + { + StartTestTarget(); + InitRestClients(); + InitializeTestTarget(); + } + + protected virtual void InitRestClients() + { + RestClient = new RestClient(RootUrl + "api/"); + RestClient.AddDefaultHeader("Authentication", ApiKey); + RestClient.AddDefaultHeader("X-Api-Key", ApiKey); + + Blacklist = new ClientBase(RestClient, ApiKey); + Commands = new CommandClient(RestClient, ApiKey); + DownloadClients = new DownloadClientClient(RestClient, ApiKey); + Episodes = new EpisodeClient(RestClient, ApiKey); + History = new ClientBase(RestClient, ApiKey); + Indexers = new IndexerClient(RestClient, ApiKey); + NamingConfig = new ClientBase(RestClient, ApiKey, "config/naming"); + Notifications = new NotificationClient(RestClient, ApiKey); + Releases = new ReleaseClient(RestClient, ApiKey); + RootFolders = new ClientBase(RestClient, ApiKey); + Series = new SeriesClient(RestClient, ApiKey); + Tags = new ClientBase(RestClient, ApiKey); + } + + [OneTimeTearDown] + public void SmokeTestTearDown() + { + StopTestTarget(); + } + + [SetUp] + public void IntegrationSetUp() + { + TempDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "_test_" + DateTime.UtcNow.Ticks); + } + + [TearDown] + public void IntegrationTearDown() + { + if (_signalrConnection != null) + { + switch (_signalrConnection.State) + { + case ConnectionState.Connected: + case ConnectionState.Connecting: + { + _signalrConnection.Stop(); + break; + } + } + + _signalrConnection = null; + _signalRReceived = new List(); + } + } + + public string GetTempDirectory(params string[] args) + { + var path = Path.Combine(TempDirectory, Path.Combine(args)); + + Directory.CreateDirectory(path); + + return path; + } + + protected void ConnectSignalR() + { + _signalRReceived = new List(); + _signalrConnection = new Connection("http://localhost:8989/signalr"); + _signalrConnection.Start(new LongPollingTransport()).ContinueWith(task => + { + if (task.IsFaulted) + { + Assert.Fail("SignalrConnection failed. {0}", task.Exception.GetBaseException()); + } + }); + + var retryCount = 0; + + while (_signalrConnection.State != ConnectionState.Connected) + { + if (retryCount > 25) + { + Assert.Fail("Couldn't establish signalr connection. State: {0}", _signalrConnection.State); + } + + retryCount++; + Console.WriteLine("Connecting to signalR" + _signalrConnection.State); + Thread.Sleep(200); + } + + _signalrConnection.Received += json => _signalRReceived.Add(Json.Deserialize(json)); ; + } + + public static void WaitForCompletion(Func predicate, int timeout = 10000, int interval = 500) + { + var count = timeout / interval; + for (var i = 0; i < count; i++) + { + if (predicate()) + return; + + Thread.Sleep(interval); + } + + if (predicate()) + return; + + Assert.Fail("Timed on wait"); + } + + public SeriesResource EnsureSeries(int tvdbId, string seriesTitle, bool? monitored = null) + { + var result = Series.All().FirstOrDefault(v => v.TvdbId == tvdbId); + + if (result == null) + { + var lookup = Series.Lookup("tvdb:" + tvdbId); + var series = lookup.First(); + series.ProfileId = 1; + series.Path = Path.Combine(SeriesRootFolder, series.Title); + series.Monitored = true; + series.Seasons.ForEach(v => v.Monitored = true); + series.AddOptions = new Core.Tv.AddSeriesOptions(); + Directory.CreateDirectory(series.Path); + + result = Series.Post(series); + + WaitForCompletion(() => Episodes.GetEpisodesInSeries(result.Id).Count > 0); + } + + if (monitored.HasValue) + { + var changed = false; + if (result.Monitored != monitored.Value) + { + result.Monitored = monitored.Value; + changed = true; + } + + result.Seasons.ForEach(season => + { + if (season.Monitored != monitored.Value) + { + season.Monitored = monitored.Value; + changed = true; + } + }); + + if (changed) + { + Series.Put(result); + } + } + + return result; + } + + public void EnsureNoSeries(int tvdbId, string seriesTitle) + { + var result = Series.All().FirstOrDefault(v => v.TvdbId == tvdbId); + + if (result != null) + { + Series.Delete(result.Id); + } + } + + public TagResource EnsureTag(string tagLabel) + { + var tag = Tags.All().FirstOrDefault(v => v.Label == tagLabel); + + if (tag == null) + { + tag = Tags.Post(new TagResource { Label = tagLabel }); + } + + return tag; + } + } +} diff --git a/src/NzbDrone.Integration.Test/IntegrationTestDirectoryInfo.cs b/src/NzbDrone.Integration.Test/IntegrationTestDirectoryInfo.cs deleted file mode 100644 index 922a9537c..000000000 --- a/src/NzbDrone.Integration.Test/IntegrationTestDirectoryInfo.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.IO; -using NzbDrone.Common.EnvironmentInfo; - -namespace NzbDrone.Integration.Test -{ - public class IntegrationTestFolderInfo : IAppFolderInfo - { - public IntegrationTestFolderInfo() - { - TempFolder = Path.GetTempPath(); - AppDataFolder = Path.Combine(Directory.GetCurrentDirectory(), "integ_test", DateTime.Now.Ticks.ToString()); - - if (!Directory.Exists(AppDataFolder)) - { - Directory.CreateDirectory(AppDataFolder); - } - - StartUpFolder = Directory.GetCurrentDirectory(); - } - - public string AppDataFolder { get; private set; } - public string TempFolder { get; private set; } - public string StartUpFolder { get; private set; } - } -} \ No newline at end of file diff --git a/src/NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj b/src/NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj index 81a41230b..31d6541f3 100644 --- a/src/NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj +++ b/src/NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj @@ -103,27 +103,33 @@ + + + + + + - + - - - - + + + + - - - + + + - - - - + + + + diff --git a/src/NzbDrone.Integration.Test/SeriesIntegrationTest.cs b/src/NzbDrone.Integration.Test/SeriesIntegrationTest.cs deleted file mode 100644 index f4e6f0c0d..000000000 --- a/src/NzbDrone.Integration.Test/SeriesIntegrationTest.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System.Net; -using FluentAssertions; -using NUnit.Framework; -using NzbDrone.Api.Series; -using System.Linq; -using NzbDrone.Test.Common; - -namespace NzbDrone.Integration.Test -{ - [TestFixture] - public class SeriesIntegrationTest : IntegrationTest - { - [Test] - public void series_lookup_on_tvdb() - { - var series = Series.Lookup("archer"); - - series.Should().NotBeEmpty(); - series.Should().Contain(c => c.Title == "Archer (2009)"); - } - - [Test] - public void add_series_without_required_fields_should_return_badrequest() - { - var errors = Series.InvalidPost(new SeriesResource()); - errors.Should().NotBeEmpty(); - } - - [Test] - public void should_be_able_to_add_and_delete_series() - { - var series = Series.Lookup("archer").First(); - - series.ProfileId = 1; - series.Path = @"C:\Test\Archer".AsOsAgnostic(); - - series = Series.Post(series); - - Series.All().Should().HaveCount(1); - - Series.Get(series.Id).Should().NotBeNull(); - - Series.Delete(series.Id); - - Series.All().Should().BeEmpty(); - } - - [Test] - public void should_be_able_to_find_series_by_id() - { - var series = Series.Lookup("90210").First(); - - series.ProfileId = 1; - series.Path = @"C:\Test\90210".AsOsAgnostic(); - - series = Series.Post(series); - - Series.All().Should().HaveCount(1); - - Series.Get(series.Id).Should().NotBeNull(); - } - - [Test] - public void invalid_id_should_return_404() - { - Series.Get(99, HttpStatusCode.NotFound); - } - } -} \ No newline at end of file diff --git a/src/NzbDrone.Test.Common/NzbDroneRunner.cs b/src/NzbDrone.Test.Common/NzbDroneRunner.cs index fb91f7127..2f1d8e3f5 100644 --- a/src/NzbDrone.Test.Common/NzbDroneRunner.cs +++ b/src/NzbDrone.Test.Common/NzbDroneRunner.cs @@ -30,7 +30,7 @@ namespace NzbDrone.Test.Common public void Start() { - AppData = Path.Combine(Directory.GetCurrentDirectory(), "_intg_" + DateTime.Now.Ticks); + AppData = Path.Combine(TestContext.CurrentContext.TestDirectory, "_intg_" + DateTime.Now.Ticks); var nzbdroneConsoleExe = "NzbDrone.Console.exe"; @@ -41,7 +41,7 @@ namespace NzbDrone.Test.Common if (BuildInfo.IsDebug) { - Start("..\\..\\..\\..\\..\\_output\\NzbDrone.Console.exe"); + Start(Path.Combine(TestContext.CurrentContext.TestDirectory, "..\\..\\..\\..\\..\\_output\\NzbDrone.Console.exe")); } else { diff --git a/src/NzbDrone.Test.Common/TestBase.cs b/src/NzbDrone.Test.Common/TestBase.cs index 20109e461..bf32a1423 100644 --- a/src/NzbDrone.Test.Common/TestBase.cs +++ b/src/NzbDrone.Test.Common/TestBase.cs @@ -90,14 +90,11 @@ namespace NzbDrone.Test.Common [SetUp] public void TestBaseSetup() { - GetType().IsPublic.Should().BeTrue("All Test fixtures should be public to work in mono."); - - LogManager.ReconfigExistingLoggers(); - TempFolder = Path.Combine(Directory.GetCurrentDirectory(), "_temp_" + DateTime.Now.Ticks); + TempFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, "_temp_" + DateTime.Now.Ticks); Directory.CreateDirectory(TempFolder); } @@ -152,6 +149,16 @@ namespace NzbDrone.Test.Common TestFolderInfo = Mocker.GetMock().Object; } + protected string GetTestPath(string path) + { + return Path.Combine(TestContext.CurrentContext.TestDirectory, Path.Combine(path.Split('/'))); + } + + protected string ReadAllText(string path) + { + return File.ReadAllText(GetTestPath(path)); + } + protected string GetTempFilePath() { return Path.Combine(TempFolder, Path.GetRandomFileName()); diff --git a/src/UI/Calendar/CalendarView.js b/src/UI/Calendar/CalendarView.js index bf24a7e6a..871db9343 100644 --- a/src/UI/Calendar/CalendarView.js +++ b/src/UI/Calendar/CalendarView.js @@ -161,7 +161,7 @@ module.exports = Marionette.ItemView.extend({ statusLevel : self._getStatusLevel(model, end), downloading : QueueCollection.findEpisode(model.get('id')), model : model, - sortOrder : (model.get('seasonNumber') == 0 ? 1000000 : model.get('seasonNumber') * 10000) + model.get('episodeNumber') + sortOrder : (model.get('seasonNumber') === 0 ? 1000000 : model.get('seasonNumber') * 10000) + model.get('episodeNumber') }; events.push(event);