From b73485a58b905de39f3117b83afc194170552188 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Thu, 28 Mar 2013 12:05:43 -0700 Subject: [PATCH] fixed unit test file path generation to be linux compatible. --- NzbDrone.Core.Test/FluentTest.cs | 6 ++-- NzbDrone.Core.Test/Framework/CoreTest.cs | 5 +++ .../IndexerTests/NzbxFixture.cs | 34 +++++++++---------- .../NzbgetProviderTests/DownloadNzbFixture.cs | 7 ++-- .../NzbgetProviderTests/QueueFixture.cs | 9 ++--- .../SabProviderTests/QueueFixture.cs | 13 +++---- .../SabProviderTests/SabProviderFixture.cs | 10 +++--- .../ProviderTests/SceneMappingProviderTest.cs | 2 +- .../GetSceneTvdbMappingsFixture.cs | 6 ++-- .../GetXemSeriesIdsFixture.cs | 6 ++-- 10 files changed, 51 insertions(+), 47 deletions(-) diff --git a/NzbDrone.Core.Test/FluentTest.cs b/NzbDrone.Core.Test/FluentTest.cs index c4439cc7e..32abc1d20 100644 --- a/NzbDrone.Core.Test/FluentTest.cs +++ b/NzbDrone.Core.Test/FluentTest.cs @@ -184,7 +184,7 @@ namespace NzbDrone.Core.Test public void MaxOrDefault_should_return_max_when_collection_is_not_empty() { //Setup - var list = new List {6, 4, 5, 3, 8, 10}; + var list = new List { 6, 4, 5, 3, 8, 10 }; //Act var result = list.MaxOrDefault(); @@ -210,13 +210,13 @@ namespace NzbDrone.Core.Test public void Truncate_should_truncate_strings_to_max_specified_number_of_bytes() { //Setup - var str = File.ReadAllText(@"Files\LongOverview.txt"); + var str = ReadAllText("Files", "LongOverview.txt"); //Act var resultString = str.Truncate(1000); //Resolve - var result = new UTF8Encoding().GetBytes(resultString); + var result = new UTF8Encoding().GetBytes(resultString); result.Length.Should().BeLessOrEqualTo(1000); } diff --git a/NzbDrone.Core.Test/Framework/CoreTest.cs b/NzbDrone.Core.Test/Framework/CoreTest.cs index 767202879..bd655aced 100644 --- a/NzbDrone.Core.Test/Framework/CoreTest.cs +++ b/NzbDrone.Core.Test/Framework/CoreTest.cs @@ -26,6 +26,11 @@ namespace NzbDrone.Core.Test.Framework { return File.OpenRead(Path.Combine(path)); } + + protected string ReadAllText(params string[] path) + { + return ReadAllText(Path.Combine(path)); + } } public abstract class CoreTest : CoreTest where TSubject : class diff --git a/NzbDrone.Core.Test/IndexerTests/NzbxFixture.cs b/NzbDrone.Core.Test/IndexerTests/NzbxFixture.cs index f108b9f5b..aadb147fe 100644 --- a/NzbDrone.Core.Test/IndexerTests/NzbxFixture.cs +++ b/NzbDrone.Core.Test/IndexerTests/NzbxFixture.cs @@ -29,7 +29,7 @@ namespace NzbDrone.Core.Test.IndexerTests { Mocker.GetMock() .Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny())) - .Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_recent.json")); + .Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_recent.json")); //Act var parseResults = Mocker.Resolve().FetchRss(); @@ -38,12 +38,12 @@ namespace NzbDrone.Core.Test.IndexerTests parseResults[0].Size.Should().Be(890190951); } - [Test] + [Test] public void should_get_size_when_parsing_search_results() { Mocker.GetMock() .Setup(h => h.DownloadString("https://nzbx.co/api/search?q=30+Rock+S01E01", It.IsAny())) - .Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_search.json")); + .Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_search.json")); //Act var parseResults = Mocker.Resolve().FetchEpisode("30 Rock", 1, 1); @@ -57,7 +57,7 @@ namespace NzbDrone.Core.Test.IndexerTests { Mocker.GetMock() .Setup(h => h.DownloadString(It.IsAny(), It.IsAny())) - .Returns(File.ReadAllText(".\\Files\\Rss\\nzbx_recent.json")); + .Returns(ReadAllText("Files", "Rss", "nzbx_recent.json")); var parseResults = Mocker.Resolve().FetchRss(); @@ -69,18 +69,18 @@ namespace NzbDrone.Core.Test.IndexerTests [Test] public void should_be_able_to_parse_results_from_search_results() - { - Mocker.GetMock() - .Setup(h => h.DownloadString(It.IsAny(), It.IsAny())) - .Returns(File.ReadAllText(".\\Files\\Rss\\nzbx_search.json")); + { + Mocker.GetMock() + .Setup(h => h.DownloadString(It.IsAny(), It.IsAny())) + .Returns(ReadAllText("Files", "Rss", "nzbx_search.json")); - var parseResults = Mocker.Resolve().FetchEpisode("30 Rock", 1, 1); + var parseResults = Mocker.Resolve().FetchEpisode("30 Rock", 1, 1); - parseResults.Should().NotBeEmpty(); - parseResults.Should().OnlyContain(s => s.Indexer == "nzbx"); - parseResults.Should().OnlyContain(s => !String.IsNullOrEmpty(s.OriginalString)); - parseResults.Should().OnlyContain(s => s.Age >= 0); - } + parseResults.Should().NotBeEmpty(); + parseResults.Should().OnlyContain(s => s.Indexer == "nzbx"); + parseResults.Should().OnlyContain(s => !String.IsNullOrEmpty(s.OriginalString)); + parseResults.Should().OnlyContain(s => s.Age >= 0); + } [Test] public void should_get_postedDate_when_parsing_recent_feed() @@ -89,7 +89,7 @@ namespace NzbDrone.Core.Test.IndexerTests Mocker.GetMock() .Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny())) - .Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_recent.json")); + .Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_recent.json")); //Act var parseResults = Mocker.Resolve().FetchRss(); @@ -105,7 +105,7 @@ namespace NzbDrone.Core.Test.IndexerTests Mocker.GetMock() .Setup(h => h.DownloadString("https://nzbx.co/api/search?q=30+Rock+S01E01", It.IsAny())) - .Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_search.json")); + .Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_search.json")); //Act var parseResults = Mocker.Resolve().FetchEpisode("30 Rock", 1, 1); @@ -119,7 +119,7 @@ namespace NzbDrone.Core.Test.IndexerTests { Mocker.GetMock() .Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny())) - .Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_recent.json")); + .Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_recent.json")); //Act var parseResults = Mocker.Resolve().FetchRss(); diff --git a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/NzbgetProviderTests/DownloadNzbFixture.cs b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/NzbgetProviderTests/DownloadNzbFixture.cs index dee7374fc..9e2bd61c5 100644 --- a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/NzbgetProviderTests/DownloadNzbFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/NzbgetProviderTests/DownloadNzbFixture.cs @@ -10,11 +10,12 @@ using NzbDrone.Common; using NzbDrone.Core.Configuration; using NzbDrone.Core.Download.Clients; using NzbDrone.Core.Download.Clients.Nzbget; +using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.NzbgetProviderTests { - public class DownloadNzbFixture : TestBase + public class DownloadNzbFixture : CoreTest { [SetUp] public void Setup() @@ -29,12 +30,12 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.NzbgetProviderTes fakeConfig.SetupGet(c => c.NzbgetRecentTvPriority).Returns(PriorityType.High); } - + private void WithFailResponse() { Mocker.GetMock() .Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny())) - .Returns(File.ReadAllText(@".\Files\Nzbget\JsonError.txt")); + .Returns(ReadAllText("Files", "Nzbget", "JsonError.txt")); } [Test] diff --git a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/NzbgetProviderTests/QueueFixture.cs b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/NzbgetProviderTests/QueueFixture.cs index cd1af39ee..ee7324cb1 100644 --- a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/NzbgetProviderTests/QueueFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/NzbgetProviderTests/QueueFixture.cs @@ -10,11 +10,12 @@ using NzbDrone.Common; using NzbDrone.Core.Configuration; using NzbDrone.Core.Download.Clients; using NzbDrone.Core.Download.Clients.Nzbget; +using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.NzbgetProviderTests { - public class QueueFixture : TestBase + public class QueueFixture : CoreTest { [SetUp] public void Setup() @@ -33,21 +34,21 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.NzbgetProviderTes { Mocker.GetMock() .Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny())) - .Returns(File.ReadAllText(@".\Files\Nzbget\Queue.txt")); + .Returns(ReadAllText("Files", "Nzbget", "Queue.txt")); } private void WithEmptyQueue() { Mocker.GetMock() .Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny())) - .Returns(File.ReadAllText(@".\Files\Nzbget\Queue_empty.txt")); + .Returns(ReadAllText("Files", "Nzbget", "Queue_empty.txt")); } private void WithFailResponse() { Mocker.GetMock() .Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny())) - .Returns(File.ReadAllText(@".\Files\Nzbget\JsonError.txt")); + .Returns(ReadAllText("Files", "Nzbget", "JsonError.txt")); } [Test] diff --git a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/QueueFixture.cs b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/QueueFixture.cs index 554f78fa8..022b597bb 100644 --- a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/QueueFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/QueueFixture.cs @@ -51,23 +51,20 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests s => s.DownloadString( "http://192.168.5.55:2222/api?mode=queue&output=json&start=0&limit=0&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) - .Returns(File.ReadAllText(@".\Files\Queue.txt")); + .Returns(ReadAllText("Files","Queue.txt")); } private void WithEmptyQueue() { Mocker.GetMock() - .Setup( - s => - s.DownloadString( - "http://192.168.5.55:2222/api?mode=queue&output=json&start=0&limit=0&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) - .Returns(File.ReadAllText(@".\Files\QueueEmpty.txt")); + .Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=json&start=0&limit=0&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) + .Returns(ReadAllText("Files","QueueEmpty.txt")); } private void WithFailResponse() { Mocker.GetMock() - .Setup(s => s.DownloadString(It.IsAny())).Returns(File.ReadAllText(@".\Files\JsonError.txt")); + .Setup(s => s.DownloadString(It.IsAny())).Returns(ReadAllText("Files","JsonError.txt")); } private void WithUnknownPriorityQueue() @@ -77,7 +74,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests s => s.DownloadString( "http://192.168.5.55:2222/api?mode=queue&output=json&start=0&limit=0&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) - .Returns(File.ReadAllText(@".\Files\QueueUnknownPriority.txt")); + .Returns(ReadAllText("Files", "QueueUnknownPriority.txt")); } [Test] diff --git a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/SabProviderFixture.cs b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/SabProviderFixture.cs index 9fa947edb..c6d3bf65e 100644 --- a/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/SabProviderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DownloadClientTests/SabProviderTests/SabProviderFixture.cs @@ -81,7 +81,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests Mocker.GetMock(MockBehavior.Strict) .Setup(s => s.DownloadString("http://192.168.5.22:1111/api?mode=get_cats&output=json&apikey=5c770e3197e4fe763423ee7c392c25d2&ma_username=admin2&ma_password=pass2")) - .Returns(File.ReadAllText(@".\Files\Categories_json.txt")); + .Returns(ReadAllText("Files","Categories_json.txt")); //Act var result = Mocker.Resolve().GetCategories(host, port, apikey, username, password); @@ -96,7 +96,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests { Mocker.GetMock(MockBehavior.Strict) .Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=get_cats&output=json&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) - .Returns(File.ReadAllText(@".\Files\Categories_json.txt")); + .Returns(ReadAllText("Files","Categories_json.txt")); //Act var result = Mocker.Resolve().GetCategories(); @@ -111,7 +111,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests { Mocker.GetMock() .Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=history&output=json&start=0&limit=0&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) - .Returns(File.ReadAllText(@".\Files\History.txt")); + .Returns(ReadAllText("Files", "History.txt")); //Act var result = Mocker.Resolve().GetHistory(); @@ -125,7 +125,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests { Mocker.GetMock() .Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=history&output=json&start=0&limit=0&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) - .Returns(File.ReadAllText(@".\Files\HistoryEmpty.txt")); + .Returns(ReadAllText("Files","HistoryEmpty.txt")); //Act var result = Mocker.Resolve().GetHistory(); @@ -139,7 +139,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests { Mocker.GetMock() .Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=history&output=json&start=0&limit=0&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")) - .Returns(File.ReadAllText(@".\Files\JsonError.txt")); + .Returns(ReadAllText("Files","JsonError.txt")); //Act Assert.Throws(() => Mocker.Resolve().GetHistory(), "API Key Incorrect"); diff --git a/NzbDrone.Core.Test/ProviderTests/SceneMappingProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/SceneMappingProviderTest.cs index 316d2c4ae..d45cd4697 100644 --- a/NzbDrone.Core.Test/ProviderTests/SceneMappingProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/SceneMappingProviderTest.cs @@ -32,7 +32,7 @@ namespace NzbDrone.Core.Test.ProviderTests { Mocker.GetMock() .Setup(s => s.DownloadString(SceneMappingUrl)) - .Returns(File.ReadAllText(@".\Files\SceneMappings.json")); + .Returns(ReadAllText("Files", "SceneMappings.json")); } private void WithErrorDownloadingJson() diff --git a/NzbDrone.Core.Test/ProviderTests/XemCommunicationProviderTests/GetSceneTvdbMappingsFixture.cs b/NzbDrone.Core.Test/ProviderTests/XemCommunicationProviderTests/GetSceneTvdbMappingsFixture.cs index 1f4848677..6a589db61 100644 --- a/NzbDrone.Core.Test/ProviderTests/XemCommunicationProviderTests/GetSceneTvdbMappingsFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/XemCommunicationProviderTests/GetSceneTvdbMappingsFixture.cs @@ -23,19 +23,19 @@ namespace NzbDrone.Core.Test.ProviderTests.XemCommunicationProviderTests private void WithFailureJson() { Mocker.GetMock().Setup(s => s.DownloadString(It.IsAny())) - .Returns(File.ReadAllText(@".\Files\Xem\Failure.txt")); + .Returns(ReadAllText("Files","Xem","Failure.txt")); } private void WithIdsJson() { Mocker.GetMock().Setup(s => s.DownloadString(It.IsAny())) - .Returns(File.ReadAllText(@".\Files\Xem\Ids.txt")); + .Returns(ReadAllText("Files","Xem","Ids.txt")); } private void WithMappingsJson() { Mocker.GetMock().Setup(s => s.DownloadString(It.IsAny())) - .Returns(File.ReadAllText(@".\Files\Xem\Mappings.txt")); + .Returns(ReadAllText("Files","Xem","Mappings.txt")); } [Test] diff --git a/NzbDrone.Core.Test/ProviderTests/XemCommunicationProviderTests/GetXemSeriesIdsFixture.cs b/NzbDrone.Core.Test/ProviderTests/XemCommunicationProviderTests/GetXemSeriesIdsFixture.cs index aeb5ef4f5..224dc145e 100644 --- a/NzbDrone.Core.Test/ProviderTests/XemCommunicationProviderTests/GetXemSeriesIdsFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/XemCommunicationProviderTests/GetXemSeriesIdsFixture.cs @@ -23,19 +23,19 @@ namespace NzbDrone.Core.Test.ProviderTests.XemCommunicationProviderTests private void WithFailureJson() { Mocker.GetMock().Setup(s => s.DownloadString(It.IsAny())) - .Returns(File.ReadAllText(@".\Files\Xem\Failure.txt")); + .Returns(ReadAllText("Files", "Xem", "Failure.txt")); } private void WithIdsJson() { Mocker.GetMock().Setup(s => s.DownloadString(It.IsAny())) - .Returns(File.ReadAllText(@".\Files\Xem\Ids.txt")); + .Returns(ReadAllText("Files", "Xem", "Ids.txt")); } private void WithMappingsJson() { Mocker.GetMock().Setup(s => s.DownloadString(It.IsAny())) - .Returns(File.ReadAllText(@".\Files\Xem\Mappings.txt")); + .Returns(ReadAllText("Files", "Xem", "Mappings.txt")); } [Test]