2011-11-26 02:20:50 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2012-02-28 05:50:56 +00:00
|
|
|
|
using System.Net;
|
2011-11-26 02:20:50 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
2012-02-28 05:50:56 +00:00
|
|
|
|
using Moq;
|
2011-11-26 02:20:50 +00:00
|
|
|
|
using NUnit.Framework;
|
2012-02-11 00:48:20 +00:00
|
|
|
|
using NzbDrone.Common;
|
2013-02-24 06:48:52 +00:00
|
|
|
|
using NzbDrone.Core.Configuration;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2011-11-26 02:20:50 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-02 20:54:03 +00:00
|
|
|
|
public class ReferenceDataProviderTest : SqlCeTest
|
2011-11-26 02:20:50 +00:00
|
|
|
|
{
|
2012-01-13 04:08:58 +00:00
|
|
|
|
private const string validSeriesIds = "[1,2,3,4,5]";
|
|
|
|
|
private const string invalidSeriesIds = "[1,2,NaN,4,5]";
|
|
|
|
|
|
|
|
|
|
private const string url = "http://services.nzbdrone.com/DailySeries/AllIds";
|
2011-11-26 02:20:50 +00:00
|
|
|
|
|
2012-02-04 05:28:50 +00:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
2013-02-24 19:39:31 +00:00
|
|
|
|
Mocker.GetMock<IConfigService>().SetupGet(s => s.ServiceRootUrl)
|
2012-02-04 05:28:50 +00:00
|
|
|
|
.Returns("http://services.nzbdrone.com");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-11-26 02:20:50 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void GetDailySeriesIds_should_return_list_of_int_when_all_are_valid()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
2012-01-13 04:08:58 +00:00
|
|
|
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.Returns(validSeriesIds);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = Mocker.Resolve<ReferenceDataProvider>().GetDailySeriesIds();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
result.Should().HaveCount(5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2012-01-13 04:08:58 +00:00
|
|
|
|
public void GetDailySeriesIds_should_return_empty_list_when_unable_to_parse()
|
2011-11-26 02:20:50 +00:00
|
|
|
|
{
|
|
|
|
|
//Setup
|
2012-01-13 04:08:58 +00:00
|
|
|
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.Returns(invalidSeriesIds);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = Mocker.Resolve<ReferenceDataProvider>().GetDailySeriesIds();
|
|
|
|
|
|
|
|
|
|
//Assert
|
2012-01-13 04:08:58 +00:00
|
|
|
|
result.Should().BeEmpty();
|
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
2011-11-26 02:20:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetDailySeriesIds_should_return_empty_list_of_int_when_server_is_unavailable()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
2012-01-13 04:08:58 +00:00
|
|
|
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.Throws(new Exception());
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = Mocker.Resolve<ReferenceDataProvider>().GetDailySeriesIds();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
result.Should().HaveCount(0);
|
2011-12-20 00:58:26 +00:00
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
2011-11-26 02:20:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void IsDailySeries_should_return_true()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
2012-01-13 04:08:58 +00:00
|
|
|
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.Returns(validSeriesIds);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = Mocker.Resolve<ReferenceDataProvider>().IsSeriesDaily(1);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
result.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void IsDailySeries_should_return_false()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
2012-01-13 04:08:58 +00:00
|
|
|
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.Returns(validSeriesIds);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var result = Mocker.Resolve<ReferenceDataProvider>().IsSeriesDaily(10);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
result.Should().BeFalse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void UpdateDailySeries_should_update_series_that_match_daily_series_list()
|
|
|
|
|
{
|
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(5)
|
|
|
|
|
.All()
|
2013-02-20 02:05:15 +00:00
|
|
|
|
.With(s => s.SeriesType = SeriesType.Standard)
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
Db.InsertMany(fakeSeries);
|
|
|
|
|
|
|
|
|
|
//Setup
|
2012-01-13 04:08:58 +00:00
|
|
|
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.Returns(validSeriesIds);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
Mocker.Resolve<ReferenceDataProvider>().UpdateDailySeries();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var result = Db.Fetch<Series>();
|
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
result.Where(s => s.SeriesType == SeriesType.Daily).Should().HaveCount(5);
|
2011-11-26 02:20:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void UpdateDailySeries_should_update_series_should_skip_series_that_dont_match()
|
|
|
|
|
{
|
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(5)
|
|
|
|
|
.All()
|
2013-02-20 02:05:15 +00:00
|
|
|
|
.With(s => s.SeriesType = SeriesType.Standard)
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.TheFirst(1)
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(s => s.Id = 10)
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.TheNext(1)
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(s => s.Id = 11)
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.TheNext(1)
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(s => s.Id = 12)
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
Db.InsertMany(fakeSeries);
|
|
|
|
|
|
|
|
|
|
//Setup
|
2012-01-13 04:08:58 +00:00
|
|
|
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.Returns(validSeriesIds);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
Mocker.Resolve<ReferenceDataProvider>().UpdateDailySeries();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var result = Db.Fetch<Series>();
|
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
result.Where(s => s.SeriesType == SeriesType.Standard).Should().HaveCount(3);
|
|
|
|
|
result.Where(s => s.SeriesType == SeriesType.Daily).Should().HaveCount(2);
|
2011-11-26 02:20:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void UpdateDailySeries_should_update_series_should_not_overwrite_existing_isDaily()
|
|
|
|
|
{
|
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(5)
|
|
|
|
|
.All()
|
2013-02-20 02:05:15 +00:00
|
|
|
|
.With(s => s.SeriesType = SeriesType.Standard)
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.TheFirst(1)
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(s => s.Id = 10)
|
2013-02-20 02:05:15 +00:00
|
|
|
|
.With(s => s.SeriesType = SeriesType.Daily)
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.TheNext(1)
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(s => s.Id = 11)
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.TheNext(1)
|
2013-02-26 03:58:57 +00:00
|
|
|
|
.With(s => s.Id = 12)
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
Db.InsertMany(fakeSeries);
|
|
|
|
|
|
|
|
|
|
//Setup
|
2012-01-13 04:08:58 +00:00
|
|
|
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
|
2011-11-26 02:20:50 +00:00
|
|
|
|
.Returns(validSeriesIds);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
Mocker.Resolve<ReferenceDataProvider>().UpdateDailySeries();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var result = Db.Fetch<Series>();
|
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
result.Where(s => s.SeriesType == SeriesType.Daily).Should().HaveCount(3);
|
|
|
|
|
result.Where(s => s.SeriesType == SeriesType.Standard).Should().HaveCount(2);
|
2011-11-26 02:20:50 +00:00
|
|
|
|
}
|
2012-02-28 05:50:56 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void broken_service_should_not_cause_this_call_to_fail()
|
|
|
|
|
{
|
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<string>()))
|
|
|
|
|
.Throws(new WebException())
|
|
|
|
|
.Verifiable();
|
|
|
|
|
|
|
|
|
|
Mocker.Resolve<ReferenceDataProvider>().UpdateDailySeries();
|
|
|
|
|
|
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
|
|
|
|
Mocker.VerifyAllMocks();
|
|
|
|
|
}
|
2011-11-26 02:20:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|