fixed unit test file path generation to be linux compatible.

pull/4/head
Keivan Beigi 12 years ago
parent 4ac2997d78
commit b73485a58b

@ -184,7 +184,7 @@ namespace NzbDrone.Core.Test
public void MaxOrDefault_should_return_max_when_collection_is_not_empty() public void MaxOrDefault_should_return_max_when_collection_is_not_empty()
{ {
//Setup //Setup
var list = new List<int> {6, 4, 5, 3, 8, 10}; var list = new List<int> { 6, 4, 5, 3, 8, 10 };
//Act //Act
var result = list.MaxOrDefault(); var result = list.MaxOrDefault();
@ -210,13 +210,13 @@ namespace NzbDrone.Core.Test
public void Truncate_should_truncate_strings_to_max_specified_number_of_bytes() public void Truncate_should_truncate_strings_to_max_specified_number_of_bytes()
{ {
//Setup //Setup
var str = File.ReadAllText(@"Files\LongOverview.txt"); var str = ReadAllText("Files", "LongOverview.txt");
//Act //Act
var resultString = str.Truncate(1000); var resultString = str.Truncate(1000);
//Resolve //Resolve
var result = new UTF8Encoding().GetBytes(resultString); var result = new UTF8Encoding().GetBytes(resultString);
result.Length.Should().BeLessOrEqualTo(1000); result.Length.Should().BeLessOrEqualTo(1000);
} }

@ -26,6 +26,11 @@ namespace NzbDrone.Core.Test.Framework
{ {
return File.OpenRead(Path.Combine(path)); return File.OpenRead(Path.Combine(path));
} }
protected string ReadAllText(params string[] path)
{
return ReadAllText(Path.Combine(path));
}
} }
public abstract class CoreTest<TSubject> : CoreTest where TSubject : class public abstract class CoreTest<TSubject> : CoreTest where TSubject : class

@ -29,7 +29,7 @@ namespace NzbDrone.Core.Test.IndexerTests
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_recent.json")); .Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_recent.json"));
//Act //Act
var parseResults = Mocker.Resolve<Nzbx>().FetchRss(); var parseResults = Mocker.Resolve<Nzbx>().FetchRss();
@ -43,7 +43,7 @@ namespace NzbDrone.Core.Test.IndexerTests
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadString("https://nzbx.co/api/search?q=30+Rock+S01E01", It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadString("https://nzbx.co/api/search?q=30+Rock+S01E01", It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_search.json")); .Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_search.json"));
//Act //Act
var parseResults = Mocker.Resolve<Nzbx>().FetchEpisode("30 Rock", 1, 1); var parseResults = Mocker.Resolve<Nzbx>().FetchEpisode("30 Rock", 1, 1);
@ -57,7 +57,7 @@ namespace NzbDrone.Core.Test.IndexerTests
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadString(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadString(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\nzbx_recent.json")); .Returns(ReadAllText("Files", "Rss", "nzbx_recent.json"));
var parseResults = Mocker.Resolve<Nzbx>().FetchRss(); var parseResults = Mocker.Resolve<Nzbx>().FetchRss();
@ -69,18 +69,18 @@ namespace NzbDrone.Core.Test.IndexerTests
[Test] [Test]
public void should_be_able_to_parse_results_from_search_results() public void should_be_able_to_parse_results_from_search_results()
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadString(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadString(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\nzbx_search.json")); .Returns(ReadAllText("Files", "Rss", "nzbx_search.json"));
var parseResults = Mocker.Resolve<Nzbx>().FetchEpisode("30 Rock", 1, 1); var parseResults = Mocker.Resolve<Nzbx>().FetchEpisode("30 Rock", 1, 1);
parseResults.Should().NotBeEmpty(); parseResults.Should().NotBeEmpty();
parseResults.Should().OnlyContain(s => s.Indexer == "nzbx"); parseResults.Should().OnlyContain(s => s.Indexer == "nzbx");
parseResults.Should().OnlyContain(s => !String.IsNullOrEmpty(s.OriginalString)); parseResults.Should().OnlyContain(s => !String.IsNullOrEmpty(s.OriginalString));
parseResults.Should().OnlyContain(s => s.Age >= 0); parseResults.Should().OnlyContain(s => s.Age >= 0);
} }
[Test] [Test]
public void should_get_postedDate_when_parsing_recent_feed() public void should_get_postedDate_when_parsing_recent_feed()
@ -89,7 +89,7 @@ namespace NzbDrone.Core.Test.IndexerTests
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_recent.json")); .Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_recent.json"));
//Act //Act
var parseResults = Mocker.Resolve<Nzbx>().FetchRss(); var parseResults = Mocker.Resolve<Nzbx>().FetchRss();
@ -105,7 +105,7 @@ namespace NzbDrone.Core.Test.IndexerTests
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadString("https://nzbx.co/api/search?q=30+Rock+S01E01", It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadString("https://nzbx.co/api/search?q=30+Rock+S01E01", It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_search.json")); .Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_search.json"));
//Act //Act
var parseResults = Mocker.Resolve<Nzbx>().FetchEpisode("30 Rock", 1, 1); var parseResults = Mocker.Resolve<Nzbx>().FetchEpisode("30 Rock", 1, 1);
@ -119,7 +119,7 @@ namespace NzbDrone.Core.Test.IndexerTests
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadString("https://nzbx.co/api/recent?category=tv", It.IsAny<NetworkCredential>()))
.Returns(File.ReadAllText(".\\Files\\Rss\\SizeParsing\\nzbx_recent.json")); .Returns(ReadAllText("Files", "Rss", "SizeParsing", "nzbx_recent.json"));
//Act //Act
var parseResults = Mocker.Resolve<Nzbx>().FetchRss(); var parseResults = Mocker.Resolve<Nzbx>().FetchRss();

@ -10,11 +10,12 @@ using NzbDrone.Common;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download.Clients; using NzbDrone.Core.Download.Clients;
using NzbDrone.Core.Download.Clients.Nzbget; using NzbDrone.Core.Download.Clients.Nzbget;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.NzbgetProviderTests namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.NzbgetProviderTests
{ {
public class DownloadNzbFixture : TestBase public class DownloadNzbFixture : CoreTest
{ {
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -34,7 +35,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.NzbgetProviderTes
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny<String>())) .Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny<String>()))
.Returns(File.ReadAllText(@".\Files\Nzbget\JsonError.txt")); .Returns(ReadAllText("Files", "Nzbget", "JsonError.txt"));
} }
[Test] [Test]

@ -10,11 +10,12 @@ using NzbDrone.Common;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download.Clients; using NzbDrone.Core.Download.Clients;
using NzbDrone.Core.Download.Clients.Nzbget; using NzbDrone.Core.Download.Clients.Nzbget;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.NzbgetProviderTests namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.NzbgetProviderTests
{ {
public class QueueFixture : TestBase public class QueueFixture : CoreTest
{ {
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -33,21 +34,21 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.NzbgetProviderTes
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny<String>())) .Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny<String>()))
.Returns(File.ReadAllText(@".\Files\Nzbget\Queue.txt")); .Returns(ReadAllText("Files", "Nzbget", "Queue.txt"));
} }
private void WithEmptyQueue() private void WithEmptyQueue()
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny<String>())) .Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny<String>()))
.Returns(File.ReadAllText(@".\Files\Nzbget\Queue_empty.txt")); .Returns(ReadAllText("Files", "Nzbget", "Queue_empty.txt"));
} }
private void WithFailResponse() private void WithFailResponse()
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny<String>())) .Setup(s => s.PostCommand("192.168.5.55:6789", "nzbget", "pass", It.IsAny<String>()))
.Returns(File.ReadAllText(@".\Files\Nzbget\JsonError.txt")); .Returns(ReadAllText("Files", "Nzbget", "JsonError.txt"));
} }
[Test] [Test]

@ -51,23 +51,20 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests
s => s =>
s.DownloadString( 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")) "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() private void WithEmptyQueue()
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup( .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"))
s => .Returns(ReadAllText("Files","QueueEmpty.txt"));
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"));
} }
private void WithFailResponse() private void WithFailResponse()
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadString(It.IsAny<String>())).Returns(File.ReadAllText(@".\Files\JsonError.txt")); .Setup(s => s.DownloadString(It.IsAny<String>())).Returns(ReadAllText("Files","JsonError.txt"));
} }
private void WithUnknownPriorityQueue() private void WithUnknownPriorityQueue()
@ -77,7 +74,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests
s => s =>
s.DownloadString( 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")) "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] [Test]

@ -81,7 +81,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests
Mocker.GetMock<HttpProvider>(MockBehavior.Strict) Mocker.GetMock<HttpProvider>(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")) .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 //Act
var result = Mocker.Resolve<SabProvider>().GetCategories(host, port, apikey, username, password); var result = Mocker.Resolve<SabProvider>().GetCategories(host, port, apikey, username, password);
@ -96,7 +96,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests
{ {
Mocker.GetMock<HttpProvider>(MockBehavior.Strict) Mocker.GetMock<HttpProvider>(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")) .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 //Act
var result = Mocker.Resolve<SabProvider>().GetCategories(); var result = Mocker.Resolve<SabProvider>().GetCategories();
@ -111,7 +111,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.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")) .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 //Act
var result = Mocker.Resolve<SabProvider>().GetHistory(); var result = Mocker.Resolve<SabProvider>().GetHistory();
@ -125,7 +125,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.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")) .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 //Act
var result = Mocker.Resolve<SabProvider>().GetHistory(); var result = Mocker.Resolve<SabProvider>().GetHistory();
@ -139,7 +139,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.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")) .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 //Act
Assert.Throws<ApplicationException>(() => Mocker.Resolve<SabProvider>().GetHistory(), "API Key Incorrect"); Assert.Throws<ApplicationException>(() => Mocker.Resolve<SabProvider>().GetHistory(), "API Key Incorrect");

@ -32,7 +32,7 @@ namespace NzbDrone.Core.Test.ProviderTests
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadString(SceneMappingUrl)) .Setup(s => s.DownloadString(SceneMappingUrl))
.Returns(File.ReadAllText(@".\Files\SceneMappings.json")); .Returns(ReadAllText("Files", "SceneMappings.json"));
} }
private void WithErrorDownloadingJson() private void WithErrorDownloadingJson()

@ -23,19 +23,19 @@ namespace NzbDrone.Core.Test.ProviderTests.XemCommunicationProviderTests
private void WithFailureJson() private void WithFailureJson()
{ {
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>())) Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>()))
.Returns(File.ReadAllText(@".\Files\Xem\Failure.txt")); .Returns(ReadAllText("Files","Xem","Failure.txt"));
} }
private void WithIdsJson() private void WithIdsJson()
{ {
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>())) Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>()))
.Returns(File.ReadAllText(@".\Files\Xem\Ids.txt")); .Returns(ReadAllText("Files","Xem","Ids.txt"));
} }
private void WithMappingsJson() private void WithMappingsJson()
{ {
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>())) Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>()))
.Returns(File.ReadAllText(@".\Files\Xem\Mappings.txt")); .Returns(ReadAllText("Files","Xem","Mappings.txt"));
} }
[Test] [Test]

@ -23,19 +23,19 @@ namespace NzbDrone.Core.Test.ProviderTests.XemCommunicationProviderTests
private void WithFailureJson() private void WithFailureJson()
{ {
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>())) Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>()))
.Returns(File.ReadAllText(@".\Files\Xem\Failure.txt")); .Returns(ReadAllText("Files", "Xem", "Failure.txt"));
} }
private void WithIdsJson() private void WithIdsJson()
{ {
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>())) Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>()))
.Returns(File.ReadAllText(@".\Files\Xem\Ids.txt")); .Returns(ReadAllText("Files", "Xem", "Ids.txt"));
} }
private void WithMappingsJson() private void WithMappingsJson()
{ {
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>())) Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>()))
.Returns(File.ReadAllText(@".\Files\Xem\Mappings.txt")); .Returns(ReadAllText("Files", "Xem", "Mappings.txt"));
} }
[Test] [Test]

Loading…
Cancel
Save