added sample event for series added
This commit is contained in:
parent
66972e5bc6
commit
c35682376e
|
@ -10,20 +10,12 @@ namespace NzbDrone.Common.Test.EventingTests
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class ServiceNameFixture : TestBase
|
public class ServiceNameFixture : TestBase
|
||||||
{
|
{
|
||||||
private EventAggregator _aggregator;
|
|
||||||
|
|
||||||
[SetUp]
|
|
||||||
public void Setup()
|
|
||||||
{
|
|
||||||
_aggregator = new EventAggregator(TestLogger, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_publish_event_to_handlers()
|
public void should_publish_event_to_handlers()
|
||||||
{
|
{
|
||||||
var intHandler = new Mock<IHandle<int>>();
|
var intHandler = new Mock<IHandle<int>>();
|
||||||
_aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler.Object });
|
var aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler.Object });
|
||||||
_aggregator.Publish(12);
|
aggregator.Publish(12);
|
||||||
|
|
||||||
intHandler.Verify(c => c.Handle(12), Times.Once());
|
intHandler.Verify(c => c.Handle(12), Times.Once());
|
||||||
}
|
}
|
||||||
|
@ -31,23 +23,23 @@ namespace NzbDrone.Common.Test.EventingTests
|
||||||
[Test]
|
[Test]
|
||||||
public void should_publish_to_more_than_one_handler()
|
public void should_publish_to_more_than_one_handler()
|
||||||
{
|
{
|
||||||
var intHandler1 =new Mock<IHandle<int>>();
|
var intHandler1 = new Mock<IHandle<int>>();
|
||||||
var intHandler2 = new Mock<IHandle<int>>();
|
var intHandler2 = new Mock<IHandle<int>>();
|
||||||
_aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler1.Object, intHandler2.Object });
|
var aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler1.Object, intHandler2.Object });
|
||||||
_aggregator.Publish(12);
|
aggregator.Publish(12);
|
||||||
|
|
||||||
intHandler1.Verify(c => c.Handle(12), Times.Once());
|
intHandler1.Verify(c => c.Handle(12), Times.Once());
|
||||||
intHandler2.Verify(c => c.Handle(12), Times.Once());
|
intHandler2.Verify(c => c.Handle(12), Times.Once());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_not_publish_to_incompatible_handlers()
|
public void should_not_publish_to_incompatible_handlers()
|
||||||
{
|
{
|
||||||
var intHandler = new Mock<IHandle<int>>();
|
var intHandler = new Mock<IHandle<int>>();
|
||||||
var stringHandler = new Mock<IHandle<string>>();
|
var stringHandler = new Mock<IHandle<string>>();
|
||||||
_aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler.Object, stringHandler.Object });
|
var aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler.Object, stringHandler.Object });
|
||||||
|
|
||||||
_aggregator.Publish(12);
|
aggregator.Publish(12);
|
||||||
|
|
||||||
intHandler.Verify(c => c.Handle(12), Times.Once());
|
intHandler.Verify(c => c.Handle(12), Times.Once());
|
||||||
stringHandler.Verify(c => c.Handle(It.IsAny<string>()), Times.Never());
|
stringHandler.Verify(c => c.Handle(It.IsAny<string>()), Times.Never());
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using NzbDrone.Common.EnsureThat;
|
||||||
|
|
||||||
namespace NzbDrone.Common.Eventing
|
namespace NzbDrone.Common.Eventing
|
||||||
{
|
{
|
||||||
|
@ -11,6 +12,7 @@ namespace NzbDrone.Common.Eventing
|
||||||
|
|
||||||
public EventAggregator(Logger logger, IEnumerable<IHandle> handlers)
|
public EventAggregator(Logger logger, IEnumerable<IHandle> handlers)
|
||||||
{
|
{
|
||||||
|
Ensure.That(() => handlers).HasItems();
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_handlers = handlers;
|
_handlers = handlers;
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,6 +306,7 @@
|
||||||
<Compile Include="Model\LanguageType.cs" />
|
<Compile Include="Model\LanguageType.cs" />
|
||||||
<Compile Include="Model\MisnamedEpisodeModel.cs" />
|
<Compile Include="Model\MisnamedEpisodeModel.cs" />
|
||||||
<Compile Include="Tv\EpisodeService.cs" />
|
<Compile Include="Tv\EpisodeService.cs" />
|
||||||
|
<Compile Include="Tv\Events\SeriesAddedEvent.cs" />
|
||||||
<Compile Include="Tv\SeasonRepository.cs" />
|
<Compile Include="Tv\SeasonRepository.cs" />
|
||||||
<Compile Include="Tv\SeriesRepository.cs" />
|
<Compile Include="Tv\SeriesRepository.cs" />
|
||||||
<Compile Include="Tv\QualityModel.cs" />
|
<Compile Include="Tv\QualityModel.cs" />
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
namespace NzbDrone.Core.Tv.Events
|
||||||
|
{
|
||||||
|
public class SeriesAddedEvent
|
||||||
|
{
|
||||||
|
public Series Series { get; private set; }
|
||||||
|
|
||||||
|
public SeriesAddedEvent(Series series)
|
||||||
|
{
|
||||||
|
Series = series;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,9 +4,11 @@ using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.EnsureThat;
|
using NzbDrone.Common.EnsureThat;
|
||||||
|
using NzbDrone.Common.Eventing;
|
||||||
using NzbDrone.Core.Model;
|
using NzbDrone.Core.Model;
|
||||||
using NzbDrone.Core.Providers;
|
using NzbDrone.Core.Providers;
|
||||||
using NzbDrone.Core.Providers.Core;
|
using NzbDrone.Core.Providers.Core;
|
||||||
|
using NzbDrone.Core.Tv.Events;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Tv
|
namespace NzbDrone.Core.Tv
|
||||||
{
|
{
|
||||||
|
@ -26,6 +28,7 @@ namespace NzbDrone.Core.Tv
|
||||||
private readonly TvDbProvider _tvDbProvider;
|
private readonly TvDbProvider _tvDbProvider;
|
||||||
private readonly MetadataProvider _metadataProvider;
|
private readonly MetadataProvider _metadataProvider;
|
||||||
private readonly TvRageMappingProvider _tvRageMappingProvider;
|
private readonly TvRageMappingProvider _tvRageMappingProvider;
|
||||||
|
private readonly IEventAggregator _eventAggregator;
|
||||||
|
|
||||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
@ -33,7 +36,7 @@ namespace NzbDrone.Core.Tv
|
||||||
|
|
||||||
public SeriesService(ISeriesRepository seriesRepository, ConfigProvider configProviderProvider,
|
public SeriesService(ISeriesRepository seriesRepository, ConfigProvider configProviderProvider,
|
||||||
TvDbProvider tvDbProviderProvider, SceneMappingProvider sceneNameMappingProvider, MetadataProvider metadataProvider,
|
TvDbProvider tvDbProviderProvider, SceneMappingProvider sceneNameMappingProvider, MetadataProvider metadataProvider,
|
||||||
TvRageMappingProvider tvRageMappingProvider)
|
TvRageMappingProvider tvRageMappingProvider, IEventAggregator eventAggregator)
|
||||||
{
|
{
|
||||||
_seriesRepository = seriesRepository;
|
_seriesRepository = seriesRepository;
|
||||||
_configProvider = configProviderProvider;
|
_configProvider = configProviderProvider;
|
||||||
|
@ -41,6 +44,7 @@ namespace NzbDrone.Core.Tv
|
||||||
_sceneNameMappingProvider = sceneNameMappingProvider;
|
_sceneNameMappingProvider = sceneNameMappingProvider;
|
||||||
_metadataProvider = metadataProvider;
|
_metadataProvider = metadataProvider;
|
||||||
_tvRageMappingProvider = tvRageMappingProvider;
|
_tvRageMappingProvider = tvRageMappingProvider;
|
||||||
|
_eventAggregator = eventAggregator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,6 +132,8 @@ namespace NzbDrone.Core.Tv
|
||||||
repoSeries.CustomStartDate = airedAfter;
|
repoSeries.CustomStartDate = airedAfter;
|
||||||
|
|
||||||
_seriesRepository.Insert(repoSeries);
|
_seriesRepository.Insert(repoSeries);
|
||||||
|
|
||||||
|
_eventAggregator.Publish(new SeriesAddedEvent(repoSeries));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -156,7 +162,7 @@ namespace NzbDrone.Core.Tv
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name = "rawTime">The TVDB AirsTime</param>
|
/// <param name = "rawTime">The TVDB AirsTime</param>
|
||||||
/// <returns>String that contains the AirTimes</returns>
|
/// <returns>String that contains the AirTimes</returns>
|
||||||
|
|
||||||
private static readonly Regex timeRegex = new Regex(@"^(?<time>\d+:?\d*)\W*(?<meridiem>am|pm)?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
private static readonly Regex timeRegex = new Regex(@"^(?<time>\d+:?\d*)\W*(?<meridiem>am|pm)?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||||
private static string CleanAirsTime(string rawTime)
|
private static string CleanAirsTime(string rawTime)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue