Refactored IntegrationTests to work with Nunit3 VS adapter.

This commit is contained in:
Taloth Saldono 2016-04-04 19:40:51 +02:00
parent 2fa3873503
commit 71ecc96c70
36 changed files with 804 additions and 318 deletions

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -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<IHttpProvider>(new HttpProvider(TestLogger));

View File

@ -108,7 +108,7 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
Mocker.GetMock<IDiskProvider>()
.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<IDiskProvider>()
.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<IDiskProvider>()
.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();

View File

@ -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));

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);
}
}
}

View File

@ -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<EpisodeResource> Calendar;
private SeriesResource _series;
protected override void InitRestClients()
{
base.InitRestClients();
Calendar = new ClientBase<EpisodeResource>(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<List<EpisodeResource>>(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<List<EpisodeResource>>(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<List<EpisodeResource>>(request);
items = items.Where(v => v.SeriesId == _series.Id).ToList();
items.Should().HaveCount(1);
items.First().Title.Should().Be("The Troll Farmer");
}
}
}

View File

@ -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);
}
}
}

View File

@ -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");
}
}
}

View File

@ -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]

View File

@ -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()

View File

@ -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()

View File

@ -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]

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()
{

View File

@ -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<int>();
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);
}
}
}

View File

@ -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();
}
}
}

View File

@ -0,0 +1,13 @@
using NzbDrone.Api.Commands;
using RestSharp;
namespace NzbDrone.Integration.Test.Client
{
public class CommandClient : ClientBase<CommandResource>
{
public CommandClient(IRestClient restClient, string apiKey)
: base(restClient, apiKey)
{
}
}
}

View File

@ -0,0 +1,20 @@
using System.Collections.Generic;
using NzbDrone.Api.DownloadClient;
using RestSharp;
namespace NzbDrone.Integration.Test.Client
{
public class DownloadClientClient : ClientBase<DownloadClientResource>
{
public DownloadClientClient(IRestClient restClient, string apiKey)
: base(restClient, apiKey)
{
}
public List<DownloadClientResource> Schema()
{
var request = BuildRequest("/schema");
return Get<List<DownloadClientResource>>(request);
}
}
}

View File

@ -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<CommandResource>(response.Content);
trackedCommand.Id.Should().NotBe(0);
}
}
}

View File

@ -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()

View File

@ -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<RootFolderResource> RootFolders;
protected ClientBase<CommandResource> Commands;
protected ReleaseClient Releases;
protected ClientBase<HistoryResource> History;
protected IndexerClient Indexers;
protected EpisodeClient Episodes;
protected ClientBase<NamingConfigResource> NamingConfig;
protected NotificationClient Notifications;
private NzbDroneRunner _runner;
private List<SignalRMessage> _signalRReceived;
private Connection _signalrConnection;
protected static readonly string RootUrl = "http://localhost:8989/";
protected IEnumerable<SignalRMessage> 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<RootFolderResource>(RestClient, _runner.ApiKey);
Commands = new ClientBase<CommandResource>(RestClient, _runner.ApiKey);
History = new ClientBase<HistoryResource>(RestClient, _runner.ApiKey);
Indexers = new IndexerClient(RestClient, _runner.ApiKey);
Episodes = new EpisodeClient(RestClient, _runner.ApiKey);
NamingConfig = new ClientBase<NamingConfigResource>(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<SignalRMessage>();
}
}
protected void ConnectSignalR()
{
_signalRReceived = new List<SignalRMessage>();
_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<SignalRMessage>(json)); ;
}
}
}

View File

@ -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<BlacklistResource> Blacklist;
public ClientBase<CommandResource> Commands;
public DownloadClientClient DownloadClients;
public EpisodeClient Episodes;
public ClientBase<HistoryResource> History;
public IndexerClient Indexers;
public ClientBase<NamingConfigResource> NamingConfig;
public NotificationClient Notifications;
public ReleaseClient Releases;
public ClientBase<RootFolderResource> RootFolders;
public SeriesClient Series;
public ClientBase<TagResource> Tags;
private List<SignalRMessage> _signalRReceived;
private Connection _signalrConnection;
protected IEnumerable<SignalRMessage> 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<BlacklistResource>(RestClient, ApiKey);
Commands = new CommandClient(RestClient, ApiKey);
DownloadClients = new DownloadClientClient(RestClient, ApiKey);
Episodes = new EpisodeClient(RestClient, ApiKey);
History = new ClientBase<HistoryResource>(RestClient, ApiKey);
Indexers = new IndexerClient(RestClient, ApiKey);
NamingConfig = new ClientBase<NamingConfigResource>(RestClient, ApiKey, "config/naming");
Notifications = new NotificationClient(RestClient, ApiKey);
Releases = new ReleaseClient(RestClient, ApiKey);
RootFolders = new ClientBase<RootFolderResource>(RestClient, ApiKey);
Series = new SeriesClient(RestClient, ApiKey);
Tags = new ClientBase<TagResource>(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<SignalRMessage>();
}
}
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<SignalRMessage>();
_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<SignalRMessage>(json)); ;
}
public static void WaitForCompletion(Func<bool> 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;
}
}
}

View File

@ -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; }
}
}

View File

@ -103,27 +103,33 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ApiTests\CalendarFixture.cs" />
<Compile Include="ApiTests\BlacklistFixture.cs" />
<Compile Include="ApiTests\DownloadClientFixture.cs" />
<Compile Include="ApiTests\SeriesLookupFixture.cs" />
<Compile Include="Client\ClientBase.cs" />
<Compile Include="Client\EpisodeClient.cs" />
<Compile Include="Client\IndexerClient.cs" />
<Compile Include="Client\DownloadClientClient.cs" />
<Compile Include="Client\NotificationClient.cs" />
<Compile Include="Client\CommandClient.cs" />
<Compile Include="Client\ReleaseClient.cs" />
<Compile Include="Client\SeriesClient.cs" />
<Compile Include="CommandIntegerationTests.cs" />
<Compile Include="ApiTests\CommandFixture.cs" />
<Compile Include="CorsFixture.cs" />
<Compile Include="EpisodeIntegrationTests.cs" />
<Compile Include="HistoryIntegrationTest.cs" />
<Compile Include="IndexerIntegrationFixture.cs" />
<Compile Include="IndexHtmlIntegrationFixture.cs" />
<Compile Include="ApiTests\EpisodeFixture.cs" />
<Compile Include="ApiTests\HistoryFixture.cs" />
<Compile Include="ApiTests\IndexerFixture.cs" />
<Compile Include="IndexHtmlFixture.cs" />
<Compile Include="IntegrationTest.cs" />
<Compile Include="IntegrationTestDirectoryInfo.cs" />
<Compile Include="NamingConfigTests.cs" />
<Compile Include="NotificationIntegrationFixture.cs" />
<Compile Include="IntegrationTestBase.cs" />
<Compile Include="ApiTests\NamingConfigFixture.cs" />
<Compile Include="ApiTests\NotificationFixture.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReleaseIntegrationTest.cs" />
<Compile Include="RootFolderIntegrationTest.cs" />
<Compile Include="SeriesEditorIntegrationTest.cs" />
<Compile Include="SeriesIntegrationTest.cs" />
<Compile Include="ApiTests\ReleaseFixture.cs" />
<Compile Include="ApiTests\RootFolderFixture.cs" />
<Compile Include="ApiTests\SeriesEditorFixture.cs" />
<Compile Include="ApiTests\SeriesFixture.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\NzbDrone.Test.Common\App.config">

View File

@ -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<dynamic>().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);
}
}
}

View File

@ -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
{

View File

@ -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<IAppFolderInfo>().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());

View File

@ -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);